Determining if an object has a reactor attached

Discussion in 'AutoCAD' started by Allen Johnson, Sep 18, 2003.

  1. Is there a simpler way of determining if an object has a reactor attached?
    The only way I've thought of is to step through ALL the reactors and check
    to see if the one of the owner-list objects matches the object.
     
    Allen Johnson, Sep 18, 2003
    #1
  2. So, if I wanted to remove a reactor from an erased object (to get rid of the
    "vlax-error object set to NIL" message when opening a drawing), I'd use
    something like

    (foreach r (attached-to obj)
    (vlr-owner-remove r obj)
    (if (zerop (length (vlr-owners r))) ; no more owners, so
    (progn
    (vlr-remove r) ; disable the reactor -
    isn't the name of this function confusing?!?
    (vlr-pers-release r) ; remove persistance so that
    the reactor won't be here next time
    )
    )
    )
     
    Allen Johnson, Sep 18, 2003
    #2
  3. Allen Johnson

    Luis Guest

    I did something similar some time ago, but could not make it to work, since
    looks (according to my old tests) is that even if you release the persistant
    reactor this is not deleted from the "vl-reactors" dictionary, that is why I
    wrote my own vlr-pers mechanism alike.. I have posted here before... LE.
     
    Luis, Sep 18, 2003
    #3
  4. Yes, I saw that, but was having problems understanding the my-super-command
    function....
     
    Allen Johnson, Sep 18, 2003
    #4
  5. Allen Johnson

    Luis Guest

    Allen,

    Three basic steps:

    1. save the objects in a dictionary.
    2. at loading time re-build your reactors.
    3. every time the erased event happens, remove the objects from the
    dictionary.
     
    Luis, Sep 18, 2003
    #5
  6. You don't remove reactors from erased objects, because
    they can be unerased (UNDO, OOPS, etc.).

    My advice is to avoid persistent reactors entirely as
    they're far more trouble than they're worth, even if
    they did work correctly.

    You can just attach data (e.g., extension dictionaries
    with an xrecord) to objects, and when a drawing is opened,
    you find and attach non-persistent reactors to all those
    objects.
     
    Tony Tanzillo, Sep 18, 2003
    #6
  7. Allen Johnson

    Luis Guest

    Doug,

    That is very similar/equal of what I do but in Spanish.
     
    Luis, Sep 18, 2003
    #7
  8. My code seems to work OK with persistent reactors, except for the
    "vlax-error object set to NIL" message when reopening the drawing. I guess
    I could live with that. (i.e. I haven't figured out dictionaries yet.)

    What other problems might I encounter?
     
    Allen Johnson, Sep 18, 2003
    #8
  9. Allen Johnson

    Luis Guest

    Allen,

    Please test the following, just paste it in your erased event callback
    function and let us know if works. ;)

    (if (vlax-erased-p owner)
    (vla-delete
    (vlax-ename->vla-object
    (cdr
    (assoc 350
    (dictsearch (namedobjdict) (vlr-pers-dictname)))))))

    Luis.
     
    Luis, Sep 18, 2003
    #9
  10. Allen Johnson

    Luis Guest

    I think I found something...<as always talking alone - whatever>

    ;;; 1:23 PM 9/18/2003 by Luis Esquivel

    (defun test (owner reactor params)
    (prompt "\nThis is only a test... \n"))

    (defun erased (owner reactor params)
    (if (vlax-erased-p owner)
    (progn

    ;; remove the owner
    (vlr-owner-remove reactor owner)

    ;; remove the receiver from the dictionary
    ;; I think this will get rid of the error-msg at opening time
    (vlr-data-set reactor nil)

    ;; in case we need to delete the receiver
    ;;; (vla-delete (car data))

    )))

    (defun c:tst (/ vla_line vla_circle :tst-reactor)
    (setq vla_line (vlax-ename->vla-object (car (entsel "\nLine: "))))

    (setq vla_circle
    (vlax-ename->vla-object (car (entsel "\nCircle: "))))

    (setq :tst-reactor
    (vlr-object-reactor
    (list vla_line)
    (list vla_circle)
    '(:)vlr-modified . test)
    :)vlr-erased . erased))))

    (setq :tst-reactor (vlr-pers :tst-reactor)))
     
    Luis, Sep 18, 2003
    #10
  11. (defun leader_obj_erased (nobj robj plist / r RLIST)
    (setq rlist (car (attached-to nobj)))
    (foreach r rlist
    (vlr-owner-remove r nobj)
    (if (zerop (length (vlr-owners r))) ; no more owners, so
    (progn
    (vlr-remove r) ; disable the reactor - isn't the name of this
    function confusing?!?
    (vlr-pers-release r) ; remove persistance so that the reactor won't
    be here next time
    (vlr-data-set r nil)
    )
    )
    )
    )


    I put in the (vlr-data-set nil) but still got the

    ; warning:erased VLA-object restored to NIL

    message when reopening...

    I haven't tried your previous method yet, but it appears that you don't
    think it worked either.

    Thanks for helping.

    From what TT said, it appears that this is a bug in visual lisp?
     
    Allen Johnson, Sep 18, 2003
    #11
  12. Allen Johnson

    Luis Guest

    Try this please (and about what Tony mentioned is the same think I do):

    (defun leader_obj_erased (nobj robj plist / r RLIST)
    ;;; (setq rlist (car (attached-to nobj)))
    ;;; (foreach r rlist
    ;;; (vlr-owner-remove r nobj)
    ;;; (if (zerop (length (vlr-owners r)))
    ;;; (progn
    ;;; (vlr-remove r)
    ;;; (vlr-pers-release r)
    ;;; (vlr-data-set r nil)
    ;;; )
    ;;; )
    ;;; )

    (if (vlax-erased-p nobj)
    (progn

    (vlr-owner-remove robj nobj)

    (vlr-data-set robj nil)

    ))
    )
     
    Luis, Sep 18, 2003
    #12
  13. Hey, if I took out the length check (there were still owners in the list),
    it worked!

    (defun leader_obj_erased (nobj robj plist / r RLIST)
    (setq rlist (car (reactors-attached-to nobj)))
    (foreach r rlist
    (vlr-owner-remove r nobj)
    (vlr-remove r)
    (vlr-pers-release r)
    (vlr-data-set r nil)
    )
    )
     
    Allen Johnson, Sep 18, 2003
    #13
  14. Allen Johnson

    Luis Guest

    Allen, please double check that, I tested here before and works too.

    Then, we (I) don't have to use my own custom vlr-pers anymore!

    have fun,
    Luis Esquivel
     
    Luis, Sep 18, 2003
    #14
  15. Allen Johnson

    Luis Guest

    :)



    Allen Johnson

    yea right...

    (time to update all my object-reactor command from draftteam...this
    weekend.)


    Luis.
     
    Luis, Sep 18, 2003
    #15
  16. Allen Johnson

    Luis Guest

    I will document this in my samples of simple vlisp-reactors project and let
    others understand at least the basics on object reactors too.

    Luis Esquivel
    Caddximation Software
    http://www.draffteam.com
     
    Luis, Sep 19, 2003
    #16
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.