Visio オートメーション ライブラリは、次のことに役立ちます。
これを C# で使用する方法の例を次に示します。PowerShell で使用するのは難しくありません。
var app = new IVisio.Application();
var doc = app.Documents.Add("");
var page = doc.Pages[1];
var shape1 = page.DrawRectangle(1, 1, 3, 4);
VisioAutomation.CustomProperties.CustomPropertyHelper.Set(shape1,"Hello","World");
var props = VisioAutomation.CustomProperties.CustomPropertyHelper.Get(shape1);
Visio PowerShell Moduleを使用すると、コードは次のようになります。
Set-StrictMode -Version 2
$ErrorActionPreference = "Stop"
Import-Module Visio
$app= New-VisioApplication
$doc = New-VisioDocument
$stencil_net = Open-VisioDocument "Basic Network Diagram.vst"
$stencil_comp = Open-VisioDocument "Computers and Monitors.vss"
$pc_master = Get-VisioMaster "PC" $stencil_comp
$shapes = New-VisioShape -Masters $pc_master -Points 2.2,6.8
Set-VisioText "Some Text..."
Set-VisioCustomProperty -Name "prop1" -Value "val1"
Set-VisioCustomProperty -Name "prop2" -Value "val2"
$shapedata_col = Get-VisioCustomProperty -Shapes $shapes
foreach ($shapedata in $shapedata_col)
{
Write-Host "--------------------------------------"
Write-Host Name $shapedata.Name
Write-Host Type $shapedata.Type
Write-Host Value $shapedata.Value
Write-Host Prompt $shapedata.Prompt
Write-Host Ask $shapedata.Ask
Write-Host Calendar $shapedata.Calendar
Write-Host Format $shapedata.Format
Write-Host Invisible $shapedata.Invisible
Write-Host Label $shapedata.Label
Write-Host LangId $shapedata.LangId
Write-Host ShapeID $shapedata.ShapeID
Write-Host SortKey $shapedata.SortKey
}
下部に、形状データを設定および取得する方法が表示されます。