Categories

Identifying Visio Stencils

In the previous posts on using Visio I’ve shown how to load and use a particular stencil.  But how do you know which stencil to use?

One way is to use Windows Explorer, hover the mouse over the stencil and read the Extended File Properties. That’s a bit manual so we’ll look at producing a list of stencils and for what they are used. To do this we can’t use PowerShell directly but this is where things get real easy – we can use the scripting shell just like we did with VBScript.

001
002
003
004
005
006
007
008
$direc = "C:\Program Files\Microsoft Office\Office14\Visio Content\1033"
$shell = New-Object -ComObject "Shell.Application"
$folder = $shell.Namespace($direc)

Get-ChildItem -Path $direc -Filter "*.vss" | foreach {
    $file = $folder.Items().Item($_.Name)
    "{0,-12} {1}" -f $_.Name, $($folder.GetDetailsOf($file,21))
}

 

Define the directory holding the Visio stencils – mine is Office 2010 on Windows 7.

Create an object for the shell and get the folder object using the Namespace method.

Jump back to PowerShell to run get-childitem on the folder using a filter of *.vss to restrict the output to stencils – always cheaper to filter at source.

We then use the Items() method of our folder to identify the file and use getdetailsof method to return the Title (Extended property number 21) of the stencil. The output is formatted using a .NET formatted string.

Leave a Reply