• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

change color properties to all entities

  • Thread starter Thread starter gianluigiloffreda
  • Start date Start date

gianluigiloffreda

Guest
Hello everyone,

Sorry, I'm new to this forum and I was hoping someone could help me.
I wanted to know if you can write in lisp a program that could do the following simple operations:

1. I open a generic file with hundreds of layers of different color, entities with bylayer color and not.

2. I launch the program and automatically get the same file output with all entities both simple and blocks that nested blocks and any type of entity, having as color property the color bylayer.

Thank you in advance

 
you can create a script that performs this procedure for all dwg (if there are many):

- open the dwg
- caprop -> all - colour -> dalayer
- impdalay command -> all
- save
- Get out.

of course completing with the right syntax in response to the requests of the individual commands.



If you have to do it on a single dwg, it's just two commands.... .
 
Unfortunately I am new to the lisp language and reading "my lisp" for now I managed to write the following but "obviously" does not work (synthesis error)

and above all I wonder how to apply the color bylayer even to suits the internal entities to blocks or nested blocks.
Thank you very much




(defun c:colorbylayer
(setq group (ssget "x"))

(command "_change" group "_pr" "_c" "_bylayer"")

)

(prompt "enloaded colorbylayer command ")
 
Of course I read it. .

and I created this

(defun c:colorbylayer ()

(command "caprop" "t" "c" "" "dalayer"")

(prompt "enloaded command colorbylayer2")


but with even fewer results (erroneous list in input)
I'm still trying, but being in the beginning... it's not easy:)
 
proof così:
HTML:
(defun c:colorbylayer (/ gruppo)
    (setq gruppo (ssget "x"))
    (command "_change" gruppo "" "_pr" "_c" "_bylayer" "")
    (command "_setbylayer" "_all" "" "_y" "_y")
)
(prompt "\ncaricato comando colorbylayer ")
(princ)
 
Great... it works! !
and is "almost" complete. .
leaves me out only the odds that unfortunately remain of their settings.
I assume that there is some other command that goes to intervene also on the settings of the right quota styles?
 
so it should work with everything.
HTML:
(defun c:cbl (/ e_dim cont nb name_dim col_ent tdef en ed)
(command "_setbylayer" "_all" "_y" "_y")
(setq e_dim (ssget "_x"((0 . "dimension"))))))
(setq cont 0)
(repeat (sslength e_dim)
(setq nb (cdr (assoc 2 (entget (ssname e_dim cont)))))))
(setq name_dim (cdr (car)))))
(setq col_ent nil)
(setq tdef (tblsearch "block" nb))
(setq in (cdr (assoc -2 tdef)))
(while in
(setq ed (get in))
(if (setq col_ent (assoc 62 ed))
(progn)
(setq ed (subst 62 256) (assoc 62 ed))
(entmod ed)
)
)
(setq in (entnext in))
(setq col_ent nil)
)
(setq cont (1+ cont))
(entupd name_dim)
)
)
(prompt "\ncaricato comando cbl (colorbylayer) ")
(princ)
 
thank you very much g.p.,
now more calmly I will try to create others.
in any case I thank you for the support, it works perfectly.
 
..... now more calmly I will try to create others.
in any case thank you for the support, works perfectly.
It is not true, we forgot to set the _setbylayer command settings, with default values are set on dalayer also line, thickness and material of all objects.

because that doesn't happen see the options of the setbylayermode variable, I think 97 can go well, I put the change in the first line.

HTML:
(defun c:cbl (/ e_dim cont nb name_dim col_ent tdef en ed)
    (setvar "setbylayermode" 97)
    (command "_setbylayer" "_all" "" "_y" "_y")
    (setq e_dim (ssget "_x" '((0 . "dimension"))))
    (setq cont 0)
    (repeat (sslength e_dim)
	(setq nb (cdr (assoc 2 (entget (ssname e_dim cont)))))
	(setq name_dim (cdr (car (entget (ssname e_dim cont)))))
	(setq col_ent nil)
        (setq tdef (tblsearch "block" nb))
        (setq en (cdr (assoc -2 tdef))) 
        (while en
	    (setq ed (entget en))
	    (if (setq col_ent (assoc 62 ed))
	        (progn
	    	    (setq ed (subst (cons 62 256) (assoc 62 ed) ed))
		    (entmod ed)
	        )
	    )    
	    (setq en (entnext en))
	    (setq col_ent nil)
        )
	(setq cont (1+ cont))
	(entupd name_dim)
    )
)
(prompt "\ncaricato comando cbl (colorbylayer) ")
(princ)
 
hi g.p.,

Yes, I checked the properties of the setbylayermode command and (again) you got arson.
97 is fine, even if I admit I don't know the plot style property well.
Anyway, thank you again.
 
hi g.p.,
I tried the lisp command in several cases, now it keeps line type, thickness etc. but in some cases it returns me an error:

Iselsetp

I read around and it would seem that there is a command that expects a selection and instead the selection is nothing, only that I can't understand what it can be.
Actually the command seems to do what it should but read "error" from a little nuisance.
Do you have any idea what that could be?
 
the lisp reports that it did not find elements, in your case because you operated on a dwg without quotas, but still carries out his work.
Now "would" be fine.
HTML:
(defun c:cbl (/ e_dim cont nb name_dim col_ent tdef en ed)
(setbylayermode 97)
(command "_setbylayer" "_all" "_y" "_y")
(setq e_dim (ssget "_x"((0 . "dimension"))))))
(if e_dim
(progn)
(setq cont 0)
(repeat (sslength e_dim)
(setq nb (cdr (assoc 2 (entget (ssname e_dim cont)))))))
(setq name_dim (cdr (car)))))
(setq col_ent nil)
(setq tdef (tblsearch "block" nb))
(setq in (cdr (assoc -2 tdef)))
(while in
(setq ed (get in))
(if (setq col_ent (assoc 62 ed))
(progn)
(setq ed (subst 62 256) (assoc 62 ed))
(entmod ed)
)
)
(setq in (entnext in))
(setq col_ent nil)
)
(setq cont (1+ cont))
(entupd name_dim)
)
)
)
)
(prompt "\ncaricato comando cbl (colorbylayer) ")
(princ)
 
Hi, gp.
I wanted to ask if the lisp of this post can do even in my case. in case positive (I hope) I would like to know what to change.
My problem is essentially this:
I have a map with loads of blocks that I would like to bring to color 186,186,186.
now I'm doing it manually, and I'm like,
the block is on the layer that interests me (for example roads) with color 186,186,186, I open the editor of the blocks and the layer of the content is 0. I select the content and attribute the color 186,186,186. I close the editor and the result is what I was interested in.
I hope I made myself understand.
I tried the lisp as it is by selecting a block on the layer to which I changed the color. gives me this error: setting of the autocad variable rejected: "setbylayermode" 97
Thank you.
 
setbylayermode is usable with versions > 2007, but this lisp does not do what you ask. :smile:
 
Hi, gp.
thanks to the answer: Then that's the reason for the mistake. I have the 2007 version because I am under w2k.
I managed to solve by manually assigning the desired color to the layers so that even the objects belonging to those layers changed automatically.
thanks anyway to the stimulus to seek a new solution.
greetings
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top