I have the following layer routine:
Works fine in 2008. What I am getting in 2009 is that sometimes theCode:; 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) ) )
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?


Reply With Quote