TheSwamp

Code Red => .NET => Topic started by: Irvin on November 07, 2011, 07:02:57 AM

Title: How to check if a dgw fil is openend
Post 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
Title: Re: How to check if a dgw fil is openend
Post by: Jeff H on November 07, 2011, 11:02:20 AM
Code: [Select]
   DocumentCollection docs = Application.DocumentManager;
           foreach (Document doc in docs)
            {
                if (doc.Name == "C:\\TheDrawingYouWant.dwg")
                {
                    Application.DocumentManager.MdiActiveDocument = doc; 
                }               
                               
            } 
Title: Re: How to check if a dgw fil is openend
Post by: Irvin on November 08, 2011, 03:21:48 AM
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
Title: Re: How to check if a dgw fil is openend
Post by: Kerry on November 08, 2011, 04:48:40 AM

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 ...

Code: [Select]
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;
}