2015-06-23 41 views
0

我試圖在交換機外形和服務器形狀之間更改Visio中連接器的顏色。我當前的代碼如下:如何更改電源外殼中Visio的動態連接線顏色

$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 

我當然明白最後一行是不正確的,我只是不知道如何着手。

非常感謝您的幫助。

+0

如果您正在討論VisioAutomation powershell模塊,那麼您應該可以完全按照您寫的那樣來完成它(即$ xx.Fill.ForegroundColor = 0xff0000)。 http://blogs.msdn.com/b/saveenr/archive/2009/01/22/visio-ironpython-powershell-how-to-draw-nice-diagrams-from-the-command-line.aspx。可能這是混淆來自哪裏? – Nikolay

回答

0

明白的事情是,你寫在形狀的ShapeSheet細胞,使任一應工作:

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

,這裏是一個完整的例子基於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"")" 

如果你不熟悉的ShapeSheet,那麼你可能會發現thsi介紹有用:

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

+0

太好了,非常感謝你的幫助。 –