Hi Team,
I am trying to add pages and shapes to a Diagram object and create a new diagram using C# .NET.
When I debug the code it shows me that the new Pages are created and shapes are added to those pages, but when I save the file and render it, it throws error that there are shapes with duplicate IDs and an unexpected closure of file was detected.
Context: Line 1 —
Description: Unexpected end of file.
ID='3’
Description: This file contains a duplicate of an element that can exist only once. Visio has ignored the duplicate element.
Also, when I open the file, the file is blank.
I would be grateful if you could please provide your valuable inputs at the earliest.
-Best Regards,
Agraj
Hi Agraj,
Hi Imran,
Thank you for the quick response.
In Visio Interop Library, there is a Document collection, in which we can load multiple stencils and templates in a document and edit-save-render the same.
But here in Aspose.Diagram, is there any way to load multiple stencils/templates in one single Diagram and edit-save-render it?
My requirement is to add multiple pages using .NET codes and add shapes to those pages and further add sub shapes inside those shapes.
To accomplish this, I have followed the below approach:
1) First I add a new Page (newPage) to the Page Collection (pagesCollection)
2) In the newly added page I add shapes using: newPage.Shapes.Add(newShape) - this shape is a part of one stencil which I need to use
3) Now I want to use another stencil and fetch a shape from this stencil and add this to the parent shape added in step 2: something like multiple shapes inside a shape - not sure how to accomplish this.
4) Now all these shapes/pages I want to add to the Diagram object.
For now, what I have done is:
foreach(Page p in pagesCollection)
{
newDiagram.Pages.Add§;
}
5) For saving: newDiagram.Save(“filename”,SaveFileFormat.VDX);
When I do all this, I get errors few of which I have mentioned in the post above.
Please suggest and let me know if you need any further information/code related to this.
Thank You.
-Best Regards,
Agraj
Hi Agraj,
Thank you for these details. I would like to update you that the VSS / VSX stencil file formats are a set of masters/templates which can be used for new diagram creation. Masters should be present in the stencil. You can use the masters from any other diagram as well but master names should match the masters present in the diagram or stencil.
At the moment, you cannot add a new page. I tried the Diagram.Pages.Add method but this is not functioning as expected. I have logged this issue in our issue tracking system as DIAGRAM-33426. Your request has also been linked to this issue and you will be notified as soon as it is fixed.
Please follow up the source code to add each shape from different stencil. I also have attached the document files for your reference.
// Initialize new Diagram object
Diagram diagram = new Diagram();
string templateFileName1 = @“C:\temp\BasicShapes.VSS”;
string masterName1 = “Rectangle”;
// add master
diagram.AddMaster(templateFileName1, masterName1);
long shapeid = diagram.AddShape(2.25, 2.25, masterName1, 0);
string templateFileName2 = @“C:\temp\Stencil2.vss”;
string masterName2 = “GroupMaster”;
// add master from another stencil
diagram.AddMaster(templateFileName2, masterName2);
diagram.AddShape(4.25, 5.25, masterName2, 0);
diagram.Save(@“C:\temp\Output.vdx”, SaveFileFormat.VDX);
Please elaborate a bit more regarding sub shapes. Do you mean adding sub shapes for grouping shape? However, you can add group shapes to the Visio diagram. You need to include group shape as a part of custom stencil.
Please do let me know in case of any confusion or questions.
Hi Imran,
Thank you for the update.
By sub shape I mean, adding a shape inside another shape. For example: There is a page, inside that I want to add a Rectangle. Now, inside this added rectangle I want to add 2 or more square shapes and so on.
Also, I am getting one more error which I posted earlier as well:
[Warning] DataType:
Context: Line 2 — ID='0’
Description: An attribute in this file contains data that is valid but inconsistent with the rest of the file. Visio has ignored the element that contains the attribute.
Please suggest.
Thanks in advance.
-Best Regards,
Agraj
Hi Agraj,
By sub shape I mean, adding a shape inside another shape. For example: There is a page, inside that I want to add a Rectangle. Now, inside this added rectangle I want to add 2 or more square shapes and so on.
Also, I am getting one more error which I posted earlier as well:[Warning] DataType:Context: Line 2 — ID='0’Description: An attribute in this file contains data that is valid but inconsistent with the rest of the file. Visio has ignored the element that contains the attribute.
Hi Imran,
Thank you for your response.
I have attached the desired output which we could successfully generate using Visio Interop library. The file which is getting generated using Aspose.Diagram is also attached and the error file while opening the saved Visio diagram created using Aspose.Diagram is attached as well.
The .net code class files are also attached.
I am trying to generate a view similar to the one in the file: VSTO output - desired document.
There you can see, a new page gets created, different stencils get loaded and shapes are drawn. Also, shapes within shapes are drawn and positioned as shown.
Steps which I follow to generate similar diagram using Aspose.Diagram (mentioned in the code files attached):
1) Create a Diagram and load the template inside that inside VisioEngine.cs file
2) Open stencils and assign those to different diagrams in VisioEngine.cs file
3) Create a new Page inside VisioUtils.cs file
4) Draw shape(s) as mentioned in the type of diagram selected, it can have n number of parent shapes (using DrawCabinet method inside VisioFrontViewGenerator.cs)
5) Pick up shapes drawn in Step 4 one by one and add sub shapes to these shapes (DrawShape method in VisioFrontViewGenerator.cs, DrawShape method is defined in ControllerFrontViewDrawer.cs)
6) Draw these sub shapes and add it to Parent shape
7) Once both these steps (5 and 6) finish, I add these shapes to the Page object created in Step 3
8) Now, I add that page to the Diagram created in Step 1
9) Once all these steps finish, I save the diagram inside SaveVisio method of VisioEngine.cs file in VDX format
All these steps finish successfully, but when I try to open the saved Diagram, I get the error mentioned in the attached txt file AsposeDiagram error file.
Also, as you can see in the file Aspose diagram output file - no shapes are being generated, though a new page gets added.
Please let me know if you have problems understanding any part of this post.
Is there any contact number where I can get in touch with Aspose team so that we can reduce the iterations.
Thank You, looking forward for your suggestions.
-Best Regards,
Agraj
Hi Imran,
In addition to the above post, when I open the VDX file generated using Aspose.Diagram, I every time get the below error, not sure about the cause of the same:
[Warning] DataType:
Context: Line 17241 —
Description: Unexpected end of file.
-Best Regards,
Agraj
Hi Agraj,
Hi Imran,
Any updates on the query?
Request you to increase the priority of the query.
I am able to add page to the diagram now, also I am able to add few shapes, but some duplicate ID of shape warning are coming and all the shapes which I added are not appearing on the page.
Plus, the shapes which are getting added are not positioned properly.
-Best Regards,
Agraj
Hi Agraj,
agraj_nema:
I am able to add page to the diagram now, also I am able to add few shapes, but some duplicate ID of shape warning are coming and all the shapes which I added are not appearing on the page.Plus, the shapes which are getting added are not positioned properly.
The issues you have found earlier (filed as DIAGRAM-33426) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Agraj,
The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.