Hi, anyone know how to write a lisp that when i activate it, it will change all the objects in the drawings to be change to "Layer 0" and all linetypes "Dashed" change to be "hidden"...
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Check this out ....
(defun c:Test (/ ss i sn) ;;; Tharwat 10. March. 2012 ;;; (vl-load-com) (if (not (tblsearch "LTYPE" "HIDDEN")) (vla-load (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object) ) ) "HIDDEN" "acadiso.lin" ) (princ) ) (defun LTYPE2Hidden (sn) (entupd (cdr (assoc -1 (entmod (subst (cons 6 "HIDDEN") (assoc 6 (entget sn)) (entget sn)) ) ) ) ) ) (defun ChangeLayers (sn) (entupd (cdr (assoc -1 (entmod (subst (cons 8 "0") (assoc 8 (entget sn)) (entget sn)) ) ) ) ) ) (if (setq ss (ssget "_x")) (repeat (setq i (sslength ss)) (setq sn (ssname ss (setq i (1- i)))) (if (eq (cdr (assoc 6 (entget sn))) "DASHED") (LTYPE2Hidden sn) ) (ChangeLayers sn) ) (princ) ) (princ) )
@Anonymous wrote:Hi, anyone know how to write a lisp that when i activate it, it will change all the objects in the drawings to be change to "Layer 0" and all linetypes "Dashed" change to be "hidden"...
Minimally tested, but I think you can do it as simply as this:
(defun C:Whatever (/ ss)
(if
(setq ss (ssget "_X" '((6 . "DASHED"))))
(command "_.chprop" ss "" "_ltype" "HIDDEN" "")
); if
(command "_.chprop" "_all" "" "_layer" "0" "")
); defun
[It's not necessary to ensure that the Hidden linetype is loaded -- CHPROP will find it.]
That won't find parts within Block definitions, and will only find things with an override Dashed linetype, not things that are Bylayer and only of Dashed linetype because that's the linetype of their Layer. But at quick glance, it appears the same limitations are true of TharwaT313's suggestion.
I think you'll find similar threads in the Discussion Group with a Search, and probably something that can dig into Block definitions, change the Dashed linetype of a Layer to Hidden, etc. The former is mildly complicated, but the latter is pretty easy, if you need to do that.
Dear Kent,
I just now try to modify the lisp abit, but then i not sure where is my error..Somehow i can't make all my hidden lines to be in "magenta"..Please advise where is my mistake.
Here is what i wish to have:
1) Make all objects to be in "LAYER 0" + color "BYLAYER)
2) Make all objects lineweight to be "BYLAYER"
3) Make all "DASHED" to be "HIDDEN" + "MAGENTA" color
@Anonymous wrote:Dear Kent,
Here is what i wish to have:
1) Make all objects to be in "LAYER 0" + color "BYLAYER)
2) Make all objects lineweight to be "BYLAYER"
3) Make all "DASHED" to be "HIDDEN" + "MAGENTA" color
Judging by the sequence you are proposing, i would assume "DASHED" and "MAGENTA" are Layer properties.
Is that correct?
@Anonymous wrote:Dear @pbejse
Yes, i need to change all objects in "DASHED lintype" to be change to "HIDDEN linetype" and with color properties of "MAGENTA".
Did not my code work for you ? or did you even see it ?
@Anonymous wrote:Dear pbejse
Yes, i need to change all objects in "DASHED lintype" to be change to "HIDDEN linetype" and with color properties of "MAGENTA".
Still not clear lai,
Layers with "DASHED" will be change to HIDDEN" and color to "MAGENTA"
I'm talking about layer properties here and not object properties.
as you posted before:
1) Make all objects to be in "LAYER 0" + color "BYLAYER)
2) Make all objects lineweight to be "BYLAYER"
I would think, there wont be any property overrides left on the drawing and ALL entity properties will be BYLAYER
Are we on the same page lai?
Dear Tharwat,
Yes, i have try it before, but after a few time trys, somehow i didn't see the original "dashed" line been change to "Hidden" line..After i load the LISP, i type "TEST", then all the object properties seems no any changes..Please advise if in case i have done wrongly anythings. Thanks.
Dear All,
Sorry if i have give any misunderstand...i have attach a sample drawing with end result that i need for a better understanding.
@Anonymous wrote:Dear All,
Sorry if i have give any misunderstand...i have attach a sample drawing with end result that i need for a better understanding.
The key here would be finding all Entities with an overriden linetype property of"DASHED" and change those to "HIDDEN"/"MAGENTA"
both codes by tharwat and kent would work then. but with this statement
1) Make all objects to be in "LAYER 0" + color "BYLAYER) doenst jibe with the result you want as those "DASHED" lines would have a color property of "BYLAYER", so you understand my confusion.
so it can be as simple as this one
(defun C:Whatever (/ ss)
(if
(setq ss (ssget "_X" '((6 . "DASHED"))))
(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")
)
)
as you had it on your test.lsp
Hi pbejse,
This is my final LISP...all goes good, except that somehow my hidden lines wont change to be color "6"...Where is my mistake?
(defun C:Whatever (/ ss)
(if
(setq ss (ssget "_X" '((6 . "DASHED"))))
(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")
); if (command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")
); defun
@Anonymous wrote:Hi pbejse,
This is my final LISP...all goes good, except that somehow my hidden lines wont change to be color "6"...Where is my mistake?
(defun C:Whatever (/ ss)
(if
(setq ss (ssget "_X" '((6 . "DASHED"))))
(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")
); if (command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")
); defun
Why you asked? because right after you change the objects on selection set ss you changed "ALL" colors to bylayer. so you see the predicament there lai.
but it can be done done of course 🙂
EDIT: but with the issues Kent pointed out earlier. this method wont work for entities inside a block nor objects NOT within the active viewport.
try this for now
(defun C:Whatever (/ ss ss2) (if (setq ss (ssget "_X" (list '(6 . "DASHED")(cons 410 (getvar 'Ctab))))) (progn (command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "") (setq ss2 (ssget "_X" (list (cons 410 (getvar 'Ctab))))) (repeat (setq i (sslength ss)) (ssdel (ssname ss (setq i (1- i))) ss2)) (command "_.chprop" ss2 "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "") ) ) )
HTH
@Anonymous wrote:.... Somehow i can't make all my hidden lines to be in "magenta"..Please advise where is my mistake.
....
I think you are only missing the closing right parenthesis for the second (if) function:
(command "_.chprop" ss "" "_color" "magenta" "")
); if
); defun
Dear Kent,
Thanks for your advise...Anyway, to give a better understanding for everyone, i have attach along the lisp which work without problem.
Hi all, after sometime of using this lisp, i have tot of want to modify it abit...i wish to when i activate the lisp, it will ask me " Do you want to make changes? (Y/N)" and then i have option to choose yes or no..
Reason is because without this quote i have been a few time accidentally go change all my layer base on the lisp criteria and i find it quite dangerous without being inform me..Thanks.
@Anonymous wrote:....i wish to when i activate the lisp, it will ask me " Do you want to make changes? (Y/N)" and then i have option to choose yes or no..
....
Here is one way to do that [untested]:
(defun C:changer (/ ss)
(initget "Yes No")
(if
(=
(getkword "\nDo you want to make changes? [Y/N] <N>: ")
"Yes"
); =
(progn
(if
(setq ss (ssget "_X" '((6 . "DASHED"))))
(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "")
); if
(command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")
(if
(setq ss (ssget "_X" '((6 . "HIDDEN"))))
(command "_.chprop" ss "" "_color" "magenta" "_Scale" "0.6" "")
);if
); progn
); if
); defun
Thanks Kent,
It works fine for me at the moment..Will test it out a few more times...
I would like to change the linetype in the "E-Switching" layer from "Hidden" to "Continuous" by executing a lisp program. can anyone assist how to resolve the above.
Thank you
lingam