Get text from visio shapes

D

dink337

How would I go about accessing the text (that was typed in) in shapes through
C#?

I have a basic hierarchical diagram in visio that is based on a "True/False"
structure (parent has two children - one each for true and false, which in
turn has a granchild for each true/false, and so on).

The idea is to have text in each true/false shape that I want to "pull out"
and read through a C# app.

How would I go about doing this? Any simple samples would be great, or if
there's a resource online you could point me to.

Ideally, I'd like to be able to pass in the name of the file (visio document
path), then somehow loop through each object (shape) and get the text
displayed in each one.

Any help on this would be extremely appreciated.

Thanks,

Dez
 
A

AlEdlund

I'd probably start with the visioSDK, since it has a lot of C# code in it.

in vba it looks something like
dim strText as string
strText = visShape.text

al
 
D

David J Parker

best to use :
strText = visShape.Characters.text

AlEdlund said:
I'd probably start with the visioSDK, since it has a lot of C# code in it.

in vba it looks something like
dim strText as string
strText = visShape.text

al
 
D

dink337

Thanks for the help (both).

I was able to get going in the right direction using the
"Microsoft.Office.Interop.Visio" dll to open and parse the shapes.

Something like this is what I'm currently playing with:

ApplicationClass visapp = new ApplicationClass();
Document doc = visapp.Documents.Open(@"c:\temp\myFile.vsd");
Page page = visapp.ActivePage;

foreach (Shape shp in page.Shapes)
{
rtb1.Text += shp.Characters.Text + "\n";
}

I'm just opening the file, looping through the shapes collection then
writing each shapes' text to a rich text box on a form (just for testing).

Works great so far (just what I was after).

- Dez
 

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