How do I control drawing scales and rotate shapes I drop using Powershell

Started by dougc, December 19, 2019, 12:24:05 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dougc

I have 2 problems to resolve to make my script more useful and complete.

1.  coordinates of dropped shape don't match commands
I use a code snippet like below to drop a shape, but the coordinates do not correspond to the Drawing sheet.

$item = $stencil.Masters.Item("my_shape"); $shape = $page.Drop($item, 1.52, 10)

The actual center-point of the placed shape is 21.9466, 40.6925

Is there a problem with the scale of the new drawing page I create using this series of commands?
$Visio = New-Object -ComObject Visio.Application
$documents = $Visio.Documents
$document = $documents.Add("Basic Diagram.vst")
$pages = $Visio.ActiveDocument.Pages
$page = $pages.Item(1)

2. The second issue I have is I have not found the correct method to rotate or flip shapes.
The VB macro code equivalent is below:

    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(2685), visSelect
    Application.ActiveWindow.Selection.Rotate 90, visDegrees

    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(2685), visSelect
    Application.ActiveWindow.Selection.FlipHorizontal

    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(2685), visSelect
    Application.ActiveWindow.Selection.FlipVertical

Are there equivalent commands available in Powershell?
Do you have a good reference for the Shape object relevant to Powershell.  So far I have only found documentation related to VB.

Thanks in advance for any help!
-Doug




Yacine

Hello Doug,

I don't know anything about powershell, but I'll have a try.

1) The coordinates are given in visio internal units, that's inches. Check your page settings.
2) The code you posted can be reduced to the following *pseudo-code*:

sub flipNRotate(shp) 'shp ist the object you got earlier when creating it ($shape)

  shp.Rotate 90, visDegrees
  shp.FlipHorizontal
  shp.FlipVertical

I believe that for the visio specific functions, the powershell syntax shouldn't differ that much.

Sorry for the little input.
Yacine