Author Topic: How to check if a dgw fil is openend  (Read 2436 times)

0 Members and 1 Guest are viewing this topic.

Irvin

  • Guest
How to check if a dgw fil is openend
« 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

Jeff H

  • Needs a day job
  • Posts: 6150
Re: How to check if a dgw fil is openend
« Reply #1 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; 
                }               
                               
            } 

Irvin

  • Guest
Re: How to check if a dgw fil is openend
« Reply #2 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to check if a dgw fil is openend
« Reply #3 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;
}
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.