jediderek
jediderek

Reputation: 319

Visio: Cannot find shape in a group shape

I am transfering vba code over to c# using the Microsoft.Office.Interop.Visio library. I am having a hard time figuring out why I'm getting an "Object name not found" exception. Code below:

foreach (IVisio.Shape t in GroupStall.Shapes)
                    {
                        Console.WriteLine(t.Name);
                    }
                    var aa = "door" + index;
                    IVisio.Shape test = GroupStall.Shapes.ItemU[aa];

I'm using the for each loop for debugging purposes. In the output of foreach is:

headrail2
headrail1
toilet1
toprail1
siderail1A
door1
stallwidth1

I already know that "door1" exist in there so I shouldn't need to always go through a foreach loop just to assign it to a shape object. But when I get to assigning "door1" shape to "test, I get the exception, "Object name not found." Any help on why?

Upvotes: 0

Views: 805

Answers (1)

jediderek
jediderek

Reputation: 319

Already found the answer to my own question. In C# if you want to assign a shape object using a shape's name you use:

IVisio.Shape test = GroupStall.Shapes["name"]

I found this weird because I could not do this in VBA, VBA you had to use the item method to find a shape by name:

test = GroupStall.Shapes.Item("name")

Hope this helps anyone else developing in visio using C#.

Upvotes: 1

Related Questions