In Visio VBA (or COM API)
How can i get a shape without expecting an exception when the shape name is not found?
... in my visio page, there might or might not be a Rectangle Shape with the name "DraftText".
i want to check that it is there and if yes, do smth.
my code seems like:
Shape waterMarkRect = page.Shapes["DraftText"];
if (waterMarkRect == null)
{
waterMarkRect = page.DrawRectangle(0, 0, 50, 15);
waterMarkRect.Name = "DraftText";
waterMarkRect.NameU = waterMarkRect.Name;
waterMarkRect.Text = "INCONSISTANT";
Layer wMarkLayer = page.Layers["WMark"] ?? page.Layers.Add("WMark");
wMarkLayer.Add(waterMarkRect, 0);
}
...
...
The problem is that, if the shape "DraftText" is not there, i get a COM Exception.
as i am against using try catch block as a coding utility,
i am searching for a way to check for the shape existance prior to taking it such as IDictionary.TryGetValue(, out);
or if(page.Shapes.Contain("DraftText"))...
Any Ideas?