How to get Visio ShapeData information with C#?

Asked By 480 points N/A Posted on -
qa-featured

I am a programmer and I am facing a problem while using the Visio document. I am writing my codes on c# and using custom templates, stencils, and masters of Visio document.

I am coding a programmed that will take Shape Data information (properties, labels, values, prompts, etc.) and/or external data information of a shape on my chosen template.

During my work I dropped the shapes on a Visio 2007 page and I can get which shapes are on the pre-defined page.

However, I can’t find a workaround to take the properties of a shape on my code in C#.
 
Code:
 
 Visio.Page visioPage2 = this.Application.ActivePage;
////
 int shapeCount2 = visioPage2.Shapes.Count;
 for (int i = 1; i < shapeCount2; i++)
            {
                shapenameArray[i] = visioPage2.Shapes[i].Name;
                shapepromptArray[i] = visioPage2.Shapes[i].Master.Prompt;
                string data1 = visioPage2.Shapes[i].Data1;
                string data2  = visioPage2.Shapes[i].Data2;
                string data3 = visioPage2.Shapes[i].Data3;
                string text  = visioPage2.Shapes[i].Text;
                short type = visioPage2.Shapes[i].Type;
                int id = visioPage2.Shapes[i].ID;                
                shapeinfoArray[i] = visioPage2.Shapes[i].MasterShape.Text;
                string property = visioPage2.Shapes[i].get_Cells("Prop.NameOfProperty").Formula;
            }
////
  
The code above gives me the shape prompt value however no label names, values or types are noticed for the Shape Data defined on Vision.
 
I shall be very thankful to you if give your expert opinions on this issue.

SHARE
Best Answer by molasbryani
Answered By 0 points N/A #98534

How to get Visio ShapeData information with C#?

qa-featured

Hi Joanna,

Here is the code that might help you.

public void DrawSampleShapeConnection()
{
// get the current draw page
Visio.Page currentPage = axDrawingControl1.Document.Pages[1];

// Load the stencil we want
Visio.Document currentStencil = axDrawingControl1.Document.Application.Documents.OpenEx("Basic_U.vss", (short)Visio.VisOpenSaveArgs.visOpenDocked);

// show the stencil window
Visio.Window stencilWindow = currentPage.Document.OpenStencilWindow();

// this gives a count of all the stencils on the status bar
int countStencils = currentStencil.Masters.Count;

toolStripStatusLabel1.Text = string.Format("Number of Stencils in {0} = {1}", currentStencil.Title, countStencils);
statusStrip1.Refresh();

// create a triangle shape from the stencil master collection
Visio.Shape shape1 = currentPage.Drop(currentStencil.Masters["Triangle"], 1.50, 1.50);

// create a square shape from the stencil master collection
Visio.Shape shape2 = currentPage.Drop(currentStencil.Masters["Square"], 10, 7.50);

// create a dynamic connector from the stencil master collection
Visio.Shape connector = currentPage.Drop(currentStencil.Masters["Dynamic connector"], 4.50, 4.50);

// currentPage.Layout();

// connect the shapes together through the dynamic connector
ConnectShapes(shape1, shape2, connector);

}

Best Answer
Best Answer
Answered By 0 points N/A #98535

How to get Visio ShapeData information with C#?

qa-featured

To get Visio ShapeData information with C# ,one should use get_SectionExists(short Section, short fExistsLocally) to check if a section exists in the Shape first.

After using the get section and checking for the section in the shape we got to iterate through all of the rows. You can use the following codes to get the visio shape data.

short iSect = (short) Visio.visCetionIndices.visSectionProp;
if (0 != shp.get_SectionExists(iSection, (short)Visio.VisExistsFlags.visExistsAnywhere))
{
 for (short iRow = 0; iRow < shp.get_RowCount(iSection);++iRow)
 {
  if (0 != shp.get_CellsSRCExists(iSection, iRow, (short)Visio.VisCellIndices.visCustPropsValue,                                        (short)Visio.VisExistsFlags.visExistsAnywhere))
  {
   string rowName = shp.get_CellsSRC(iSection, iRow, (short)Visio.VisCellIndices.visCustPropsValue).RowNameU;
   //Your code here???
  }
 }
}

Now we are done and it can be seen that the visio shape data is got.

Answered By 0 points N/A #98536

How to get Visio ShapeData information with C#?

qa-featured

Visio shape is a deal of information in the form of shapes and application drawings. There are more skills that integrate Visio application with other organizations database. We can assign custom properties.

We can add many fields to the text as we need. To portray a diagram it is often considered to put some information or read or some information in shapes in the diagram.

In order read those information there are two ways which can be performed. Visio custom properties must be used properly which will be one choice and the other is to have the information portrayed stored in the form of a database.

Of the two choices/ways given the second choice will be the best one to execute as it is more versatile as it has the ability to query a database with other such business applications.

Related Questions