Hello,
Hi Blake,
Thank you for the reply. I have attached the Visio Stencil. If you start a new diagram in Visio and then open the attached stencil. Then drag “2” from the stencils to the canvas. Now click specifically on the “arrow” shape next to the text. Then right click the arrow and select shape data (similar to the first screen shot on my original post). You will see the properties listed and those properties populate the text box. I am trying to access those properties in the Aspose code and edit each property for each instance of the shape on the diagram. I am able to see the properties on the Master and MasterShape objects but not on the Shape object.
Here is the code I am using in my Aspose program:
// Load masters from any existing diagram, stencil or template
// and add in the new diagram
string visioStencil = dataDir + “Stencil.vss”;
// Create a new diagram
Diagram diagram = new Diagram(visioStencil);
// steps = the shapes in the stencil. Basically just adding the shapes to the diagram
foreach (var s in steps)
{
Shape newShape = new Shape();
[//newShape.Text.Value.Add](https://newshape.text.value.add/)(new Txt("This is New " + s.stepid));
s.visioId = diagram.AddShape(newShape, s.shapeId, pageNumber);
}
//Now I loop through each shape on the diagram and I try to access the properties set in the stencil shape data. The property names are “from”, “min count”, “restrict to current”, “to”, “tracer” and “step number”
foreach (Aspose.Diagram.Shape shape in diagram.Pages[0].Shapes)
{
// FormatTxtCollection txt = shape.Shapes[1].Text.Value;
// txt.Clear();
}
Please let me know if you need any additional information or files.
Thank you for any help with this matter.
Hi Blake,
Diagram diagram = new Diagram();
// add master from the stencil file
diagram.AddMaster(@“C:\AD\test539\Stencil.vss”, “2”);
// get page of the VIsio diagram
Aspose.Diagram.Page page = diagram.Pages.GetPage(“Page-0”);
// place a shape in the page.
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), “2”);
// save in the VDX format
diagram.Save(@“C:\AD\test539\Output.vdx”, SaveFileFormat.VDX);
Diagram diagram = new Diagram(@“C:\AD\test539\Output.vdx”);
// get shape
Aspose.Diagram.Shape shape = diagram.Pages[0].Shapes.GetShape(1).Shapes.GetShape(8);
// extract propeties
foreach (Prop property in shape.Props)
Console.WriteLine(property.Label.Value + ": " + property.Value.Val);
// edit a property
Prop prop = shape.Props.GetProp(“Row_1”);
prop.Value.Val = “Updated Value”;
// save in the VDX format
diagram.Save(@“C:\AD\test539\OutputUpdated.vdx”, SaveFileFormat.VDX);
Wow thank you so much for the solution. That works great. The only question I have left is can I access the properties of the shapes on the page before I save the diagram that way I would not need to reload the diagram?
Good afternoon,
Diagram diagram = new Diagram();
// add master from the stencil file
diagram.AddMaster(@“C:\AD\test539\Stencil.vss”, “2”);
// get page of the VIsio diagram
Aspose.Diagram.Page page = diagram.Pages.GetPage(“Page-0”);
// place a shape in the page.
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), “2”);
// save in the VDX format
diagram.Save(@“C:\AD\test539\Output.vdx”, SaveFileFormat.VDX);
Diagram diagram = new Diagram(@“C:\AD\test539\Output.vdx”);
// get shape
Aspose.Diagram.Shape shape = diagram.Pages[0].Shapes.GetShape(1).Shapes.GetShape(8);
// extract propeties
foreach (Prop property in shape.Props)
Console.WriteLine(property.Label.Value + ": " + property.Value.Val);
// edit a property
Prop prop = shape.Props.GetProp(“Row_1”);
prop.Value.Val = “Updated Value”;
// save in the VDX format
diagram.Save(@“C:\AD\test539\OutputUpdated.vdx”, SaveFileFormat.VDX);
serranoblake:The only question I have left is can I access the properties of the shapes on the page before I save the diagram that way I would not need to reload the diagram?
serranoblake:when I open the new saved diagram it shows the value as 0.00000 instead of "Updated Value". I tried adding another set of double quotes to the string like this prop.Value.Val = "\"Updated Value\""; But that did not work. If I add a number in the string like this prop.Value.Val = "12345"; that number does show properly on the actual diagram. There seems to be something strange going on with the prop type.
Hi Blake,
Prop prop = shape.Props.GetProp(“Row_1”);
// set string value
prop.Value.Val = “Updated Value”;
//add this line code to set unit
prop.Value.Ufev.Unit = MeasureConst.STR;
This is perfect! Thank you so much for your help on all these issues. We are very impressed with your response time and ability to help us move pass our problems. We will definitely be purchasing the Aspose Diagram library.
Hi Blake,