View Full Version : Set layer prior to command
Thomas Maleski
2007-06-21, 08:51 PM
I'm trying to have autolayer when adding a linear dimension
(defun c:DD ()
(setq clay (getvar "clayer")
tlay (setvar "clayer" "s-dims"))
(command "dimlinear")
(setvar "clayer" clay)
)
But it put the current layer back early.
It's something simple.
rkmcswain
2007-06-21, 09:02 PM
Not sure what version you are using, but can you use a Tool Palette button? If so, there is no code involved and much easier....
ccowgill
2007-06-21, 09:13 PM
I'm trying to have autolayer when adding a linear dimension
(defun c:DD ()
(setq clay (getvar "clayer")
tlay (setvar "clayer" "s-dims"))
(command "dimlinear")
(setvar "clayer" clay)
)
But it put the current layer back early.
It's something simple.
you forgot a couple of pauses after dimlinear (for user input)
Thomas Maleski
2007-06-21, 09:29 PM
That was it, I was having writers block.
(defun c:DD ()
(setq clay (getvar "clayer")
tlay (setvar "clayer" "s-dims"))
(command "_dimlinear" pause pause)
(setvar "clayer" clay)
)
Yes I know about the toolpalettes but I have some old school drafters, if they had their way I would have the screen menu working as well.
Mike_R
2007-06-21, 09:40 PM
Writing a routine for dimensions that involves pauses can be problematic and/or bug ridden. Put enough pauses in to actually finish the command, or put in a while loop that runs a pause while the dim command is active, and it will work just fine, as long as you don't try and input custom text during the command. Trying to do that will give you a dimension with a text string of "//////////////////////////////////////////////////////////////////////////////," etc....
In my experience, this is best done with a reactor after the fact that will change the layer of the dimension object itself, once it's created...
Regards,
Mike
aaronic_abacus
2007-06-21, 09:43 PM
(defun c:DD ()
(setq clay (getvar "clayer"))
(command "layer" "m" "s-dims" "")
(setq tlay (setvar "clayer" "s-dims"))
(command "dimlinear")
(setq lp 1)
(while lp
(if (> (getvar "cmdactive") 0) (command pause) (setq lp nil))
);end lp
(setvar "clayer" clay)
)
kpblc2000
2007-06-22, 06:25 AM
Another way:
(defun c:dd2 (/ *error* clay adoc)
(defun *error* (msg)
(if clay
(vl-catch-all-apply '(lambda () (setvar "clayer" clay)))
) ;_ end of if
(vla-endundomark adoc)
(princ msg)
(princ)
) ;_ end of defun
(vl-load-com)
(vla-startundomark
(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
) ;_ end of vla-startundomark
(setq clay (getvar "clayer"))
(command "_.-layer" "_m" "s-dims" "")
(command "_.dimlinear")
(while (/= (logand (getvar "cmdactive") 31) 0)
(command pause)
) ;_ end of while
(vl-catch-all-apply '(lambda () (setvar "clayer" clay)))
(vla-endundomark adoc)
(princ)
) ;_ end of defun
ccowgill
2007-06-22, 01:30 PM
;; Check if Dim_Reactor is loaded in the task otherwise load it ( Do NOT load a reactor more than once )
(if (not Dimwillstart_Reactor )
(setq Dimwillstart_Reactor (vlr-command-reactor nil '((:vlr-commandwillstart . My_Dimstart_Command ))) )
( ) ;; The reactor is already loaded
)
(if (not Dimended_Reactor )
(setq Dimended_Reactor (vlr-command-reactor nil '((:vlr-commandended . My_Dimend_Command ))) )
( ) ;; The reactor is already loaded
)
(if (not Dimcancelled_Reactor )
(setq Dimcancelled_Reactor (vlr-command-reactor nil '((:vlr-commandcancelled . My_Dimcancel_Command ))) )
( ) ;; The reactor is already loaded
)
;;; Function used as Callbacks when the event fires / reactor triggers
(defun My_Dimstart_Command (In_ReactorName In_Command / LayObj)
;(alert (car In_Command )) ;; <-- Remove this line, it shows all incomming command
;; Check if incomming command is qleader
(if
(or
(= (car In_Command) "QLEADER")
(= (car In_Command) "DIMALIGNED")
(= (car In_Command) "DIMLINEAR")
(= (car In_Command) "DIMCONTINUE")
(= (car In_Command) "DIMANGULAR")
)
(if (tblsearch "LAYER" "As-Recorded Dim")
(progn
(setq DimReactorlayer (getvar "clayer"))
(setvar "clayer" "As-Recorded Dim")
) ;end progn
(if (tblsearch "LAYER" "Dim")
(progn
(setq DimReactorlayer (getvar "clayer"))
(setvar "clayer" "Dim")
) ;end progn
(progn
(setq DimReactorlayer (getvar "clayer"))
(setq LayObj (vla-Add (vla-get-Layers acadDocument) "Dim"))
(vla-put-color LayObj 3)
(setvar "clayer" "Dim")
) ;end progn
) ;end if
) ;end if
()
;; The last command was not qleader
) ;end if
(princ)
) ;end defun
(defun My_Dimend_Command (In_ReactorName In_Command / )
;(alert (car In_Command )) ;; <-- Remove this line, it shows all incomming command
;; Check if incomming command is qleader
(if
(or
(= (car In_Command ) "QLEADER" )
(= (car In_Command ) "DIMALIGNED" )
(= (car In_Command ) "DIMLINEAR" )
(= (car In_Command ) "DIMCONTINUE" )
(= (car In_Command ) "DIMANGULAR" )
)
(PROGN
(setvar "clayer" DimReactorlayer)
(setq DimReactorlayer nil)
);END PROGN
( ) ;; The last command was not a dimension command
);end if
(princ)
);end defun
(defun My_Dimcancel_Command (In_ReactorName In_Command / )
;(alert (car In_Command )) ;; <-- Remove this line, it shows all incomming command
;; Check if incomming command is qleader
(if
(or
(= (car In_Command ) "QLEADER" )
(= (car In_Command ) "DIMALIGNED" )
(= (car In_Command ) "DIMLINEAR" )
(= (car In_Command ) "DIMCONTINUE" )
(= (car In_Command ) "DIMANGULAR" )
)
(PROGN
(setvar "clayer" DimReactorlayer)
(setq DimReactorlayer nil)
);END PROGN
( ) ;; The last command was not a dimension command
);end if
(princ)
);end defun
It is a little long, but It was the best way I could think of to use a reactor and of course there are more dimension commands, these are just the ones we use.
Mike_R
2007-06-25, 03:41 PM
This is a simplified version of the one we use. (Ours actually checks for quite a few more things than just the layer it's on.)
Code Removed.
Now the strange thing about this is, on my system this causes an access violation in ACAD... Have no idea why since I can't see any reason why it should. If it causes this to anyone else I'll pull it out, but I think it's because of all the other stuff I have running...
Mike_R
2007-06-25, 04:39 PM
Nevermind the last post... Figured out the problem. Got it stuck in an infinite loop...
Anyway, working code...
(if (not NewDimReactor) (setq NewDimReactor (vlr-acdb-reactor "NewDimReactor" '((:vlr-objectAppended . My_Dim_Reactor)))))
(defun My_Dim_Reactor (Reactor_Name New_Object / e1)
(setq e1 (entget (cadr New_Object)))
(if (wcmatch (cdr (assoc 0 e1)) "*DIMENSION")
(progn
(if (/= (cdr (assoc 8 e1)) "DIM")
(entmod (subst '(8 . "DIM") (assoc 8 e1) e1))
)
)
)
)
Just change "DIM" to whatever your dimension layer is and she'll work beautifully. To add other object types, such as qleaders, just change (if (wcmatch (cdr (assoc 0 e1)) "*DIMENSION") to (if (or (wcmatch (cdr (assoc 0 e1)) "*DIMENSION") (= (cdr (assoc 0 e1)) "LEADER")) or whatever your object type is and it will set that to your dimension layer as well.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.