TheSwamp
Code Red => .NET => Topic started by: Irvin on November 07, 2011, 07:02:57 AM
-
Hi there,
I need to open a drawing. i know how to do that. But i need to know if the drawing is already openend in autocad. Now each time when i run my open command
the drawing is opened again. And that's not what i want. First check if the drawing is already opened if so make it the current drawing if not open the file.
i know how to add all open drawing to a DocumentCollection but that has no contains or has function.
How can i check if the drawing is already opened if make it current.
Kind regards,
Irvin
-
DocumentCollection docs = Application.DocumentManager;
foreach (Document doc in docs)
{
if (doc.Name == "C:\\TheDrawingYouWant.dwg")
{
Application.DocumentManager.MdiActiveDocument = doc;
}
}
-
Hi Jeff,
Thats what i already came up with. I only need to add a return in the loop when it found it. Stupid mee. My mind must have been on a long weekend absent.
Kind regards,
Irvin
-
If you are concerned with matching Upper/Lower Case characters ...
have a look at string.Compare
perhaps try something like this in a test method that you can pass the docCollection and NameToTest to ...
public static Document GetDocumentFrom ( DocumentCollection dc, string docName )
{
foreach ( Document doc in dc ) {
if ( string.Compare( docName, doc.Name, true ) == 0 )
return doc;
}
return null;
}