pausing with reactors

Discussion in 'AutoCAD' started by jlspartz, Dec 9, 2004.

  1. jlspartz

    jlspartz Guest

    I'm working on getting all xrefs to be automatically put on layer 0 (no comments on that please) so I have this so far:

    (vl-load-com)
    (setvar "cmdecho" 0)
    (command "._undefine" "xref")
    (setvar "cmdecho" 1)
    (defun c:xref ( / x *acad-object* *acad-doc*)
    (setq *acad-object* (vlax-get-acad-object))
    (setq *acad-doc* (vla-get-activedocument *acad-object*))
    (setq x (vla-add (vla-get-layers *acad-doc*) "0"))
    (vla-put-activelayer *acad-doc* x)
    (vla-sendCommand *acad-doc* "._XREF\n")
    (vlax-release-object *acad-doc*)
    (vlax-release-object *acad-object*)
    )

    It works great, but I'd like to be able to set it back to the previous layer after the xref is done being dropped in. How do I get it to pause for the user input and the perform the command?
     
    jlspartz, Dec 9, 2004
    #1
  2. jlspartz

    T.Willey Guest

    If you only want to get the current layer and put if back you can do.

    (setq clay (getvar "clayer"))

    do stuff here

    (setvar "clayer" clay)

    Tim
     
    T.Willey, Dec 9, 2004
    #2
  3. jlspartz

    jlspartz Guest

    yes, but i need to pause after the xref command and wait for the user and then after the xref is in set the layer back. if you add those two lines of code you got without pausing, it will get the current layer, set it to 0, do the xref command and bring up the dialog box, and behind the scenes switch the layer back to the previous one before ever getting the xref in there on layer 0.
     
    jlspartz, Dec 9, 2004
    #3
  4. jlspartz

    T.Willey Guest

    (vl-load-com)
    (setvar "cmdecho" 0)
    (command "._undefine" "xref")
    (setvar "cmdecho" 1)
    (defun c:xref ( / x *acad-object* *acad-doc*)
    (setq *acad-object* (vlax-get-acad-object))
    (setq *acad-doc* (vla-get-activedocument *acad-object*))
    (setq x (vla-add (vla-get-layers *acad-doc*) "0"))
    (setq clay (vla-get-activelayer *acad-doc*)) ; <-- do this then
    (vla-put-activelayer *acad-doc* x)
    (vla-sendCommand *acad-doc* "._XREF\n")
    (vla-put-activelayer *acad-doc* clay) ; <-- do this then
    (vlax-release-object *acad-doc*)
    (vlax-release-object *acad-object*)
    )


    Tim
     
    T.Willey, Dec 9, 2004
    #4
  5. jlspartz

    Jeff Mishler Guest

    This doesn't appear to be a reactor so you could use (command "xref") in
    place of the (vla-sendcommand) then use the oft posted
    (while ( < 0 (getvar "cmdactive"))
    (command pause)
    )

    Or, if you want to use reactors, why not just use the command-ended event,
    check if the command was XREF and change the last entity's layer property to
    0.

    As an aside, you don't need to check for or create layer "0", it is always a
    part of a drawing.


    Jeff
    check out www.cadvault.com
     
    Jeff Mishler, Dec 9, 2004
    #5
  6. jlspartz

    Doug Broad Guest

    A couple of points which don't necessarily answer your question but seem appropriate:
    1) Your code is not a reactor. It is a simple command.
    2) Adding layer "0" is unnecessary since it exists by default.
    3) In general, it is unnecessary to release the current document and the acad object.
    4) A commandended reactor would solve your problem. Use your new xref
    command to create the command reactor. The commandended callback should
    look for the last entity, check that it's a block reference, change its layer to 0 and then
    undefine the reactor (vlr-remove..). The pauses will be unnecessary because the
    xref command will continue after your substitute xref lisp ends.
    5) Your command won't solve situations where another program is used to
    attach the xref and where xattach is used rather than xref. A database reactor
    might but it would be too active to be of much use.

    Note: Tim's code will change your current layer (which may be undesirable).

    I leave the code to you.
     
    Doug Broad, Dec 9, 2004
    #6
  7. jlspartz

    Dann Guest

    I got this a while back on the 'net somewhere.
    It may be what you are looking for....If not, at least it's educational :)

    (prompt " \nLoad Only....Do NOT Run...")
    (vl-load-com)
    (vlr-command-reactor
    nil
    '(:)vlr-commandWillStart . startCommand)
    )
    )
    (vlr-command-reactor
    nil
    '(:)vlr-commandEnded . endCommand))
    )
    (vlr-command-reactor
    nil
    '(:)vlr-commandCancelled . cancelCommand))
    )
    (defun startCommand
    (calling-reactor startcommandInfo / thecommandstart)
    (setq OldLayer (getvar "CLAYER"))
    (setq thecommandstart (nth 0 startcommandInfo))
    (cond
    ((= thecommandstart "XREF")
    (setvar "CLAYER" "0")
    )
    )
    (princ)
    )

    (defun endCommand (calling-reactor endcommandInfo / thecommandend)
    (setq thecommandend (nth 0 endcommandInfo))
    (cond
    ((= thecommandend "XREF")
    (setvar "CLAYER" OldLayer)
    )
    )
    (princ)
    )
    (defun cancelCommand
    (calling-reactor cancelcommandInfo / thecommandcancel)
    (setq thecommandcancel (nth 0 cancelcommandInfo))
    (cond
    ((= thecommandcancel "XREF")
    (setvar "CLAYER" OldLayer)
    )
    )
    (princ)
    )
    (princ)
     
    Dann, Dec 10, 2004
    #7
  8. Not a reactor, but this one puts all x-refs on layer s-xref (this could be
    changed to whatever you want but that's what I want....) Also, It uses
    DosLib, which is worth having imho.

    It could also be modified to use entmod instead of command and chprop if so
    desired.

    C-ya

    Casey


    (defun c:xlay ( / fullist name ss dwg)

    (IF (NOT (TBLSEARCH "LAYER" "S-XREF"))

    (COMMAND "LAYER" "NEW" "S-XREF" "")

    )

    (SETQ FULLIST (DOS_XREFLIST))

    (if fullist(foreach dwg fullist

    (setq name (vl-filename-base dwg))

    (setq ss (ssget "x" (list (cons 0 "insert")(cons 2 name))))

    (command "chprop" ss "" "layer" "s-xref" "")




    )

    )

    )

    comments on that please) so I have this so far:
    layer after the xref is done being dropped in. How do I get it to pause for
    the user input and the perform the command?
     
    Casey Roberts, Dec 14, 2004
    #8
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.