Redefine vs. Reactors

Discussion in 'AutoCAD' started by Daniel J. Altamura, R.A., Dec 22, 2004.

  1. I need some advice as to which approach to take regarding text and dimension
    command customization. I want to make text and dimensions easier and more
    consistent for my users. For example, I want my textsetup routine to
    initiate whenever a text command is used, and my dimsetup routine to
    initiate whenever a dimension command is used. These setup routines set the
    proper layer, textstyle, dimstyle, dimscale, etc. I have three methods for
    doing this. Each has advantages and disadvantages. What do you think?

    1. Define separate commands such as AQLEADER, AMTEXT, ADIMLINEAR, keeping
    the original AutoCAD commands intact. This approach might not be obvious to
    new users, until they learn the new commands. This also won't work for
    pulldowns and toolbars, unless I customize the main AutoCAD menu. I don't
    want to do that. I only use partial menus.

    2. Use reactors to run the appropriate setup routine before the text and
    dimension commands. This will be automatic for the user, but may not offer
    enough flexibility. What happens if they want to put text or dimensions on
    another layer, or use another style, for some reason? I'm not sure this
    approach has any advantages over #3.

    3. Undefine the AutoCAD commands, and redefine my own versions of each.
    This is also automatic for the user, but may not offer enough flexibility.
    With this method, however, they can always precede the command with "." to
    run the original AutoCAD command.

    Thanks for any help or insight.
    Dan
     
    Daniel J. Altamura, R.A., Dec 22, 2004
    #1
  2. Daniel J. Altamura, R.A.

    kemp Guest

    We use the first option. Our users are aware they must use the text
    commands in the partial menu so I don't worry about them and it seems to
    work well for us.

    kemp
     
    kemp, Dec 22, 2004
    #2
  3. I'd vote for using reactors. I've tried the redefinition
    of commands and it doesn't really work that well. In
    some instances you loose the implied windowing.

    In the event that the users need to do something
    different, as you noted, you could always provide
    a way to turn the reactor off.

    That is what I have done with my "Layering Tools"
    Here is a prompt from my code.

    [Enable/Disable/Reset/About]specify option <enable>:

    As you can see, it would very easy for a user to
    turn it off, do what they need, then turn it back on.
     
    Jason Piercey, Dec 22, 2004
    #3
  4. Wasn't option #2 already done? Search for a routine called AutoLay


    ;|=====================================================================
    autolay[2].lsp V2.0 complete with notes (maybe too many even) and all
    For Autocad 2000 and above
    Date: 8-18-00, Converted everything to ActiveX/LISP
    Written by: Eric Schneider, Reno, NV

    With special thanks to the greatest minds in the Autodesk Customization
    newsgroup:
    Sebastien Perreault
    R. Robert Bell
    Frank Oquendo
    Jimmy B. (?)
    Silvio Camolesi
    Tony Tanzillo and
    Cliff Middleton
    (not necessarily in that order) whos contributions made
    it possible for me to figure this all out for you!
    The knowledge you have given me is hereby returned to the public domain.
    =======================================================================
    This program automatically creates and switches to layers for dimensions,
    text hatches and viewports, then restores the layers to their previous
    states when the command has ended. Or it's supposed to anyway!
    =======================================================================
     
    Allen Johnson, Dec 22, 2004
    #4
  5. Thanks for the reply. I already have the reactors written. I am testing
    out all three options to find the best solutions, based upon the
    requirements that I listed.

    --
    Daniel J. Altamura, R.A.
    Altamura Architectural Consulting
    and SoftWorx, Autodesk Authorized Developer
    --------------------------------------------------------------------


     
    Daniel J. Altamura, R.A., Dec 22, 2004
    #5
  6. Hi Daniel,

    Reactors are the way to go.... even with all the limitations...

    Have a look at "drawhelp" at www.draffteam.com it might help....
     
    Luis Esquivel, Dec 23, 2004
    #6
  7. Luis,
    Thanks for the reply. Why, in your opinion, should I use reactors instead?
    What limitations do you foresee? I am very interested to know? I did look
    at drawhelp previously. Very nice!

    Dan
     
    Daniel J. Altamura, R.A., Dec 23, 2004
    #7
  8. Jason,
    Thanks for the reply. Can you recall in what instances implied windowing
    doesn't work? I have not run into this problem yet, and would like to hear
    what you have to say.

    Dan
     
    Daniel J. Altamura, R.A., Dec 23, 2004
    #8
  9. IIRC, it was the redefinition of some dimension
    commands and/or the mtext command. I know
    I posted here about it, but can't seem to find all
    the details while searching google.

    I'll see if I still have the old code (I might of trashed
    it already) laying around to reproduce the errors.

    Perhaps things have changed with the newer releases
    and this isn't a problem anymore, I don't know.
     
    Jason Piercey, Dec 23, 2004
    #9
  10. Thanks Jason. It would be helpful if you could find that info. I still
    have to support previous versions of AutoCAD.
     
    Daniel J. Altamura, R.A., Dec 23, 2004
    #10
  11. Daniel J. Altamura, R.A.

    Doug Broad Guest

    Daniel,
    I use approach 1. Have used it since before reactors were available.
    Reactors have advantages and if I were doing it again, I might consider
    doing it that way. IMO, you should do whatever you feel most
    comfortable doing and which makes sense for your organization.

    These days palettes can take care of most of these issues for you without
    programming.

    Regards,
    Doug
     
    Doug Broad, Dec 23, 2004
    #11
  12. Thanks for the reply Doug. In your opinion, specifically, what are the
    advantages of using reactors? I have all three methods working, but must
    choose one. How is using a reactor any different functionally from
    redefining commands? After I finished writing the reactors, I realized that
    they basically did the exact same thing as redefining the commands, it just
    took more effort. Please enlighten me.

    Dan
     
    Daniel J. Altamura, R.A., Dec 23, 2004
    #12
  13. undefined commands are very easy to break, simple by using the dot in front of the built-in command.

    with reactors we can monitor several parts where we can force or do our own things, even to cancel a built-in or lisp routine and force ours....

    reactors have some limitations, like even that it is possible to run from containers like properties or layer/linetype... pull-downs, with the sysvar reactors events, this in my opinion does not work the effort, because of the possibilities of have a lot of loops.

    in the form i use the sysvar reactors today is to grab a variable flag that later i can compare to do any update in other event.

    reactors can be turn off this in the case of simple by deleting the file where resides the code or not loading them, or if they are not inside of a protected separate namespace vlx.

    there is a way to force the reactors to be loaded on per drawing basis.

    for example, if an smart command [from a separate namespace vlx] is used within a drawing session and then the session is being saved, the next time that drawing is open, the vlx will be loaded even if the vlx file is not on the autocad support's paths.

    this might be use only by a decision of the end-user, since it will saved on the database, and is not easy to delete.

    here is what do you need to place:

    (vlax-ldata-put "my_dictionary" "my_custom_cmds" nil t)

    and saved your separate namespace vlx, standard is just fine.

    then load it in one drawing, save the drawing open it again and the vlx will be loaded.... try it....

    regards,
    luis.
     
    Luis Esquivel, Dec 23, 2004
    #13
  14. Daniel J. Altamura, R.A.

    Doug Broad Guest

    Reactor Advantages:
    1)Can change built-in command behavior such that it can't be worked around
    without removing the reactor. Redefined commands can always be circumvented
    by using the "." prefix.
    2)Either eliminates the need to change the current layer (Items created during the command
    can be re-layered afterwards.) or simplifies the process of restoring layers.
    3)No need to build in special input loops. You let the command take care of
    its own input process.
    4)Simpler cleanup-routines when commands are cancelled.

    There are probably more but those are a few examples. VBA versions, called
    event handlers, can also work across documents more easily.
     
    Doug Broad, Dec 23, 2004
    #14
  15. Daniel J. Altamura, R.A.

    GaryDF Guest

    I would vote for reactors.
    Redefine can be canceled out with the dot before the command name.

    Here is what I use for controlling layers.

    Using AutoCAD 2005 on Windows 2000
    Works perfectly.

    Gary


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;; VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

    ;;; Vlr Command is a function that will switch the active layer in a drawing.
    ;;; The reactor checks the command that is starting and if it recognizes it
    ;;; it will switch to a specified layer. If the layer doesn't exist it will
    ;;; create it with the color, linetype, and plottable setting provided.
    ;;; To load and run this program add the lines (load
    "vlr_command")(c:vlr_command)
    ;;; to your acaddoc.lsp or another autoloading lisp routine.

    (defun VLR_COMMAND-IT ()
    (vl-load-com)
    (vlr-command-reactor nil '(:)vlr-commandWillStart . startCommand)))
    (vlr-command-reactor nil '(:)vlr-commandEnded . endCommand)))
    (vlr-command-reactor nil '(:)vlr-commandCancelled . cancelCommand)))
    (vlr-editor-reactor nil '(:)vlr-commandwillstart . ARCH:COM1)))
    )
    (princ "\n*** ------ Layer Reactor Activated. ------ ***")
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun ARCH:COM1 (CALL CALLBACK / COMLAYLST)
    ;;; List of corrusponding commands layers color linetype plottable
    (setq COMLAYLST
    (list (list "DIMANGULAR" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMBASELINE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMCENTER" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMCONTINUE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMDIAMETER" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMLINEAR" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMORDINATE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMRADIUS" "A-DIMS" 30 "continuous" :vlax-true)
    (list "QDIM" "A-DIMS" 30 "continuous" :vlax-true)

    (list "LEADER" "A-NOTE" 2 "continuous" :vlax-true)
    (list "QLEADER" "A-NOTE" 2 "continuous" :vlax-true)

    (list "DTEXT" "A-NOTE" 2 "continuous" :vlax-true)
    (list "MTEXT" "A-NOTE" 2 "continuous" :vlax-true)
    ;;(list "TEXT" "A-NOTE" 2 "continuous" :vlax-true)

    ;;(list "BHATCH" "A-PATT" 9 "continuous" :vlax-true)
    ;;(list "HATCH" "A-PATT" 9 "continuous" :vlax-true)

    (list "POINT" "X-PNTS" 4 "continuous" :vlax-true)

    (list "XLINE" "X-LINE" 8 "continuous" :vlax-true)
    (list "XREF" "0-XREF" 7 "continuous" :vlax-true)
    )
    )
    (foreach
    N COMLAYLST
    (if (= (strcase (car CALLBACK)) (strcase (car N)))
    (progn
    (make_layers
    (cadr N)
    (caddr N)
    (cadddr N)
    (car (cddddr N))
    )
    (setq n1 n)
    (vla-put-activelayer
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    (vlax-ename->vla-object
    (tblobjname "LAYER" (cadr N))
    )
    )
    )
    )
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;; Make layers using activeX
    (defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
    (setq CDWGOBJ (vla-get-activedocument
    (vlax-get-acad-object)
    )
    LAYSOBJ (vla-get-layers CDWGOBJ)
    )
    (if (not (tblobjname "layer" LAY_NAM))
    (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
    )
    )
    (setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
    (if (not (tblobjname "ltype" LTYPE))
    (progn
    (setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
    (vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
    (vlax-release-object LTYPESOBJ)
    )
    )
    (vla-put-layeron LAYOBJ :vlax-true)
    (if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
    (vla-put-freeze LAYOBJ :vlax-false)
    )
    (vla-put-lock LAYOBJ :vlax-false)
    (vla-put-color LAYOBJ COLOR)
    (vla-put-linetype LAYOBJ LTYPE)
    (vla-put-plottable LAYOBJ PLOTL)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;Kenny Ramage @ afralisp.com
    (defun startCommand (calling-reactor
    startcommandInfo
    /
    thecommandstart
    )
    (setq OldLayer (getvar "CLAYER"))
    ;;(vlr-editor-reactor nil '(:)vlr-commandwillstart . ARCH:COM1)))
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun endCommand (calling-reactor
    endcommandInfo
    /
    thecommandend
    )
    (setq thecommandend (nth 0 endcommandInfo))
    (cond
    ((= thecommandend "DIMANGULAR") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMBASELINE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMCENTER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMCONTINUE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMDIAMETER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMLINEAR") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMORDINATE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMRADIUS") (setvar "CLAYER" OldLayer))
    ((= thecommandend "QDIM") (setvar "CLAYER" OldLayer))

    ((= thecommandend "LEADER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "QLEADER") (setvar "CLAYER" OldLayer))

    ((= thecommandend "DTEXT") (setvar "CLAYER" OldLayer))
    ((= thecommandend "MTEXT") (setvar "CLAYER" OldLayer))
    ;;((= thecommandend "TEXT") (setvar "CLAYER" OldLayer))

    ;;((= thecommandend "BHATCH") (setvar "CLAYER" OldLayer))
    ;;((= thecommandend "HATCH") (setvar "CLAYER" OldLayer))

    ((= thecommandend "POINT") (setvar "CLAYER" OldLayer))

    ((= thecommandend "XLINE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun cancelCommand (calling-reactor
    cancelcommandInfo
    /
    thecommandcancel
    )
    (setq thecommandcancel (nth 0 cancelcommandInfo))
    (cond
    ((= thecommandcancel "DIMANGULAR") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMBASELINE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMCENTER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMCONTINUE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMDIAMETER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMLINEAR") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMORDINATE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMRADIUS") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "QDIM") (setvar "CLAYER" OldLayer))

    ((= thecommandcancel "LEADER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "QLEADER") (setvar "CLAYER" OldLayer))

    ((= thecommandcancel "DTEXT") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "MTEXT") (setvar "CLAYER" OldLayer))
    ;;((= thecommandcancel "TEXT") (setvar "CLAYER" OldLayer))

    ;;((= thecommandcancel "BHATCH") (setvar "CLAYER" OldLayer))
    ;;((= thecommandcancel "HATCH") (setvar "CLAYER" OldLayer))

    ((= thecommandcancel "POINT") (setvar "CLAYER" OldLayer))

    ((= thecommandcancel "XLINE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (VLR_COMMAND-IT)
     
    GaryDF, Dec 23, 2004
    #15
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.