Author Topic: Run Code Upon Opening Document  (Read 2095 times)

0 Members and 2 Guests are viewing this topic.

patrickcraig31

  • Mosquito
  • Posts: 3
Run Code Upon Opening Document
« on: August 29, 2018, 10:40:03 AM »
Hello,

Does anyone know how to run code using the event of opening a document? I would like to load the cuix file every time a document is opened.




Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Run Code Upon Opening Document
« Reply #2 on: August 29, 2018, 07:17:16 PM »
Several methods as alluded to above

You didn't say what language so I'll provide VB.Net

First you need to capture the document collection. To make use of the existing events, simply declare the variable WithEvents like so (public or private as the case warrants) You will need to make it a global variable within your class(s)

Code - vb.net: [Select]
  1. Private WithEvents docManager = Autodesk.AutoCAD.ApplicationServices.DocumentCollection

Now you can capture document events like this:

Code - vb.net: [Select]
  1. Private Sub docManager_DocumentActivated(sender as Object, e As DocumentCollectionEventArgs) Handles docManager.DocumentActivated
  2.    'DoStuffHere
  3. End Sub
  4.  
  5. Private Sub docManager_DocumentCreated(sender as Object, e As DocumentCollectionEventArgs) Handles docManager.DocumentCreated
  6.    'DoStuffHere
  7. End Sub


Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Run Code Upon Opening Document
« Reply #3 on: August 30, 2018, 08:51:38 AM »