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

Free Support Forum - aspose.com

Aspose. Diagrama - Error Connecting shapes - Id "shape to" does not exist

I need your help connecting shapes.

I am reading a visio file using aspose, in the first part I have a list with the shapes (Shape, Id) and other list with connectors (shape from, shape to).

The shape to (Id 344) does not exist in my list of shapes.

What can I do?

Attached is the project in visual studio 2015 and the image “ThisIdDoesnotexist.png” with the result.

My code is the following.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data;

using Aspose.Diagram;

using System.IO;


namespace ConnShapes

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}


private void btnRead_Click(object sender, EventArgs e)

{

readfile("CnnShapes.vsd");

}

private void readfile(string fileName)

{

DataTable dt = new DataTable();

dt.Columns.Add(new System.Data.DataColumn("Shape", typeof(string)));

dt.Columns.Add(new System.Data.DataColumn("Shape Id", typeof(string)));


DataTable dt2 = new DataTable();

dt2.Columns.Add(new System.Data.DataColumn("Shape From", typeof(string)));

dt2.Columns.Add(new System.Data.DataColumn("Shape To", typeof(string)));



string licencepath = @"d:\Aspose.Total.lic";


Aspose.Diagram.License diagramLicense = new Aspose.Diagram.License();

diagramLicense.SetLicense(licencepath);


FileStream st = new FileStream(fileName, FileMode.Open);

Diagram vsdDiagram = new Diagram(st);


foreach (Aspose.Diagram.Page page in vsdDiagram.Pages)

{

foreach (Aspose.Diagram.Shape shape in page.Shapes)

{

DataRow r = dt.NewRow();

r["Shape"] = shape.Name + "-" + shape.NameU;

r["Shape Id"] = shape.ID.ToString();

dt.Rows.Add(r);

}

foreach (Aspose.Diagram.Connect connector in page.Connects)

{

DataRow r = dt2.NewRow();

r["Shape From"] = connector.FromSheet.ToString();

r["Shape To"] = connector.ToSheet.ToString();

dt2.Rows.Add(r);

}

}

dataGridView1.DataSource = dt;

dataGridView2.DataSource = dt2;


}

}

}


Thanks for your help.

Hi Consu,


Thank you for contacting Aspose support.

Let me summarize my understanding of the said scenario so I may evaluate the case properly. As per your problem description, you are concerned that you’re missing the shape with Id 344 in the sample document CnnShapes.vsd however, it is still listed in ConnectCollection. Is it correct?

Hi,


the Id 344 is missing in the shape list… and when I try to connect the shape 352 to 344 I can´t.

Hi Consu,


Thank you for the details. We’re working over your query and will get back to you soon. Please spare us a little time.

Hi Consu,


Thank you for being patient. The sub shape (ID: 344) of a group shape (ID: 343) is connected with the connector shape (ID: 352). You may apply a check of the group shape in the code as below:

[.NET, C#]
foreach (Aspose.Diagram.Shape shape in page.Shapes)
{
DataRow r = dt.NewRow();
r[“Shape”] = shape.Name + “-” + shape.NameU;
r[“Shape Id”] = shape.ID.ToString();
dt.Rows.Add®;
if (shape.Type == TypeValue.Group)
foreach (Aspose.Diagram.Shape subshape in shape.Shapes)
{
DataRow subshapeR = dt.NewRow();
subshapeR[“Shape”] = shape.Name + “-” + shape.NameU;
subshapeR[“Shape Id”] = subshape.ID.ToString();
dt.Rows.Add(subshapeR);
}

}

To get the name and ID of each shape, you may recursively iterate through the sub shapes as we have written a code example to get text of each shape in this help topic: Extract Plain Text of the Visio Diagram Page