Simple Read Text from shapes/Change current page

D

David Benedict

Hello,

I am new to Visio Automation. I have a program where I simply need to read
the text from the Visio Shapes to look for specific text within the shape.
I have tried using:

Visio.Application.ActivePage.Shapes.Item(0).Text.ToString()

But this returns an error. I have searched and searched for a simple
example of how to get the text, but it is difficult to find.

I also need to loop through the pages, and I could not find a simple example
to change the active page.

Any help or websites would be greatly appreciated. (VB.Net or C# doesn't
matter)

Thanks.

David Benedict
 
C

Chris Roth [MVP]

Hi David!

Try this snippet:


Visio.Document visDoc = visApp.ActiveDocument;

foreach( Visio.Page pg in visDoc.Pages )
{
foreach( Visio.Shape shp in pg.Shapes )
{
Console.WriteLine( shp.Text );
}
}

Also, if a shape is a group, then it can also have a Shapes collection -
shp.Shapes[3].Shapes[0].Text, etc.

I've got a few more code examples on my web log:
http://www.wanderkind.com/visio/

And John Marshall has a ton on his:
http://visio.mvps.org/VBA.htm

--
Hope this helps,

Chris Roth
Visio MVP

More Visio shapes, articles, development info and pure diagramming fun at:
www.wanderkind.com/visio
 
D

David Benedict

Thanks SO MUCH!

I think this is the heirarchy I was looking for.

David

Chris Roth said:
Hi David!

Try this snippet:


Visio.Document visDoc = visApp.ActiveDocument;

foreach( Visio.Page pg in visDoc.Pages )
{
foreach( Visio.Shape shp in pg.Shapes )
{
Console.WriteLine( shp.Text );
}
}

Also, if a shape is a group, then it can also have a Shapes collection -
shp.Shapes[3].Shapes[0].Text, etc.

I've got a few more code examples on my web log:
http://www.wanderkind.com/visio/

And John Marshall has a ton on his:
http://visio.mvps.org/VBA.htm

--
Hope this helps,

Chris Roth
Visio MVP

More Visio shapes, articles, development info and pure diagramming fun at:
www.wanderkind.com/visio



David Benedict said:
Hello,

I am new to Visio Automation. I have a program where I simply need to
read
the text from the Visio Shapes to look for specific text within the shape.
I have tried using:

Visio.Application.ActivePage.Shapes.Item(0).Text.ToString()

But this returns an error. I have searched and searched for a simple
example of how to get the text, but it is difficult to find.

I also need to loop through the pages, and I could not find a simple
example
to change the active page.

Any help or websites would be greatly appreciated. (VB.Net or C# doesn't
matter)

Thanks.

David Benedict
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top