Can I do "multithreaded" apps for Acad in VBA?

Discussion in 'AutoCAD' started by perry, Jun 3, 2004.

  1. perry

    perry Guest

    That may not be the proper term, but heres the gist of it.
    I have an application which I load through the startup suite, it is then
    initialized via SS:startup in AcadDoc.lsp
    this initialization merely sets some global variables such as the document
    name etc. it then calls the main program
    which checks numerous conditions in the drawing. This initialization, being
    in the ss:startup, is run each time a drawing is opened.
    That last sentence there is the crux of my dilema. I want this program to
    initialize and run each time a drawing is opened, including
    when multiple drawings are open.
    At this point, Im not sure about the proper use of the AcadApp object and
    AcadDoc object. Should I create global references to them
    at the start of the program so that any "peripheral" fuctions I may invoke
    (either during or after the main program has run) will have acces
    to these global references, this also seems to imply that at the end of the
    main program these refernces are NOT set to nothing since other
    functions will need them later (thus depending on VBA to "garbage clean" on
    end of acad).
    Or should I clear these references at the end of the main program and any
    other functions that may need these will declare, then clear,
    their own copies??
    After trying the first method, using global references, I thought this may
    be wrong. Since after closing a second document, the first document
    seemed to "lose" the value of AcadObject and AcadDoc.

    I am also kinda murky on the use of Events within this program. I am using
    the ss:startup mentioned above because the "BeginOpen" event
    isnt quite right for this app because it fires before the drawing is fully
    opened so I could get some weird results. The BeginOpen event also
    does not seem to fire when Acad is first invoked. The "NewDrawing" event
    also doesnt seem to fire when Acad is first invoked. Alternatively
    the "BeginClose" event seems unfit for what I want because like the
    previous, it fires before the drawing is fully closed (and any underlying
    document,
    if any, gets the focus). So for example if I want to re-establish the
    current drawing name during this event I get the wrong name.
    So I have got into the habit of extensive use of the "EndCommand" event and
    doing things there. My main question then is since I want this
    application to run its own independent copy for each open drawing, should I
    check for events indicating a drawing has closed and set the
    AcadObject and AcadDoc references to nothing? (assuming Im using the
    "global" method) Also, in this same vein, should I check for the
    DocActivate and Deactive events and do the same (including setting New
    Object references)?
    One more thing on events. I have put all these in an EventClassModule and
    there are a few lines in my initialization code (which runs on each
    open drawing) which initializes these event functions. Is it proper to
    initialize these events on each drawing, or should it be done only once
    during an Acad session?

    Theres quite a bit of good vba example code out there, but I havent yet
    found any that makes extensive use of events, or any that
    is clearly designed to run in muliple instances. The documenttation is kinda
    skimpy here too. Anyone know where I might find
    some of this treasure?
    Thanks for any tips.
     
    perry, Jun 3, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.