TestDiagram.zip (459.0 KB)
I’m trying to create a list of shapes based on a shape in an existing document. I’m getting the shapes created and labeled, but every other shape is filled incorrectly. If you resize any of the shapes they “revert” to the correct color. I’ve also tried setting the fill color explicitly, but get the same behavior.
image.png (5.7 KB)
$template = 'c:\temp\TestDocument.vsdx'
$diagramFile = 'c:\temp\Testoutput.vsdx'
Copy-Item $template $diagramfile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$page = $doc.pages[0]
$Container = $page.Shapes.GetShapeIncludingChild([int]3005)
$Shape = $page.Shapes.GetShapeIncludingChild([int]3010)
$height = $shape.xform.height.value
$items = 1..10 | ForEach-Object { "Product$_" }
$first = $true
foreach ($item in $items ) {
if (-not $first) {
$shape2 = New-Object Aspose.Diagram.Shape
$shape2.Copy($shape)
$shape = $shape2
$shape.Move(0, -$height)
$null = $page.Addshape($shape, $shape.master.name)
}
$shape.text.value[1].text=$item
$first = $false
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
@MikeShepard1
It seems you’re experiencing an issue with the fill color of copied shapes in your Visio diagram. This can occur due to how the shapes are being copied and added to the page.
To ensure that the fill color is set correctly, you can explicitly set the fill color after copying the shape. Here’s a modified version of your code that sets the fill color for each new shape:
$template = 'c:\temp\TestDocument.vsdx'
$diagramFile = 'c:\temp\Testoutput.vsdx'
Copy-Item $template $diagramFile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$page = $doc.pages[0]
$Container = $page.Shapes.GetShapeIncludingChild([int]3005)
$Shape = $page.Shapes.GetShapeIncludingChild([int]3010)
$height = $Shape.xform.height.value
$items = 1..10 | ForEach-Object { "Product$_" }
$first = $true
foreach ($item in $items) {
if (-not $first) {
$shape2 = New-Object Aspose.Diagram.Shape
$shape2.Copy($Shape)
$Shape = $shape2
$Shape.Move(0, -$height)
# Set the fill color explicitly
$Shape.FillStyle = [Aspose.Diagram.FillStyle]::Solid
$Shape.FillColor = [Aspose.Diagram.Color]::FromArgb(255, 0, 0, 255) # Example: Blue color
$null = $page.AddShape($Shape, $Shape.master.name)
}
$Shape.text.value[1].text = $item
$first = $false
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
In this code, replace FromArgb(255, 0, 0, 255)
with the desired ARGB values for your fill color. This should help maintain the correct color for the shapes even after they are copied. If the issue persists, consider checking if there are any specific properties in the original shape that need to be replicated in the new shapes.
Professionalize.Discourse:
gramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
In this code, replace From
I’m not following your answer.
Shape doesn’t have a FillColor property.
There is no Aspose.Diagram.Color class.
@MikeShepard1
There are formulas on the color of the shape, we need to remove the formulas and then set the colors.
Please try this sample code:
shape.Fill.FillForegnd.Ufe.F = "";
shape.Fill.FillForegnd.Value = "#ff0000";
Thanks.
MikeShepard1:
$template = 'c:\temp\TestDocument.vsdx'
$diagramFile = 'c:\temp\Testoutput.vsdx'
Copy-Item $template $diagramfile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$page = $doc.pages[0]
$Container = $page.Shapes.GetShapeIncludingChild([int]3005)
$Shape = $page.Shapes.GetShapeIncludingChild([int]3010)
$height = $shape.xform.height.value
$items = 1..10 | ForEach-Object { "Product$_" }
$first = $true
foreach ($item in $items ) {
if (-not $first) {
$shape2 = New-Object Aspose.Diagram.Shape
$shape2.Copy($shape)
$shape = $shape2
$shape.Move(0, -$height)
$null = $page.Addshape($shape, $shape.master.name)
}
$shape.text.value[1].text=$item
$first = $false
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
I hadn’t noticed those formulas, but removing them doesn’t change the behavior. Here’s my updated code, including output showing that the formulas are blank:
$template = 'c:\temp\TestDocument.vsdx'
$diagramFile = 'c:\temp\Testoutput.vsdx'
Copy-Item $template $diagramfile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$page = $doc.pages[0]
$Container = $page.Shapes.GetShapeIncludingChild([int]3005)
$Shape = $page.Shapes.GetShapeIncludingChild([int]3010)
$shape.fill.FillBkgnd.ufe.f=""
$shape.fill.FillForegnd.ufe.f=""
$height = $shape.xform.height.value
$items = 1..10 | ForEach-Object { "Product$_" }
$first = $true
foreach ($item in $items ) {
if (-not $first) {
$shape2 = New-Object Aspose.Diagram.Shape
$shape2.Copy($shape)
$shape = $shape2
$shape.Move(0, -$height)
$null = $page.Addshape($shape, $shape.master.name)
}
$shape.text.value[1].text=$item
$first = $false
write-host "FillBkgnd: $($shape.fill.Fillbkgnd | convertto-json)"
write-host "FillForegnd: $($shape.fill.FillForegnd | convertto-json)"
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
And here’s an image showing that the fill color isn’t displaying correctly for Product4 (I already resized Product2, so that’s why it’s displaying correctly).
image.png (31.5 KB)
Here’s the output from the script:
FillBkgnd: {
"Value": "#e2ebd1",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
FillForegnd: {
"Value": "#d7e3bf",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
FillBkgnd: {
"Value": "#e2ebd1",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
FillForegnd: {
"Value": "#d7e3bf",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
FillBkgnd: {
"Value": "#e2ebd1",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
FillForegnd: {
"Value": "#d7e3bf",
"Ufe": {
"Unit": -2147483648,
"F": "",
"Err": ""
}
}
<snip....all of the output are identical>
This seems like it might be similar.
@MikeShepard1
Thanks for the screenshots.
We reproduced the problems you mentioned by running the code.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies .
Issue ID(s): DIAGRAMNET-53814
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thank you so much.
I was able work around the issue with the following code:
$template = 'c:\temp\TestDocument.vsdx'
$diagramFile = 'c:\temp\Testoutput.vsdx'
Copy-Item $template $diagramfile
$doc = New-Object Aspose.Diagram.Diagram -ArgumentList $diagramFile
$page = $doc.pages[0]
$Container = $page.Shapes.GetShapeIncludingChild([int]3005)
$Shape = $page.Shapes.GetShapeIncludingChild([int]3010)
$shape.fill.FillBkgnd.ufe.f=""
$shape.fill.FillForegnd.ufe.f=""
$height = $shape.xform.height.value
$items = 1..15| ForEach-Object { "Product$_" }
$first = $true
foreach ($item in $items ) {
if (-not $first) {
$shape2 = New-Object Aspose.Diagram.Shape
$shape2.Copy($shape)
$shape = $shape2
$shape.Move(0, -$height)
$null = $page.Addshape($shape, $shape.master.name)
}
if($shape.GetPureText().Trim() -match '[1345]$'){
$Shape.fill.FillForegnd.value = '#fce1cd'
} else {
$Shape.fill.FillForegnd.value = '#b7dde8'
}
$shape.text.value[1].text=$item
#This line of code made it start working
$shape.SetWidth($shape.xform.width.value+0.0)
$first = $false
#$shape.RefreshData()
}
$doc.Save($diagramFile, [Aspose.Diagram.SaveFileFormat]::vsdx)
@MikeShepard1
Should you have further queries or issue, feel free to write us back, we will assist you soon.
Thanks.