Started here:
After the 25.11 update I’m still seeing some issues with styling of copied containers.
Issues:
- The first container copy is quite a bit wider than the original or the other copies.
- The style still doesn’t seem to have completely applied. If you select a container, go to container properties in the toolbar, and click the (already) selected container style, it “finishes” applying the style and it looks correct.
- With the original container, if you click the container style, it doesn’t do anything. With the copies, each time you click the style it expands the container vertically and messes up the contained shapes. Not sure why this is (and this is a very minor issue…I just noticed it and thought I’d bring it up).
- The containerproperties object still isn’t exposed anywhere I can find in the API. If we can get it to work without specifically referencing that object I guess it’s not a big deal. On the other hand it would make sense to me that there might be instances where I would want to change which container style a container had, and I don’t see how that would be possible without referencing the container specifically (as opposed to the shape).
Here are the script, the source file and a sample output file.
containerstyle_poc.zip (137.6 KB)
I have made the following changes to the POC code:
- I stopped removing the placeholder page (so that comparisons are easier)
- I added a .RefreshData() and .Move(0.0,0.0) to the loop.
Here’s the code:
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
$container.RefreshData()
$container.Move(0.0,0.0)
}
#$doc.pages.Remove($doc.pages[0])
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
Invoke-Item $diagramfile