VisioStencil.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<# .SYNOPSIS Loads a stencil and gives it a name .DESCRIPTION Loads a stencil and gives it a name .PARAMETER Name The name to use to refer to the stencil .PARAMETER Path The path to the stencil file. Ignored with -Builtin .PARAMETER BuiltIn Flags that Path (or Name) refer to a built-in stencil. .INPUTS None. You cannot pipe objects to Register-VisioStencil. .OUTPUTS None .EXAMPLE Register-VisioStencil -Name Containers -Path 'c:\temp\my containers.vssx' .EXAMPLE Register-VisioStencil -Name Connectors -Builtin #> Function Register-VisioStencil{ [CmdletBinding()] Param([string]$Name, [Alias('From')][string]$Path, [ValidateSet('Backgrounds','Borders','Containers','Callouts','Legends')][string]$BuiltIn) if($BuiltIn){ $stencilID=@('Backgrounds','Borders','Containers','Callouts','Legends').IndexOf($BuiltIn) $stencilPath=$Visio.GetBuiltInStencilFile($stencilID,$vis.MSDefault) $stencil=$Visio.Documents.OpenEx($stencilPath,$vis.OpenHidden) } else { if($Path -eq (split-path -path $Path -leaf)){ #if the path is just a filename if(-not(test-path $path)){ #and the filename doesn't exist in the current directory foreach($folder in $StencilSearchPath){ if (test-path (join-path -Path $folder -ChildPath $path)){ $path=join-path -Path $folder -ChildPath $path break } } } } if (test-path $path){ $stencil=$Visio.Documents.OpenEx($Path,$vis.OpenHidden) } else { write-error "$path not found when registering the stencil" } } $script:stencils[$Name]=$stencil } |