Run a Command when a Specific Drawing Opens

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to have a command execute when a drawing is opened. Specifically I want this functionality to be associated with a particular file, not to be executed for all files that are opened. I know that modifications can be made to the ACADDOC.lsp file to change the startup behaviors of AutoCAD when a document opens, but from what I understand this can only be done such that every document that is opened adopts this startup behavior. This is not ideal in my situation.
My motivation is this:
My company uses an AutoCAD application to convert spreadsheets to blocks in AutoCAD. The blocks that are created are not linked to the excel file, so the user must update the block any time a change is made using a command built in to the application. The company is pretty set on not using OLE's or any different software for uploading spreadsheets. My boss has asked me to find a way to get the spreadsheet-update command to run when a drawing is opened because he finds the process of updating it manually tedious.
I've already solved the problem on the excel side with a macro that runs whenever the spreadsheet is saved, and I wrote a macro in AutoCAD's VBA editor to run the command. In excel I'm able to place my macro in the "ThisWorkbook" module and change the header such that the macro is associated with a particular behavior within the workbook (i.e. saving). But when I try to do something similar in AutoCAD I can't seem to get my macro to run correctly.
I've already run the AutoCAD macro from within the VBA editor and it executes correctly, but I can't seem to find the correct header that will make the macro run when that drawing is opened. I'm also unsure if I'm writing my macro into the correct location.
I've had a lot more experience writing macros for excel, and I seem to be having a hard time understanding how to run them in AutoCAD. I've got a little bit of experience with LISP, and if that's the only solution I can hopefully figure out how to get it working, but a solution with Visual Basic is definitely preferable. That being said, I'm also interested in learning how to write LISP routines for AutoCAD, so feel free to toss in any good links you might have for a beginner.
Definitely appreciate any help, sorry if this problem is oddly specific.