Reactor Heck!

Discussion in 'AutoCAD' started by Steven Craig Basham, Jun 23, 2004.

  1. AAARGH! I'm so close, yet so far from solving this problem I'm going bald!
    :p

    I've created a reactor as noted below... the reactor event modified fires
    off swimmingly. However, I am uncertain how to DEAL with the event... what
    I wanted to do was change the draworder of the reactor_object to be in the
    front. As you can imagine, I've instantly created an unending loop... it's
    changed, and reissues modified, and it's changed, and reissues
    modified...etc.

    Can someone help me with the Noted_Moved function (pseudocode or actual)
    that will only fire the draworder if the location of the reactor_object has
    changed? My knowledge of reacter is brand new, and I'm trying to
    conceptualize how to use them as quickly as I can.

    Thank you so much for your help!

    Steven Craig Basham

    (...
    (setq NOBJ (entget (entlast)))
    (setq newNOBJ (cdr(car nobj)))
    (setq vlNOBJ (vlax-ename->vla-object (cdr(car nobj))))
    (setq note_reactor (vlr-object-reactor (list vlNOBJ) "Note Reactor"
    '(:)vlr-modified . Note_Moved))))
    (vlr-pers note_reactor)
    (command "QLATTACH" (cdr(car lobj)) newnobj )
    ....)

    The following function is my REACTION to a modified reactor-object... I'm
    really only interested in firing this function if the location of the object
    has changed.

    (defun Note_moved (reactor_owner reactor_object reactor_list / enameObj )
    (setq enameObj (vlax-vla-object->ename reactor_owner))
    (command "DRAWORDER" enameObj "" "F")
    )
     
    Steven Craig Basham, Jun 23, 2004
    #1
  2. You might try setting a global flag in the Note_Moved and checking its value. If it is not set then
    set it and run the command.
    Else if it's set, then this reactor is already running so don't process anything.

    (defun Note_moved (reactor_owner reactor_object reactor_list / enameObj )
    (if (not REACTOR_RUNNING )
    (progn
    (setq REACTOR_RUNNING T)
    (setq enameObj (vlax-vla-object->ename reactor_owner))
    (command "DRAWORDER" enameObj "" "F")
    (setq REACTOR_RUNNING nil)
    )
    )

    )
     
    Allen Johnson, Jun 23, 2004
    #2
  3. Does that not fire the reactor event if you use it (vla-sendcommand)?
     
    Allen Johnson, Jun 23, 2004
    #3
  4. I could not find that command as listed... do you mean vl-cmdf ?
     
    Steven Craig Basham, Jun 23, 2004
    #4
  5. I think Luis is referring to the "reactor guidelines"

    <snip>

    Do not use any interactive functions in your reactor
    callback function (for example, do not use getPoint,
    entsel). Attempting to execute interactive functions
    from within a reactor callback function can cause
    serious problems, as AutoCAD may still be processing
    a command at the time the event is triggered. Therefore,
    avoid the use of input-acquisition methods such as
    getPoint, entsel, and getkword, as well as selection set
    operations and the command function.

    <snip>
     
    Jason Piercey, Jun 23, 2004
    #5
  6. But how would vla-sendcommand be any different than using the command function?
     
    Allen Johnson, Jun 23, 2004
    #6
  7. It is different because the help file says so :)

    vla-sendcommand is permitted in a callback
    and the command function is not.

    I'm no expert on reactors, but everything thing
    I have ever read on the subject leans torward
    no calls to the command function inside a callback.
     
    Jason Piercey, Jun 23, 2004
    #7
  8. Okay... I think I found the issue with commands from a callback...

    INTERNAL ERROR: !U:\global\dbqspace.h@386:eWasOpenForWrite

    it is happening on this line:

    (vl-cmdf "DRAWORDER" enameObj "" "F")

    I'm very frustrated now... :( If you can't send command from a callback,
    what good is one?
     
    Steven Craig Basham, Jun 23, 2004
    #8
  9. If LE and JP think sendcommand will work, try this instead:


    (setq *doc* (vla-get-activedocument (vlax-get-acad-object) ) ; initializes the document object
    (vla-sendcommand *doc* "Draworder !enameObj F ")
     
    Allen Johnson, Jun 23, 2004
    #9
  10. Both your method (and mine) seemed to work....
    But it's actually Steven's routine!

    (defun C:TST ()
    (setq obj (vlax-ename->vla-object (car (entsel))))

    (if (not reactor)
    (setq reactor
    (vlr-object-reactor
    (list obj)
    "testing only"
    '(:)vlr-modified . Note_moved)))
    )
    )
    )

    (defun Note_moved (reactor_owner reactor_object reactor_list / doc enameObj)
    (setq enameObj (vlax-vla-object->ename reactor_owner))
    (setq doc (vla-get-activedocument (vlax-get-acad-object))) ; initializes the document object
    (vla-sendcommand doc "Draworder !enameObj F ")
    )
     
    Allen Johnson, Jun 23, 2004
    #10
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.