global variables question

Mark Propst

Usenet Archive
Joined
May 2, 2000
Messages
492
Reaction score
0
For the past year or so I've been running with some globals set for the convenience of several vla routines they are loaded from a lisp file Globals.lsp which is called by acaddoc.lsp and therefore loads with each dwg. ex:
(vl-load-com)
(or *acad* (setq *acad* (vlax-get-acad-object)))
(or *doc* (setq *doc* (vla-get-activedocument *acad*))) (or *Mspace* (setq *Mspace* (vla-get-modelspace *doc*)))
etc.....

I've read on this ng about the need to destroy these objects before closing acad thus:
; Notes:
; Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event ; to release the global objects at the end of a session - otherwise AutoCAD may crash

well, being pathologically lazy and sloppy I haven't implemented this reactor business - guess I'm more scared of reactors than wandering globals....

and of course acad does crash on occasion - it has always crashed on occasion ever since I started using around rel12 dos. - so I'm so used to that, that I can't tell any difference since I've been declaring these globals.

so the question is, do I need to get to trying to figure out that reactor doomahickey or is it not an urgent necessity????

and as I'm trying to think about these global objects, since this loads with each drawing, they are just global to the document space, not to the acad session ....is that right?

so if I have 5 drawings open I have 5 versions of *acad* and *doc*, .... is that right?

so the reactor would be defined like also in the acaddoc.lsp file or called from there so that it would be loaded in each drawing as well, .... is that right?

but a docManagerReactor I would think was an Editor reactor as opposed to a document level reactor, so maybe the above is not right?

any input on this?
tia
Mark
 
Mark,
I agree with what the others said. The most important things to remove when the drawing is closed are REACTORS. If reactors are not properly removed, they can continue to act without their own namespace generating errors and, in some cases, crashing AutoCAD.

Any variables that are bound to objects internal to the documents should be localized where possible.

I have tried to minimize my use of globals. I haven't found a significant difference in speed except within loops in accessing the acad and document objects with the built in functions.

Using reactors to destroy globals will certainly cause more problems than it solves.

Regards,
Doug
 
Thanks Tony,
Once again my laziness and procrastination (at implementing the reactor) ends up looking like disciplined self control (by eliminating unnecessary coding). That makes me laugh!
:-)))

Tony Tanzillo said:
Not sure where you're getting this advice from,

I've seen it in a number of posts on this ng a while back...when the vla discussions began to proliferate.

I paraphrased that note out of a header from a file by Menzi

; -- Function VxGetDimStyles
; Returns a list of all dimension style names
; Copyright:
; ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
; None
; Return [Typ]:
; > List of Dim style names

  • ; Notes:
    ; Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event ; to release the Gb:AcO and Gb:AcD objects at the end of a ; AutoCAD session - otherwise AutoCAD maybe crashes... (defun VxGetDimStyles ( / DstLst) (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
    Gb:AcD (cond (Gb:AcD) ((vla-get-ActiveDocument Gb:AcO))) ) (vlax-for Dst (vla-get-DimStyles Gb:AcD) (setq DstLst (cons (vla-get-Name Dst) DstLst)) ) (reverse DstLst)
    )
 
LISP is a garbage-collected (a.k.a. "Managed") language, and there's no need to do any clean up WRT varaibles. There is a need to disconnect reactors because the namespace where they live can be destroyed and they'll continue to be fired.

Visual LISP does not manage reactors properly (they should be automatically disconnected when the namespace containing them is destroyed).

Mark Propst said:
Thanks Tony,
Once again my laziness and procrastination (at implementing the reactor) ends up looking like disciplined self control (by eliminating unnecessary coding). That makes me laugh!
:-)))

Tony Tanzillo said:
Not sure where you're getting this advice from,

I've seen it in a number of posts on this ng a while back...when the vla discussions began to proliferate.

I paraphrased that note out of a header from a file by Menzi

; -- Function VxGetDimStyles
; Returns a list of all dimension style names
; Copyright:
; ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
; None
; Return [Typ]:
; > List of Dim style names

  • ; Notes:
    ; Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event ; to release the Gb:AcO and Gb:AcD objects at the end of a ; AutoCAD session - otherwise AutoCAD maybe crashes... (defun VxGetDimStyles ( / DstLst) (setq Gb:AcO (cond (Gb:AcO) ((vlax-get-acad-object)))
    Gb:AcD (cond (Gb:AcD) ((vla-get-ActiveDocument Gb:AcO))) ) (vlax-for Dst (vla-get-DimStyles Gb:AcD) (setq DstLst (cons (vla-get-Name Dst) DstLst)) ) (reverse DstLst) )
 
Does this apply to simple reactors that monitor system variables such as TILEMODE to change LTSCALE/DIMSCALE ? We have a lot of sporadic crashing in the office and I'd like to clean up what ever I can.

If so, any tips on disconnecting reactors?

Thanks,

Dan
 
I don't use Visual LISP for much these days
(limited to very simple functions and command
scripting and testing code written in other
languages).

Most of my work is done in C++ and Delphi.
 
Luis Esquivel said:
is strange I supposed is because of the virus that is around right now, maybe my provider is locking some emails, let me ask them, I still receiving emails. Can you try one more time, please.

rejected again from our office server, but I did send another via my earthlink account.

Your message did not reach some or all of the intended recipients.

Subject: Re: global variables question
Sent: 8/21/2003 9:56 AM

The following recipient(s) could not be reached:

'' on 8/21/2003 9:57 AM
The recipient name is not recognized
The MTS-ID of the original message is: c=US;a=
;p=BCVARCH;l=RAIDSERVER-030821165629Z-2862
MSEXCH:IMS:BCVARCH:RAIDSERVER:RAIDSERVER 3503 (000B09AA) 503
5.0.0 Need MAIL before RCPT
 

Latest threads

Back
Top