Jump to content
ILoveMadoka

Move objects to new layer(s) based upon color??

Recommended Posts

ILoveMadoka

First of all, I'm not asking anyone to write this for me...

I'm asking if they can point me to an existing routine if it indeed exists..

 

I have a legacy drawing where everything is on Layer 0 and all the entities have colors assigned to them.

 

I am looking for an existing routine <Hopefully!> that will take all the red objects and move them to a new layer called 1 for color 1.

Same thing for each color used in the drawing. 

When done, nothing would be on Layer 0.

 

I've looked and in my searching I've had no luck.

 

= =

 

I did find this:

http://forums.augi.com/showthread.php?110777-Select-by-colour-and-move-to-layer

 

I login to the site, my name appears but when I go to this page, it does not show me logged in (so I cannot look at the code)

I pick Login, it takes me to the main page (and shows me logged in)

I cannot click the link.. 😕

 

Share this post


Link to post
Share on other sites
dlanorh
(vl-load-com)

(defun c:lbc (/ c_doc ent obj o_col ss ) 
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))) 
  (while (setq ent (entsel "\nSelect Object of Color to hide : "))
    (setq obj (vlax-ename->vla-object (car ent)) 
          o_col (vlax-get-property obj 'color)
          ss (ssget "_X" (list '(8 . "0") (cons 62 o_col)))
    );end_setq      
    (vlax-for c_obj (vla-get-activeselectionset c_doc)
      (cond ( (vlax-property-available-p c_obj 'layer T)
        	  (vlax-put-property c_obj 'layer "1");<<==THIS ASSUMES THAT LAYER 1 ALREADY EXISTS IN THE DRAWING
              (vlax-put-property c_obj 'color 256);<<==THIS CHANGES THE COLOR OF THE OBJECT TO BYLAYER
            )
      );end_cond
    );end_for
	);end_while
  (setq ss nil)
);end_defun

Try this. It assumes layer "1" already exists and changes the color of the objects, once moved to bylayer which will reflect the layers color.

If you want the layer created let me know. Its a few lines of code

Edited by dlanorh
corrected code

Share this post


Link to post
Share on other sites
gilsoto13

DotSoft has this one.


 

Quote

 

(defun c:cco ()
  (setq cmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "UNDO" "G")
  ;
  (setq sset (ssget))
  (if (/= sset nil)
    (progn
      (setq num (sslength sset) itm 0)
      (while (< itm num)
        (setq hnd (ssname sset itm))
        (setq ent (entget hnd))
        (setq col (cdr (assoc 62 ent)))
        (if (/= col nil)
          (if (and (> col 0)(< col 256))
            (progn
              (setq lay (strcat "M3-" (itoa col)))
              (if (= (tblsearch "LAYER" lay) nil)
                (command "_LAYER" "_N" lay "_C" col lay "")
              )
              (command "_CHPROP" hnd "" "_LA" lay "_C" "BYLAYER" "")
            )
          )
        )
        (setq itm (1+ itm))
      )
      (princ ", Done.")
    )
  )
  ;
  (setq sset nil)
  (command "UNDO" "E")
  (setvar "CMDECHO" cmdecho)
  (princ)
)


 

 

Share this post


Link to post
Share on other sites
dlanorh

Or you could use this, which selects all entities on layer "0" and moves them to a layer named for the integer color value. It will ignore objects with color bylayer or byblock. It creates the layers as it goes.

 

(vl-load-com)

(defun c:lbc (/ c_doc c_lyrs o_col ss n_lyr) 
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_lyrs (vla-get-layers c_doc)
        ss (ssget "_X" '((8 . "0")))
  );end_for
  (vlax-for c_obj (vla-get-activeselectionset c_doc)
    (setq o_col (vlax-get-property c_obj 'color))
    (cond ( (and (/= o_col 0) (/= o_col 256)) 
            (cond ( (not (tblobjname "layer" (itoa o_col))) 
                    (setq n_lyr (vla-add c_lyrs (itoa o_col))) 
                    (vlax-put-property n_lyr 'color o_col)
                  )
            );end_cond layer does not exist
            (vlax-put-property c_obj 'layer (itoa o_col))
            (vlax-put-property c_obj 'color 256)
          )  
    );end_cond object colour not bylayer or byblock            
  );end_for
  (setq ss nil)
);end_defun

 

Edited by dlanorh

Share this post


Link to post
Share on other sites
ILoveMadoka
19 hours ago, gilsoto13 said:

DotSoft has this one.


 

 

c:CCO - This one works perfectly.

 

Thank you so very much!!

Edited by ILoveMadoka

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×