I am having an issue when copying a container from one page to another. The script below makes the correct # of copies and resizes them correctly. However, the styling is incorrect.
If you open the output file in visio, you will see that the first copy of the container has its label on the bottom, whereas the second and third are at the top and not aligned with the body of the container.
However, if you select one of the containers, and go to the Container Format menu tab, you will see that the correct container format (classic) is selected. Clicking the classic container style will cause the container to be correctly styled. Why the styling is not preserved I don’t know.
I do know that in the COM Visio interface these properties were part of the ContainerProperties of the shape, and I don’t see that being available in Aspose.Diagram for .NET.
function Find-VisioShape {
[CmdletBinding()]
param($page,
[string]$Key,
[string]$Value
)
foreach ($item in $page.Shapes) {
$prop = $item.props.GetProp($Key)
if ($prop -and ($prop.value.val -eq $Value)) {
return $item
}
}
}
add-type -path 'C:\Program Files (x86)\Aspose\Aspose.Diagram for .NET\bin\net4.0\Aspose.Diagram.dll'
$Template = 'c:\temp\containerstyle_poc.vsdx'
$diagramFile = 'c:\temp\containerstyle_poc_output.vsdx'
Copy-Item $template $diagramFile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
#get source container and shape from first page
$sourcepage = $doc.pages[0]
$sourceContainer = Find-VisioShape -page $sourcepage -key Container -value "PLACEHOLDER"
$sourceShape = Find-VisioShape -page $sourcepage -key Shape -value "PLACEHOLDER"
#get page for output of data
$page = $doc.pages[1]
$data = @'
Column,Value
Column1,Value1
Column1,Value2
Column2,Value3
Column2,Value4
Column2,Value5
Column3,Value6
'@ | ConvertFrom-Csv
$columns = $data | Group-Object -Property Column
$objectNumber = 1000
$pos = 1
foreach ($column in $columns) {
Write-Host "Working with column $($column.Name)"
$container = New-Object Aspose.Diagram.Shape
$container.Copy($sourceContainer)
$null = $doc.Addshape($container, $container.master.name, ($doc.pages.id).indexof($page.id))
$container.xform.pinx.value = $pos
$container.Name = "Column_$ObjectNumber"
$container.Text.Value.Clear()
$null = $container.Text.Value.add((New-Object aspose.diagram.txt $column.Name))
$objectNumber++
$products = $column.group | Sort-Object Value
$lastY = -1
$Container.xform.pinpos = 1
$container.xform.height.value += ($sourceshape.xform.height.value * $products.count)
foreach ($product in ($products | Sort-Object Value)) {
$shape = New-Object Aspose.Diagram.Shape
$shape.Copy($sourceshape)
($shape.Text.Value | Where-Object { $_.Text } | Select-Object -First 1).text = $product.Value
if ($lastY -eq -1) {
$lastY = $shape.xform.piny.value
} else {
$shape.MoveTo($pos, $lastY - $shape.xform.height.value)
$lastY = $lasty - $shape.xform.height.value
}
$shape.xform.pinx.value = $pos
$null = $doc.Addshape($shape, $shape.master.name, ($doc.pages.id).indexof($page.id))
$shape.Name = "Object.$ObjectNumber"
#write-host "Added shapeID ($($shape.id)) - ($($shape.name))"
$objectNumber++
}
$pos += $container.xform.width.value + 0.5
}
$doc.pages.Remove($doc.pages[0])
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
Invoke-Item $diagramfile
ContainerStyle.zip (132.1 KB)