We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Accessing Shape Data Properties

Hello,

I am loading a stencil that contains several grouped shapes. In those grouped shapes I have several properties on a certain shape within the group. In the code I am creating a new instance of the grouped shape. I am then trying to access the properties of one of the specific shapes in the new instance. I cannot find the properties, value or text for those properties. I can however see those values at the MasterShape level. But if I change the MasterShape property value it changes for all of the instances. I only want to change the property value on specific instances. I have attached a screen shot of my Shape in Visio I am currently evaluating the Aspose library to see if I can accomplish this task. Any help here would be wonderful. Thanks in advance.

Hi Blake,


Thank you for contacting support. Please provide us your source Visio diagram and the code. We’ll investigate and reply you appropriately.

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,


Thank you for the details. You are placing a group shape in the Visio drawing page as shown in the screenshot of the first post. What is the file extension of the Visio drawing? Using Aspose.Diagram API, you’re loading this stencil file but not the source Visio drawing. You can place a group shape from the stencil file and then save in any supported format as follows:

[.NET, C#]
// Create a new diagram
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.
Note: overloaded methods allow to set shape location, width and height, etc.
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), “2”);

// save in the VDX format
diagram.Save(@“C:\AD\test539\Output.vdx”, SaveFileFormat.VDX);

You can also extract and edit these properties as follows:
[.NET, C#]
// load a Visio diagram
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);

Results:
-------------
from: -365
min count: 0
restrict to current: 0
to: 0
tracer: Proteinuria
Step Num: 4

We hope, this helps. Please let us know in case of any confusion or questions.

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?


For example:

[.NET, C#]
// Create a new diagram
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.
Note: overloaded methods allow to set shape location, width and height, etc.
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), “2”);

// 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\Output.vdx”, SaveFileFormat.VDX);

Good afternoon,

I ran into an issue you may be able to help me out with.

I ran the code you provided.

// Create a new diagram
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.
Note: overloaded methods allow to set shape location, width and height, etc.
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), “2”);

// save in the VDX format
diagram.Save(@“C:\AD\test539\Output.vdx”, SaveFileFormat.VDX);

You can also extract and edit these properties as follows:
[.NET, C#]
// load a Visio diagram
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);

And I can see the prop.Value.Val is changed to “Updated Value” in the code.
But 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.

I have attached the Visio Diagram. Thanks again you have been very helpful.
Hi Blake,
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?
Well, you can save the resulting Visio diagram in the MemoryStream object and then load this diagram into another Diagram object. Sample code:

[.NET, C#]
long shapeid = page.AddShape(new Aspose.Diagram.Shape(), "2"); MemoryStream stream = new MemoryStream(); diagram.Save(stream, SaveFileFormat.VDX); // load a Visio diagram Diagram dgm = new Diagram(stream); // get shape Shape shape = dgm.Pages[0].Shapes.GetShape(shapeid).Shapes.GetShape(8);
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.
We managed to replicate the problem of not being editing the shape string data value. We've logged this problem under ticket id DIAGRAMNET-50650 in our bug tracking system. Your post has also been linked to this issue. We'll keep you informed regarding any available updates. We're sorry for the inconvenience caused.

Hi Blake,


In reference of the ticket id DIAGRAMNET-50650, Please use this sample code and let us know how it goes on your side:

[.NET, C#]
// edit a property
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;

Note: we have closed the ticket id DIAGRAMNET-50650.

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,


Thank you for the confirmation and great feedback. It is nice to hear from you that the problem has been resolved. Please let us know if you require any further assistance of Aspose APIs, we will be happy to help you.