Get Text in CFF container - Pool / Lane


Hi,

Thanks for all your help in the last days. I have a doubt gettin a text in the Fcc Container an Pool / line. I Used the code of the example guide, but I cant find in this shapes.

This is the code and attached is the project (vs 2015).

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 Aspose.Diagram; using System.Data; using Aspose.Diagram; using System.IO; using System.Text.RegularExpressions;

namespace GetText
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void btnRead_Click(object sender, EventArgs e)
    {
        readfile("file.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)));
        dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string)));
        dt.Columns.Add(new System.Data.DataColumn("Master", 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();
                r["Text"] = GetShapeText(shape);
                r["Master"] = shape.Master.Name;
                dt.Rows.Add(r);
            }
            
        }
        dataGridView1.DataSource = dt;
     
    }
    private string GetShapeText(Aspose.Diagram.Shape shape)
    {
        string shapeText = "";
        if (shape.Text.Value.Text != "")
            shapeText += Regex.Replace(shape.Text.Value.Text, "\\<.*?>", "");
        if (shape.Type == TypeValue.Foreign)
            shapeText += (shape.Name);
        if (shape.Type == TypeValue.Group)
            foreach (Aspose.Diagram.Shape subshape in shape.Shapes)
            {
                GetShapeText(subshape);
            }

        return shapeText;
    }
}

}



Thank you for your patience and great help!!

Consu

Hi Consu,


Thank you for contacting support. You are iterating through the sub shapes as well, but not storing sub shape details in the data table object. You may declare a global data table, and then store shape details inside the GetShapeText method. Please update your code as below:

[.NET, C#]
static DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void btnRead_Click(object sender, EventArgs e)
{
readfile(“file.vsd”);
}
private void readfile(string fileName)
{
dt.Columns.Add(new System.Data.DataColumn(“Shape”, typeof(string)));
dt.Columns.Add(new System.Data.DataColumn(“Shape Id”, typeof(string)));
dt.Columns.Add(new System.Data.DataColumn(“Text”, typeof(string)));
dt.Columns.Add(new System.Data.DataColumn(“Master”, 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)
{
GetShapeText(shape);
}
}
dataGridView1.DataSource = dt;
}

private void GetShapeText(Aspose.Diagram.Shape shape)
{

DataRow r = dt.NewRow();
r[“Shape”] = shape.Name + “-” + shape.NameU;
r[“Shape Id”] = shape.ID.ToString();
r[“Master”] = shape.Master.Name;


string shapeText = “”;
if (shape.Text.Value.Text != “”)
shapeText += Regex.Replace(shape.Text.Value.Text, “\<.*?>”, “”);
if (shape.Type == TypeValue.Foreign)
shapeText += (shape.Name);
if (shape.Type == TypeValue.Group)
foreach (Aspose.Diagram.Shape subshape in shape.Shapes)
{
GetShapeText(subshape);
}
r[“Text”] = shapeText;
dt.Rows.Add®;

}

Please let us know in case of any confusion or questions.