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.
Solved! Go to Solution.
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?
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.
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/auto
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.
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.
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......
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.
Well, the document says "", 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.
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.
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....
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register