Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD 2012 SP 1 and Object Reactors

2 REPLIES 2
Reply
Message 1 of 3
TheDarkPrincess
712 Views, 2 Replies

AutoCAD 2012 SP 1 and Object Reactors

I have an objevt reactor that can be tied to circles, ellipses, closed polylines etc (anything that has an area property)

Since updating to SP 1 I've stumbled across a problem - (vla-get-area and (vlax-get-property obj 'Area) used internally within the reactor to determine the area causes the object to re-fire ie the object reactor is treating this call as a modification to the object resulting in an endless loop.

 

Further - doing a qsave causes the reactor to fire.

 

here's the beginning of the function - I've placed a print statment to tell when the reactor is firing.

 

(defun updateareatag ( nobj robj paramlist / areabdry areatxt areaunits factor attlist en ed en1 ed1
                                             prc obj xd temp au apc xareas ar a )
   (princ "\nArea Tag Reactor Fired")
   (if (and
           (not (wcmatch (getvar "cmdnames") "*UNDO,*REDO,*U,*OOPS"))
           (vlax-read-enabled-p nobj)
           (not (vlax-erased-p nobj))
           (vlax-property-available-p nobj "Area")
           (setq en (vlax-vla-object->ename nobj))
           (setq xd (getxdata en))
           (setq areabdry (dos_curvearea en))
;   reactor firing bug with vlax-get-property
;           (setq areabdry  (vla-get-area nobj))
       )

with the reactor as above - here's a clip from commandline for qsave:

 

Command: _qsave
Area Tag Reactor Fired
Area Tag Reactor Fired

 

why it fired twice has to do with auditing before save I think

 

Command: AUDIT

Fix any errors detected? [Yes/No] <N>: y

 

Auditing Header


Auditing Tables


Auditing Entities Pass 1

Pass 1 600     objects audited
Area Tag Reactor Fired
Auditing Entities Pass 2

Pass 2 600     objects audited
Area Tag Reactor Fired
Auditing Blocks

 7       Blocks audited

Total errors found 0 fixed 0

Erased 0 objects

 

now when I switch the lines in red and use vla-get-area instead of dos_lib function:

and do a qsave

 

Command: (defun updateareatag ( nobj robj paramlist / areabdry areatxt
areaunits factor attlist en ed en1 ed1
((_>                                              prc obj xd temp au apc xareas
ar a )
(_>    (princ "\nArea Tag Reactor Fired")
(_>    (if (and
(((_>            (not (wcmatch (getvar "cmdnames") "*UNDO,*REDO,*U,*OOPS"))
(((_>            (vlax-read-enabled-p nobj)
(((_>            (not (vlax-erased-p nobj))
(((_>            (vlax-property-available-p nobj "Area")
(((_>            (setq en (vlax-vla-object->ename nobj))
(((_>            (setq xd (getxdata en))
(((_> ;           (setq areabdry (dos_curvearea en))
(((_> ;   reactor firing bug with vlax-get-property
(((_>            (setq areabdry  (vla-get-area nobj))
(((_>        )

 

now when I execute qsave it loops endlessly

 

Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired
Area Tag Reactor Fired; error: Function cancelled

Area Tag Reactor FiredFunction cancelled
Area Tag Reactor Fired; error: Function cancelled

Area Tag Reactor FiredFunction cancelled; error: Function cancelled

Area Tag Reactor Fired
Command: *Cancel*

 

This did not happen before 2012 SP 1, on 2011, 2010, 2009 and 2008

 

Any ideas or comments are welcome.

 

 

 

 

2 REPLIES 2
Message 2 of 3
Lee_Mac
in reply to: TheDarkPrincess

To avoid infinite callback loops and allow the (possible) modification of the reactor owner object, I use this construct (untested code):

 

(defun updateareatag ( nobj robj params )
    (setq *rdata* (list nobj robj))
    (vlr-command-reactor nil
        (list
            (cons :vlr-commandended     'updateareatag2)
            (cons :vlr-commandcancelled 'updateareatag3)
            (cons :vlr-commandfailed    'updateareatag3)
        )
    )
    (vlr-remove robj)
    (princ)
)

(defun updateareatag2 ( robj params / nobj )
    (vlr-remove robj)
    (if *rdata*
        (progn
            (if
                (and
                    (setq nobj (car *rdata*))
                    (not (wcmatch (car params) "*UNDO,*REDO,*U,*OOPS"))
                    (vlax-read-enabled-p nobj)
                    (not (vlax-erased-p nobj))
                    (vlax-property-available-p nobj 'area)
                )
                (print (vla-get-area nobj))
            )
            (vlr-add (cadr *rdata*))
            (setq *rdata* nil)
        )
    )
    (princ)
)

(defun updateareatag3 ( robj params )
    (vlr-remove robj)
    (if *rdata*
        (progn
            (vlr-add (cadr *rdata*))
            (setq *rdata* nil)
        )
    )
    (princ)
)

 

An example of this can be found here.

 

I hope this helps!

 

Lee

Message 3 of 3
TheDarkPrincess
in reply to: Lee_Mac

I'm not sure why that would help in my situation. this is code that has worked for 5 versions including 2012 and just changed when I upgraded to 2012 sp 1.  and this is happening on a qsave - I mean I easily fixed this by remving the areatag reactor at the start of a save using an editor reactor and restored at the end of the save.  But this didn't help the infinited loop caused by any modification t the entity. replacing all instances of (vla-ger-area nobj) with (dos_curvearea en) fixed the looping. So the issue appears with the service pack affecting how vlisp actually works with object reactors - specifically with (vla-get-area.  none of my other reactors are affected - but none of them obtain the area using vlisp.

 

furthermore command reactors are dangerous beasts with dynamic blocks -


Thanks for the reply.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost