Results 1 to 3 of 3

Thread: layer routine

  1. #1
    Certifiable AUGI Addict robert.1.hall72202's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,508
    Login to Give a bone
    0

    Default layer routine

    I have the following layer routine:

    Code:
    ; Load the Visual LISP library
    (vl-load-com)
    
    ; Check to see if our custom command reactors
    ; have been loaded into the current drawing
    (if (= hyp-rctCmds nil)
    ; Add the command reactors and the custom callbacks
    (setq hyp-rctCmds (vlr-command-reactor nil '((:vlr-commandCancelled . hyp-cmdAbort)
    (:vlr-commandEnded . hyp-cmdAbort)
    (:vlr-commandCancelled . hyp-cmdAbort)
    (:vlr-commandWillStart . hyp-cmdStart)
    )
    )
    )
    )
    
    ; Callback used when the user presses ECSape
    ; or when the command ends by itself or due to
    ; a problem
    (defun hyp-cmdAbort (param1 param2)
    ; Check to see if our global variable has a value
    ; if it does the set the current layer
    (if (and (/= hyp-gClayer nil)(/= (strcase (getvar "clayer")) (strcase hyp-gClayer)))
    (setvar "clayer" hyp-gClayer)
    )
    ; Clear the global variable
    (setq hyp-gClayer nil)
    )
    
    ; Callbackused when a command is started
    (defun hyp-cmdStart (param1 param2 / currentlayer)
    ; Store the current layer in a global variable
    (setq hyp-gClayer (getvar "clayer"))
    ;check to see what command has been started, the
    ; command name is stored in the param2 variable
    (cond
    ; If either the QDIM command
    ; is active the set the current layer to Dimensions
    ( (or
    (= (car param2) "DIMALIGNED")
    (= (car param2) "DIMANGULAR")
    (= (car param2) "DIMBASELINE")
    (= (car param2) "DIMCONTINUE")
    (= (car param2) "DIMDIAMETER")
    (= (car param2) "DIMLINEAR")
    (= (car param2) "DIMORDINATE")
    (= (car param2) "DIMRADIUS")
    (= (car param2) "QDIM")
    )
    (setLayerCurrent "Dimensions")
    )
    ; If either the HATCH, BHATCH or GRADIENT command
    ; is active the set the current layer to Hatching
    ( (or
    (= (car param2) "HATCH")
    (= (car param2) "BHATCH")
    (= (car param2) "GRADIENT")
    )
    (setLayerCurrent "Hatching")
    )
    ; If either the MTEXT, DTEXT, QLEADER, LEADER command
    ; is active the set the current layer to Text
    ( (or
    (= (car param2) "TTEXT")
    (= (car param2) "DTEXT")
    (= (car param2) "MTEXT")
    (= (car param2) "LEADER")
    (= (car param2) "QLEADER")
    )
    (setLayerCurrent "Text")
    )
    ; If either the LAYER command
    ; is active the clear global variable for the current layer
    ( (or
    (= (car param2) "LAYER")
    (= (car param2) "-LAYER")
    )
    (setq hyp-gClayer nil);Clear the global variable to allow the layer command to change the current layer
    )
    )
    )
    
    ;Set the current layer. If the layer specified does not exist, it will be created.
    ;Thank to Lee Ambrosius for his help with this code.
    (defun setLayerCurrent (layname / acadObj docObj layColl layObj colour)
    (if (= (tblobjname "layer" layname) nil)
    (progn
    (setq acadObj (vlax-get-acad-object))
    (setq docObj (vla-get-activedocument acadObj))
    (setq layColl (vla-get-layers docObj))
    (setq layObj (vla-add layColl layname))
    (setq colour 0)
    (if (= layname "Dimensions")(setq colour 1))
    (if (= layname "Hatching")(setq colour 6))
    (if (= layname "Text")(setq colour 133))
    (vla-put-color layObj colour)
    (setvar "clayer" layname)
    )
    (setvar "clayer" layname)
    )
    )
    Works fine in 2008. What I am getting in 2009 is that sometimes the
    objects (dims, hatch, text, etc.) I cam creating do not have the color
    set to bylayer. I will get white dimensions instead of red. The layers
    seem to be correct.

    Any suggestions?

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: layer routine

    Although the code sets a layer, it does nothing about current entity overrides. You probably want to add this:
    Code:
    (defun setLayerCurrent (layname / acadObj docObj layColl layObj colour)
    (setvar "CEColor" "ByLayer")
    (if (= (tblobjname "layer" layname) nil)
    (progn
    I'm not changing linetype, lineweight, or plot styles, in case you don't desire that. But in most cases CAD Managers don't like object overrides (exceptions happen).
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  3. #3
    Certifiable AUGI Addict robert.1.hall72202's Avatar
    Join Date
    2004-07
    Location
    Detroit Michigan
    Posts
    2,508
    Login to Give a bone
    0

    Default Re: layer routine

    Thanks, that does the trick.
    I am using layers to control the colors so I should be ok.

Similar Threads

  1. LAYER SET ROUTINE
    By sovby254640 in forum AutoLISP
    Replies: 8
    Last Post: 2013-07-12, 03:24 PM
  2. Color to Layer Routine
    By DPB in forum AutoLISP
    Replies: 4
    Last Post: 2008-03-29, 01:45 PM
  3. Replies: 8
    Last Post: 2007-05-16, 01:29 AM
  4. Replies: 10
    Last Post: 2007-04-27, 06:17 PM
  5. Layer manipulation routine...
    By bhansen.114377 in forum AutoLISP
    Replies: 2
    Last Post: 2006-09-19, 08:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •