.NET

Reply
Valued Contributor
StormyC
Posts: 74
Registered: ‎11-19-2010
Message 1 of 12 (457 Views)
Accepted Solution

How a DWG is opened

457 Views, 11 Replies
08-23-2013 02:25 AM

Im hoping to issue a warning if a drawing is double clicked to open it as it sometimes causes AutoCAD to falter.

 

Is there a way to identify how a drawing is being opened?  ie was it by the open menu, double clicking or drag and drop. 

 

Any help would be appreciated.

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 12 (395 Views)

Re: How a DWG is opened

09-09-2013 11:32 AM in reply to: StormyC

I'm sure it's possible to detect the open style, but it will take a lot of work - rewinding, how is autocad faltering? Maybe we should address that first?





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
StormyC
Posts: 74
Registered: ‎11-19-2010
Message 3 of 12 (363 Views)

Re: How a DWG is opened

09-12-2013 04:09 AM in reply to: fenton.webb

Thanks for the reply;

 

Its to do with the order of execution.  I have a startup lisp routine that loads .NET modules once per AutoCAD session (acad.lsp / defun-q the_startup).  One of the .NET functions is executed from a Lisp routine that loads and runs with every document (acaddoc).

 

Due to the order of execution when drawings are double clicked the .NET function isn't available when the lisp is run so the function fails and an error message is issued.  Hence my term "AutoCAD is faltering."

 

This isn't usually a huge problem because its one of my drawing integrity routines that checks our custom data. (Sometimes an ACAD session will crash because it hangs while trying to load the .NET functions if multiple drawings are 'right clicked' and opened without an existing ACAD App running easily avoided....) However, at some point I will need that routine to run always, so, if I could issue a warning when a drawing is double clicked it would be very useful.

 

If I check that the function is loaded by trapping errors I could issue a warning with the possible reason that a drawing is double clicked.  It would be better to know how it was loaded though.

 

Many thanks for your attention.

 

 

 

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 4 of 12 (342 Views)

Re: How a DWG is opened

09-12-2013 10:17 AM in reply to: StormyC

Oh, you don't want to netload from LISP anymore. Best way it to do it from the new Autoloader bundle format. Best thing is to sign up for Autodesk Exchange Apps http://apps.exchange.autodesk.com, download some trial apps, check out their bundle folders that get installed and then modify one to suit your own needs.

 

Also, the detailed documentation on the Autoloader and how it works can be found here http://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
StormyC
Posts: 74
Registered: ‎11-19-2010
Message 5 of 12 (321 Views)

Re: How a DWG is opened

09-13-2013 12:55 AM in reply to: fenton.webb

I've tried that..

 

However, our systems are old, XP pro, the .NET install is shaky at best. For example installing dwf viewer causes AutoCAD to crash at every startup requiring a complete strip of .NET and reinstall.. Sometimes a complete op system rebuild.....  Its something to do with the way certain rights are removed - not being able to edit the registry etc...

 

SO when I did try I try it with AutoCAD 2013 I was getting problems with the custom Ribbon / toolbar loading/unloading.  ie it wasn't working as expected.

 

Oh and while we are on that topic changing the autoloader so that a plugin doesn't load up e.g. for Sketchbook Designer doesn't work on our systems either - I've had to rename the XML so that it gets ignored.........

 

Thanks for your help thus far.

 

(Would still like to know if there is a way to detect how AutoCAD was started.....)

 

Attached is the XML I was using to load up our app.

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 6 of 12 (305 Views)

Re: How a DWG is opened

09-13-2013 07:08 AM in reply to: StormyC

If you are not ready to AutoLoader, loading your .ENY code with acad.lsp is fine. You can skip using acaddoc.lsp to run a command defined iin your .NET assembly, though.

 

You can make your .NET assembly implement IExtensionApplication, and in its Initialize() procedure, you hook up to one of the DocumentCollection event, such as DocumentCreated, DocumaneActivated, and/or DocumentBecameCurrent. Since acad.lsp always gets run regardless how AutoCAD get started, thus, your IExtensionApplication is always loaded, therefore your code can do things with drawing in that AutoCAD session no matter how the drawing is opened. For example, if your code is hooked up with DocumentCreated event, then whenever an drawing is opened in AutoCAD (during the period of drawing being opened in AutoCAD, event DocumentCreated event will fire), you get chance to do something in the event handler. So, indeed, you do not have to care about how drawing is opened (via "Open" command, or user double-click a DWG file in Windows Explorer). Just make sure your code is hooked up to the appropriate DocumentCollection event that suits to your exact need.

 

Valued Contributor
StormyC
Posts: 74
Registered: ‎11-19-2010
Message 7 of 12 (294 Views)

Re: How a DWG is opened

09-13-2013 08:07 AM in reply to: norman.yuan

Many thanks for your input;

 

As I understood it those kind of events are not guaranteed to fire at the point you would expect and I need the drawing to be fully initialised so I have access to all its objects.  I did play with this before and found it to be a little unreliable.

 

From the Help Pages......

Do not rely on the sequence of events.

When writing event handlers, do not rely on the sequence of events to happen in the exact order you think they occur. For example, if you issue an OPEN command, the events CommandWillStart, DocumentCreateStarted, DocumentCreated, and CommandEnded will all be triggered. However, they may not occur in that exact order each and everytime. The only thing you can rely on is that a most events occur in pairs, a beginning and ending event.

 

When I tried it with DocumentCreated AutoCAD would sometimes hang.  I think the above was the reason.

 

 

*Expert Elite*
norman.yuan
Posts: 946
Registered: ‎04-27-2009
Message 8 of 12 (285 Views)

Re: How a DWG is opened

09-13-2013 10:09 AM in reply to: StormyC

Well, the document says "Do not rely on the sequence of events.", not "Do not handle the envent correctly".

 

If your goal is to run some code when a drawing is opened in AutoCAD, regardless how it opens, you certainly can use one of the event as the trigger to run the code. Not knowing what exactly you wna to do, I'd most likely use DocuemtnBecameCurrent event in most cases, because when opening a drawing with "Open" command or double-click a DWG file, the drawing is opened in AutoCAD editor and should become the active drawing, which means, DocumentBecameCurrent is guranteed to be fired with a drawing at least once on it is opened in AutoCAD. of course this event will fire when user switch drawings in AutoCAD. So, you may want to maintain a static list of drawing name to flag which drawing has already be processed with your code, or you can bury the flag with Document.UserData.

 

As matter of fact, I have my code runs against every single drawing opened in AutoCAD, as long as the Acad is set up with our .NET IExtensionApplication preloaded, in my office for years, no matter how the drawing is opened: "Open" command, double-click drawing file name, or even opened by automation application.

 

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 9 of 12 (267 Views)

Re: How a DWG is opened

09-14-2013 09:16 AM in reply to: StormyC

About your XP system kicking and screeming with everything that Autodesk does... You do need to keep your system up-to-date with Windows services packs, otherwise what you say is happening will happen.





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Valued Contributor
StormyC
Posts: 74
Registered: ‎11-19-2010
Message 10 of 12 (241 Views)

Re: How a DWG is opened

09-16-2013 09:34 AM in reply to: norman.yuan

Thanks Fenton.

 

Thanks Norman;  I will see if I can get my code to work using events;

 

The code will need to access object's extended data in the drawing database of the opened drawing.  I certainly dont want this to happen everytime a user makes a drawing current, only when the drawing is 1st opened.

 

Any advice is appreciated....

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community