Masters and Stencils
Masters and stencils
The recommended way to get shapes on a page is to drop a master from a stencil.
Dropping a master
The following code shows the simplest case. It drops a "Rectangle" shape into the current page at position 4,5.
$basic_u = Open-VisioDocument "basic_u.vss"
$master = Get-VisioMaster "Rectangle" -Document $basic_u
$points = New-Object VisioAutomation.Geometry.Point(4,5)
$shape = New-VisioShape -Master $master -Position $pointsDropping a master multiple times - the simple recommended and much faster way
$basic_u = Open-VisioDocument "basic_u.vss"
$master = Get-VisioMaster "Rectangle" -Document $basic_u
$points = @(
New-Object VisioAutomation.Geometry.Point(4,5)
New-Object VisioAutomation.Geometry.Point(6,1)
New-Object VisioAutomation.Geometry.Point(0,0)
)
$shapes = New-VisioShape -Master $master -Position $points
Set-VisioText "Hello World" -Shape $shapesDropping a multiple masters, multiple times
In this case, we want different masters dropped all at the same time
The New-VisioShape cmdlet returns a list of integers - these are the shape ids of the shapes that were created as a result of the drop operation.
You may have noticed that the shapes we've dropped all retained their default formatting and their default size. Use the -Cells parameter to set the cell values. The example below sets all the shapes to have a consistent width, height, fill color, and line weight.

If you want to format each shape separately, that is possible also by passing in multiple shape cells objects

Many common formatting options are available in the ShapeCells object returned by New-VisioShapeCells. To find see all the properties use the following command
Last updated