Creating either a Lisp or a script to change the pen weights of two layer in autocad 2011?
Solved! Go to Solution.
Hi
What are the pen weight values and what are the names of your layers ?
Try this ..
(defun c:Test (/ ss i sn e) (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25)) (if (tblsearch "LAYER" (car layer)) (entmod (subst (cons 370 (cadr layer)) (assoc 370 (setq e (entget (tblobjname "LAYER" (car layer)))) ) e ) ) (princ (strcat "Layer not found < " (car layer) " > ...")) ) ) (princ) )
@Anonymous wrote:
The layers are TL_TEXT pen .20 & TL_DIM pen .25. The existing pen weight is .09. Thanks
I think it can be as simple as -- in Lisp terms:
(command "_.layer" "_lw" 0.2 "TL_TEXT" "_lw" 0.25 "TL_DIM" "")
or in Macro terms:
^C^C_.layer _lw 0.2 TL_TEXT _lw 0.25 TL_DIM ;
or in Script terms:
_.layer _lw 0.2 TL_TEXT _lw 0.25 TL_DIM
followed by a blank line.
@Kent1Cooper wrote:I think it can be as simple as -- in Lisp terms:
Is not it good idea to check if the layer name is existed first in the drawing and after that implement the actions
that is needed ?
@_Tharwat wrote:....Is not it good idea to check if the layer name is existed first in the drawing and after that implement the actions that is needed ?
It doesn't hurt, but it's not necessary. This is another situation in which the (command) function simplifies things considerably. You may not be able to assign a lineweight to a non-existent Layer using (subst)/(entmod), but doing this with a Layer command, if either Layer doesn't exist, it will simply send a message: "No matching Layer names found." Then it will just go back to the Layer prompt and continue, without error. Whichever of those two Layers exists will have its lineweight assigned, and if either or both don't exist, it simply won't have found anything to assign the particular lineweight to.
@_Tharwat wrote:Try this ..
(defun c:Test (/ ss i sn e) (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25)) (if (tblsearch "LAYER" (car layer)) (entmod (subst (cons 370 (cadr layer)) (assoc 370 (setq e (entget (tblobjname "LAYER" (car layer)))) ) e ) ) (princ (strcat "Layer not found < " (car layer) " > ...")) ) ) (princ) )
Perhaps this instead?
(defun c:FOO (/ layerName eName eData) (foreach layerItem '(("TL_TEXT" 20) ("TL_DIM" 25)) (if (setq eName (tblobjname "layer" (setq layerName (car layerItem)))) (entmod (subst (cons 370 (cadr layerItem)) (assoc 370 (setq eData (entget eName))) eData ) ) (princ (strcat "Layer not found < " layerName " > ...")) ) ) (princ) )
"How we think determines what we do, and what we do determines what we get."
@BlackBoxCAD wrote:Perhaps this instead?
Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong .
@_Tharwat wrote:
@BlackBoxCAD wrote:Perhaps this instead?
Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong .
Tharwat, my friend -
While the word 'perhaps' should have been sufficient, you may substitute with whatever word you like.
Just for clarification though... Did you, earlier today in another thread, inform someone that they obtained the ActiveDocument Object twice?
That code wasn't "wrong" either, but was somewhat redundant, and so you felt compelled to point that out, right?
I've done the same thing here, as you redundantly check for a Layer Table Record via TblSearch, and then obtain the Entity Name for same via TblObjName when all I did was use the latter as my 'check' given that if no record (symbol) is found, Nil is returned:
_$ (tblobjname "layer" "foo") nil _$
For the record, not once, have I called others' offering(s) "wrong," unless blatently missing the point (i.e., posted the wrong code in the wrong thread by mistake, etc.)... I'd like to believe that you know me well enough by now, that you understand no offense was intended here, only encouragement to refine our methods.
Cheers
"How we think determines what we do, and what we do determines what we get."
@BlackBoxCAD wrote:
@_Tharwat wrote:
@BlackBoxCAD wrote:Perhaps this instead?
Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong .
Tharwat, my friend -
While the word 'perhaps' should have been sufficient, you may substitute with whatever word you like.
Just for clarification though... Did you, earlier today in another thread, inform someone that they obtained the ActiveDocument Object twice?
That code wasn't "wrong" either, but was somewhat redundant, and so you felt compelled to point that out, right?
I've done the same thing here, as you redundantly check for a Layer Table Record via TblSearch, and then obtain the Entity Name for same via TblObjName when all I did was use the latter as my 'check' given that if no record (symbol) is found, Nil is returned:
_$ (tblobjname "layer" "foo") nil _$
For the record, not once, have I called others' offering(s) "wrong," unless blatently missing the point (i.e., posted the wrong code in the wrong thread by mistake, etc.)... I'd like to believe that you know me well enough by now, that you understand no offense was intended here, only encouragement to refine our methods.
Cheers
Completely right .
I have to admit that I did not pay my attention to the function TblObjName that it could behave the same as TblSearch function .
Thank you for the nice reply .
"How we think determines what we do, and what we do determines what we get."
@BlackBoxCAD wrote:
@_Tharwat wrote:Try this ..
(defun c:Test (/ ss i sn e) (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25)) (if (tblsearch "LAYER" (car layer)) (entmod (subst (cons 370 (cadr layer)) (assoc 370 (setq e (entget (tblobjname "LAYER" (car layer)))) ) e ) ) (princ (strcat "Layer not found < " (car layer) " > ...")) ) ) (princ) )
Perhaps this instead?
(defun c:FOO (/ layerName eName eData) (foreach layerItem '(("TL_TEXT" 20) ("TL_DIM" 25)) (if (setq eName (tblobjname "layer" (setq layerName (car layerItem)))) (entmod (subst (cons 370 (cadr layerItem)) (assoc 370 (setq eData (entget eName))) eData ) ) (princ (strcat "Layer not found < " layerName " > ...")) ) ) (princ) )
Not to say this is not a good way to do it, because it is.
For an alternate approach, I choose to create a layer with the settings that I prefer and then use merge layer. Although, I have customized the Layer manager for isolating groups of layer for display within model space. All of my pages are set up with viewports to reflect managed layer groups.