Jump to content

colour in layer 0


Hsanon

Recommended Posts

hi, can someone let me know of a routine which moves selected objects (on separate layers) into another layer (say layer 0 ) but the objects need to keep the same colours of the original layers (byblock)

 

I am trying to reduce the number of layers in a drawing by pushing them all into a separate layer, but they all become bylayer taking on the new layer colour and i cannot distinguish the various elements ...

 

thanks

Link to comment
Share on other sites

Try this routine and change the variable 'lay' according to your target layer name .

 

(defun c:Test  (/ lay i ss sn)
;;; Tharwat 09.03.2015    ;;;
 (setq lay [color=red]"0"[/color]) [color=red];; <<= change the layer name as per your required one [/color]
 (if
   (and (tblsearch "LAYER" lay)
        (princ
          (strcat "\n Select objects to move to layer < " lay " > ."))
        (setq i  -1
              ss (ssget "_:L" '((0 . "~VIEWPORT"))))
        )
    (while (setq sn (ssname ss (setq i (1+ i))))
      (entmod
        (subst (cons 8 lay) (assoc 8 (setq e (entget sn))) e))
      )
    (princ
      "\n Failed !. Layer not found or nothing selected by the user ")
    )
 (princ)
 )

Link to comment
Share on other sites

thanks for your help Tharwat....

the entities can move to layer 0, but the entity colours become the colour of the layer 0 (bylayer)

 

i was looking at the entities to come into layer 0, with different colours - (which were the colours as seen in the original layers)

i.e. if the entities were red bylayer in layer 1, and green bylayer in layer 2,

when they come into layer 0, they still come in as red and green....

 

it keeps the drawing looking interesting

thanks.

Link to comment
Share on other sites

guwahati survey for dwg insert.dwg

 

i am attaching a messy drawing with a bunch of layers ... all with its own bylayer colour objects.

I would like the objects in these various layers be moved to layer 0, but to maintain the same old colours (byblock) which they had in their previous layers. and remove the older various layers.

 

it will make the drawing look more interesting than all objects having one flat single colour of layer 0

 

thanks

(have tried to insert a drawing ... hope its been attached)

Link to comment
Share on other sites

i.e. the red coloured objects remain red in layer 0, the green/blue /yellow etc objects come in as green/blue/yellow objects in layer 0 etc.....

Link to comment
Share on other sites

If I've understood correctly, please try the following:

(defun c:movetolayer ( / des enx idx lay lst sel )

   (setq des "0") ;; Destination Layer (created if not present)
   
   (if (setq sel (ssget "_:L"))
       (repeat (setq idx (sslength sel))
           (setq enx (entget (ssname sel (setq idx (1- idx))))
                 lay (assoc 8 enx)
                 enx (subst (cons 8 des) lay enx)
           )
           (if (not (assoc 62 enx))
               (setq enx
                   (append enx
                       (list
                           (cond
                               (   (cdr (assoc lay lst)))
                               (   (cdar
                                       (setq lst
                                           (cons
                                               (cons lay
                                                   (cons 62
                                                       (abs
                                                           (cdr
                                                               (assoc 62
                                                                   (tblsearch "layer"
                                                                       (cdr lay)
                                                                   )
                                                               )
                                                           )
                                                       )
                                                   )
                                               )
                                               lst
                                           )
                                       )
                                   )
                               )
                           )
                       )
                   )
               )
           )
           (entmod enx)
       )
   )
   (princ)
)

Link to comment
Share on other sites

I think you want to move objects to a specific layer and re-color each object according to its original color in its original layer .

Your first post does not give any hint about this goal . but anyway Lee step over and gave you the one before I read your attached drawing .

Link to comment
Share on other sites

Sorry for not being too clear in my post... yes this was exactly what i needed... and Lee's program works !!!! :D

 

thanks so much for your help.... !!!!

Link to comment
Share on other sites

Lee, fyi, the name is Harsh Sanon.... (not the "english" harsh)

i am a 50 year old architect .... i started autocad and dabbled in autolisp when i was younger, half my age,, and made a bunch of drafting programs which i still use personally. however, ive lost my knack of writing now.....

am still hands on, on my autocad work. your help (and that of everyone on the website) is really appreciated.

Thanks !!!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...