L
LarryF
I need to know if a shape with a particular name exists on a page in a
Visio 2003 drawing control. I could iterate through all the shapes on
the page and check the name of each one, but I'm afraid that that many
trips through the automation barrier would be slow. The way I'm doing
it now is to just try to access the shape and catch the 'Object name
not found' exception if it happens, like this C# code:
using Visio = Microsoft.Office.Interop.Visio;
....
public bool ShapeExists(Visio.Page page, string shapeName) {
try {
Visio.Shape shape = page.Shapes[shapeName];
} catch {
return false; // The shape doesn't exist.
}
return true;
}
Catching an exception to find out if a shape exists is poor design and
causes exception-handling problems in the debugger.
Does anyone know a better way?
Thanks for your help.
Visio 2003 drawing control. I could iterate through all the shapes on
the page and check the name of each one, but I'm afraid that that many
trips through the automation barrier would be slow. The way I'm doing
it now is to just try to access the shape and catch the 'Object name
not found' exception if it happens, like this C# code:
using Visio = Microsoft.Office.Interop.Visio;
....
public bool ShapeExists(Visio.Page page, string shapeName) {
try {
Visio.Shape shape = page.Shapes[shapeName];
} catch {
return false; // The shape doesn't exist.
}
return true;
}
Catching an exception to find out if a shape exists is poor design and
causes exception-handling problems in the debugger.
Does anyone know a better way?
Thanks for your help.