I have a script which copies a file, then attempts to copy a shape from the first page 10 times onto the second page, moving each shape an inch to the right.
What I end up with is:
- 3 copies of the shape
- The names of the 2nd and 3rd copy aren’t what they’re set to (but the 1st is fine)
- If I make the page auto-size, it sizes like there are 10 of them (lots of blank space to the right).
- The container styles of the original, the first copy and the other copies are all different (well, copy 2 and 3 are the same…but there are 3 different looks).
- The spacing of the 3 copies isn’t consistent…there’s an extra space (like there’s a missing copy) between the 1st and 2nd copy.
I have attached a zip of the input file as well as a sample output.
Here’s the code:
$template='c:\temp\TestDocument.vsdx'
$diagramfile=join-path c:\temp\ "$([guid]::newguid()).vsdx"
copy-item $template $diagramfile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$sourcepage=$doc.pages[0]
$shape=$sourcepage.Shapes.GetShape([int]3005)
$page=$doc.Pages[1]
$pos=0
$page.pagesheet.Copy($sourcePage.PageSheet)
1..10 | foreach {
$shape2=new-object Aspose.Diagram.Shape
$shape2.Copy($shape)
$addedID=$page.Addshape($shape2,$shape2.master.name)
$shape2.Name="NEWSHAPE.$addedID"
$shape2.Move($pos,0)
$shape2.SetWidth($shape2.xform.width.value)
write-host "Added shape with Id $addedID, $($shape2.name)"
$pos+=1
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
ii $diagramfile
TestDocument.zip (236.7 KB)
e058b69d-4546-48a4-aa4d-af45375161a1.zip (247.9 KB)