How do I change the dynamic connector line color in power shell for Visio

957 views Asked by At

I am trying to change the color of a connector in Visio between a switch shape and a server shape. My current code is as follows:

$From     = $svrSwitch.MachName
$To       = $SvrSwitch.Switch
$ConnFrom = $page.Shapes | Where {$_.name -eq $From}
$ConnTo   = $page.Shapes | Where {$_.name -eq $To}
$ConnFrom.AutoConnect($ConnTo, 0, $connectorSwitch)
$arrow = $page.Shapes | Where {$_.name -eq "Dynamic Connector"} | select -First 1
$arrow.NameU = "$From-TO-$To"
$arrow.fill.ForegroundColor = 0xff0000

Of course I understand the last line is incorrect, I am just not sure how to proceed.

Thank you very much for your help.

1

There are 1 answers

0
JohnGoldsmith On

The thing to understand is that you're writing to cells in the shape's ShapeSheet, so either of these should work:

$arrow.CellsU("LineColor").FormulaU = "=RGB(30, 200, 30)"
$arrow.CellsU("LineColor").FormulaU = "=THEMEVAL(""AccentColor2"")"

and here's a complete example (no error handling) based on Visio 2013:

$application = New-Object -ComObject Visio.Application
$documents = $application.Documents
$document = $documents.Add("NETWME_M.VSTX")
$page = $document.Pages(1)

$stencil = $application.Documents("PERIME_M.VSSX")
$switchMst = $stencil.Masters.Item("Switch")
$serverMst = $stencil.Masters.Item("Server")

$switchShp = $page.Drop($switchMst, 1, 4)
$serverShp = $page.Drop($serverMst, 3, 4)

$visAutoConnectDirNone = 0
$switchShp.Autoconnect($serverShp, $visAutoConnectDirNone)

$dynConnShp = $page.Shapes($page.Shapes.Count)

# $dynConnShp.CellsU("LineColor").FormulaU = "=RGB(30, 200, 30)"
$dynConnShp.CellsU("LineColor").FormulaU = "=THEMEVAL(""AccentColor2"")"

If you're not familiar with the ShapeSheet, then you might find thsi intro useful:

http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html