Looking for a stable reactor to automatically create layers (on certain commands)

Discussion in 'AutoCAD' started by CraigV\(fs\), Nov 24, 2004.

  1. CraigV\(fs\)

    CraigV\(fs\) Guest

    Haven't tried AutoLay yet.

    Is there a good VBA version of this sort of routine?

    I basically am looking to automate the following commands -> layers.

    Qleader - "A-Anno-Note"
    Dim* - "A-Anno-Dims"
    Mview - "G-Anno-View"
    Ray,Xline - "G-Anno-Nplt"

    Thanks.

    Craig
     
    CraigV\(fs\), Nov 24, 2004
    #1
  2. Marco Jacinto, Nov 25, 2004
    #2
  3. CraigV\(fs\)

    CraigV\(fs\) Guest

    Thanks, I'll give that a try.

    I had a similar VBA routine (BeginCommand & EndCommand) and I was getting
    some crashes.

    CV
     
    CraigV\(fs\), Nov 29, 2004
    #3
  4. I think this occurs when you have two reactors working in the same event
     
    Marco Jacinto, Nov 29, 2004
    #4
  5. CraigV\(fs\)

    GaryDF Guest

    Here is some code to do what you want...this will get you going.

    Gary


    for multiple commands:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;; 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)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;









    for just xref command:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;; 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_COMMANDXREF-IT ()
    (vl-load-com)
    (vlr-command-reactor nil '(:)vlr-commandWillStart . startCommandxref)))
    (vlr-command-reactor nil '(:)vlr-commandEnded . endCommandxref)))
    (vlr-command-reactor nil '(:)vlr-commandCancelled . cancelCommandxref)))
    (vlr-editor-reactor nil '(:)vlr-commandwillstart . ARCH:COMXREF1)))
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun ARCH:COMXREF1 (CALL CALLBACK / COMLAYLST)
    ;;; List of corrusponding commands layers color linetype plottable
    (setq COMLAYLST
    (list
    (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 startCommandxref (calling-reactor
    startCommandxrefInfo
    /
    thecommandstart
    )
    (setq OldLayer (getvar "CLAYER"))
    ;;(vlr-editor-reactor nil '(:)vlr-commandwillstart . ARCH:COMXREF1)))
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun endCommandxref (calling-reactor
    endCommandxrefInfo
    /
    thecommandendxref
    )
    (setq thecommandendxref (nth 0 endCommandxrefInfo))
    (cond
    ((= thecommandendxref "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (defun cancelCommandxref (calling-reactor
    cancelCommandxrefInfo
    /
    thecommandcancelxref
    )
    (setq thecommandcancelxref (nth 0 cancelCommandxrefInfo))
    (cond
    ((= thecommandcancelxref "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (VLR_COMMANDXREF-IT)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;
    (princ)
     
    GaryDF, Dec 1, 2004
    #5
  6. Craig,

    I am working on a modified version of AutoLay, adding a GUI interface
    using ObjectDCL, not VBA.

    It will handle the first two items in your list, the other two will
    have to be added.

    It will be a month or so till it is done.

    Basically, what you had to set up in AutoLay code to fit your
    environment, is set up using dialogs.

    You have CommandGroups which are currently: Dimension, DimCenter, Hatch
    Text, and Vport (will add MView and Ray). The Dimension CommandGroup,
    for example, is a list of all of the dimensioning commands. You assign a
    layer to the Dimension CommandGroup using the dialog config program,
    very easy to do. Then whenever any of the commands listed in the
    Dimension CommandGroup is run, the result is placed on the assigned layer.

    Qleader is a member of the Dimension CommandGroup but you want it on a
    different layer than the other dim commands. There is a Conditional
    functionality that allows you to define a different layer for Qleader
    from the other dimension commands. The conditions also allow things like
    if TextStyle1 is used, the text goes on one layer and if TextStyle2 is
    used, it goes on another layer.

    This extends to textheights also. If the text is less than a certain
    size, use one layer, if greater, use a different layer. This
    functionality is relatively easy to set up using a dialog driven
    interface. You fill in the conditions, and the program writes the code.

    The program is pretty mature, I wrote the basics a couple of years ago
    and it worked well. The version I am working on now is a rewrite, adding
    functionality and improving the interface. Trying to make it as easy as
    possible to use.

    Thinking about all I have to do yet, it may be more than a month, but if
    you like you can email me and I'll send you a copy when it is finished.
    It will be freeware.

    I would be remiss if I did not acknowledge the impressive work that Eric
    Schneider did in creating Autolay.

    Larry Leuallen
     
    Larry Leuallen, Dec 1, 2004
    #6
  7. CraigV\(fs\)

    Doug Broad Guest

    Tool palettes allow you to automatically layer BTW.
     
    Doug Broad, Dec 2, 2004
    #7
  8. CraigV\(fs\)

    CraigV\(fs\) Guest

    Thanks, Larry. Send me a copy when you are finished- I would appreciate
    that.

    I'm like you, I get a little time to develop a routine, then the next
    project deadline kicks in and it gets put on hold for a while...


    Craig
     
    CraigV\(fs\), Dec 3, 2004
    #8
  9. CraigV\(fs\)

    Doug Broad Guest

    Hi Luis,

    True. But no programming needed. :)


     
    Doug Broad, Dec 3, 2004
    #9
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.