Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set color to Layer & freeze

8 REPLIES 8
Reply
Message 1 of 9
jstarr-kimastle
510 Views, 8 Replies

Set color to Layer & freeze

I'm trying to write a lisp routine where I can click on an item (all I get are ASSURFACE to work with) and it pulls the color off that item. Then it needs to select all entities with that color to a certain layer (I've been using DATA_01, DATA_02, etc.). Then I want to freeze that layer.

The problem I'm having is the select by color and set that group to a layer.

If you can help me I'd appreciate it. I'm using MDT 2007.

Here's what I have so far:
(DEFUN C:S1 ()
(COMMAND "UNDO" "M")
(PRINC "\nSELECT THE COLOR YOU WANT TO PUT ON LAYER DATA_01... ")
(SETQ GROUP (SSGET)); <-- I think I need help here
(COMMAND "CHPROP" GROUP "" "LA" "DATA_01" "")
(COMMAND "-LAYER" "F" "DATA_01" "")
(PRINC "\nTHESE ITEMS HAVE BEEN PUT ON LAYER DATA_01.")
(PRINC)
)

Thanks again,

Jason
8 REPLIES 8
Message 2 of 9

You are wanting everything in the drawing that is the same color as the selected entity to be moved to layer "Data_01"?

What if the selected entity is color "ByLayer", would you get that layer color?
Message 3 of 9

Reply From: A_LOTA_NOTA:
You are wanting everything in the drawing that is the same color as the selected entity to be moved to layer "Data_01"?

Me:
The drawings I'm dealing with have the same color on multiple layers (don't ask me why) so yes everything in the drawing that is the same color to be moved to layer "DATA_01".

If the selected entity is color "ByLayer" and the Lisp didn't work, then I would probably leave that until the very last one.

Thanks for any help you can give. I really appreciate it. I'm going crazy with this one.

Jason
Message 4 of 9
shawndoe
in reply to: jstarr-kimastle

Hi,

It's late and I'm tierd, so you get a statement for a selection set, but no real explianation. I'll check in tomorrow, if you need more.

(Setq ss (ssget "x" (list (assoc 62 (entget (ssname (setq ss1 (ssget)) 0))))))

Night
Shawndoe
Message 5 of 9

This should get you started. This gets the color of the entity you select. Post what you add & somone here will help!

(defun c:S1 (/ Source Entz CLR)
(while (not Source); checks to make sure something was selected
(setq Source (entsel "\nSELECT THE COLOR YOU WANT TO PUT ON LAYER DATA_01... ")); pick entity
(setq Entz (car Source)); entity name
(if (not (setq CLR (cdr (assoc 62 (entget Entz))))); entity color
(setq CLR (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget Entz))))))); layer color
); end if
); end while
); end defun
Message 6 of 9

Try this...

(defun c:S1 (/ Source Entz CLR Ent SS1 Lngth Count Ent EntList)
(while (not Source); checks to make sure something was selected
(setq Source (entsel "\nSELECT THE COLOR YOU WANT TO PUT ON LAYER DATA_01... ")); pick entity
(setq Entz (car Source)); entity name
(if (not (setq CLR (cdr (assoc 62 (entget Entz))))); entity color
(setq CLR (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget Entz))))))); layer color
); end if
); end while
(setq SS1 (ssget "X")); get all entitys
(setq Lngth (sslength SS1)); list length
(setq Count 0)
(while (< Count Lngth)
(setq Ent (ssname SS1 Count)); get next item from selection set
(if (not (or (eq 9 (cdr (assoc 62 (entget Ent))))
(eq 9 (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget Ent)))))))
); end or
); end not
(progn
(ssdel Ent SS1); remove from selection set
); progn
(progn
(setq EnList (entget Ent)); group codes
(setq EnList (subst (cons 8 "DATA_01") (assoc 8 EnList) EnList)); replaces the old with the new
(entmod EnList); Changes the old
(entupd Ent); Regenerates the entity
); end prog
); end if
(setq Count (1+ Count)); add to count
); end while
); end defun
Message 7 of 9

Thanks, it works perfectly now. I really appreciate all the help everyone gave me. Thank you, thank you.

J
Message 8 of 9

Hi,

I tried what you gave me and it didn't work for this lisp. It kept giving me the error
error: bad argument
type: lentityp nil
Some of your code did work in another lisp I was trying to create. Thanks again for all your help.

J
Message 9 of 9

Sorry, had an error but its fixed now

This wont change the color of a line that is not set to bylayer. But that can be changed if thats the way you want it!

(defun c:S1 (/ Source Entz CLR Ent SS1 Lngth Count Ent EntList)
(while (not Source); checks to make sure something was selected
(setq Source (entsel "\nSELECT THE COLOR YOU WANT TO PUT ON LAYER DATA_01... ")); pick entity
(setq Entz (car Source)); entity name
(if (not (setq CLR (cdr (assoc 62 (entget Entz))))); entity color
(setq CLR (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget Entz))))))); layer color
); end if
); end while
(setq SS1 (ssget "X")); get all entitys
(setq Lngth (sslength SS1)); list length
(setq Count 0)
(while (< Count Lngth)
(setq Ent (ssname SS1 Count)); get next item from selection set
(if (not (or (eq CLR (cdr (assoc 62 (entget Ent))))
(eq CLR (cdr (assoc 62 (tblsearch "layer" (cdr (assoc 8 (entget Ent)))))))
); end or
); end not
(progn
(ssdel Ent SS1); remove from selection set
); progn
(progn
(setq EnList (entget Ent)); group codes
(setq EnList (subst (cons 8 "DATA_01") (assoc 8 EnList) EnList)); replaces the old with the new
(entmod EnList); Changes the old
(entupd Ent); Regenerates the entity
); end prog
); end if
(setq Count (1+ Count)); add to count
); end while
); end defun Message was edited by: A_LOTA_NOTA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost