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

-----------How do I move a color to a layer?

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
169 Views, 8 Replies

-----------How do I move a color to a layer?

I want to sort my file by colors.....I want each color on its corresponding
layer.
i.e.. the color green would go on the layer green
How would I do that in a lisp file?
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

This would be one way...
(defun c:color2layer ( / color2str e ent i clayer layer)
(setvar "cmdecho" 0)
(command "_.undo" "_End" "_.Undo" "_Group")
;;--------------------------------------------------
;; Function to convert an integer color to a string:
;;
(defun color2str (color#)
(cond
((not color#) nil)
((= color# 256) nil)
((= color# 0) nil)
((= color# 1) "Red")
((= color# 2) "Yellow")
((= color# 3) "Green")
((= color# 4) "Cyan")
((= color# 5) "Blue")
((= color# 6) "Magenta")
((= color# 7) "White")
(1 (itoa color#))
)
)
(setq i 1.0 ; counter
e (entnext) ; first item in drawing
)
(while e
(princ (strcat "\rProcessing # " (rtos i 2 0)))
(setq ent (entget e)
clayer (cdr (assoc 8 ent))
e (entnext e)
i (1+ i)
)
(if (and (setq layer (color2str (cdr (assoc 62 ent))))
(/= (strcase layer)(strcase clayer))
)
(progn
(if (= (logand 4 (cdr (assoc 70 (tblsearch "layer" clayer)))) 4)
(command "_.layer" "_UNlock" clayer)
)
(if (not (tblsearch "layer" layer))
(command "_.layer" "_New" layer "_Color" layer layer "")
)
(entmod (subst (cons 8 layer)(assoc 8 ent) ent))
)
)
)
(command "_.undo" "_End")
(setvar "cmdecho" 1)
(princ)
)

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Tom" wrote in message
news:4077D381FD236F446B9FB54697220AE0@in.WebX.maYIadrTaRb...
> I want to sort my file by colors.....I want each color on its
corresponding
> layer.
> i.e.. the color green would go on the layer green
> How would I do that in a lisp file?
>
>
Message 3 of 9
Anonymous
in reply to: Anonymous

"Tom" wrote in message
news:4077D381FD236F446B9FB54697220AE0@in.WebX.maYIadrTaRb...
> I want to sort my file by colors.....I want each color on its
corresponding
> layer.
> i.e.. the color green would go on the layer green
> How would I do that in a lisp file?
>
Hi Tom
I have to assume you have those layers already created in your drawing. If
not, there's more required in this routine.
Try it - it gives a report at the end to help you see what's just happened.
-doug

(defun c:col-lay ( / layer layer-name layer-color color-ents
n entity orig-layer new-layer color report)
(while (setq layer (tblnext "layer"))
(setq layer-name (cdr (assoc 2 layer)))
(setq layer-color (cdr (assoc 62 layer)))
(setq color-ents (ssget "X" (list (cons 62 layer-color))))
(if color-ents
(progn
(setq n 0)
(while
(setq entity (ssname color-ents n))
(setq entity (entget entity))
(setq orig-layer (assoc 8 entity))
(setq new-layer (cons 8 layer-name))
(setq entity (subst new-layer orig-layer entity))
(entmod entity)
(setq n (1+ n))
);end while
(setq color (itoa layer-color))
(setq report (strcat "\nEntities with color " color " placed on layer "
layer-name "."))
(princ report)
);end progn
(progn
(setq color (itoa layer-color))
(setq report (strcat "\nThere were no entities with color " color " to
place on layer " layer-name "."))
(princ report)
);end progn
);end if
);end while
(princ)
)
Message 4 of 9
Anonymous
in reply to: Anonymous

John-
Nice routine. Cleaner, faster, more complete than the one I came up with.
It doesn't cover colors past 7...I use a variety of colors all the way up to
255.
In an extended routine I was working on this morning (after seeing how well
yours worked) I was attempting to create new layers for any extant colors not
pre-created. Their names would be the color numbers.
-doug

"John Uhden" wrote in message
news:D52A00DCCC0988FF8207B9E8BA68593F@in.WebX.maYIadrTaRb...
> This would be one way...
> (defun c:color2layer ( / color2str e ent i clayer layer)
> (setvar "cmdecho" 0)
> (command "_.undo" "_End" "_.Undo" "_Group")
> ;;--------------------------------------------------
> ;; Function to convert an integer color to a string:
> ;;
> (defun color2str (color#)
> (cond
> ((not color#) nil)
> ((= color# 256) nil)
> ((= color# 0) nil)
> ((= color# 1) "Red")
> ((= color# 2) "Yellow")
> ((= color# 3) "Green")
> ((= color# 4) "Cyan")
> ((= color# 5) "Blue")
> ((= color# 6) "Magenta")
> ((= color# 7) "White")
> (1 (itoa color#))
> )
> )
> (setq i 1.0 ; counter
> e (entnext) ; first item in drawing
> )
> (while e
> (princ (strcat "\rProcessing # " (rtos i 2 0)))
> (setq ent (entget e)
> clayer (cdr (assoc 8 ent))
> e (entnext e)
> i (1+ i)
> )
> (if (and (setq layer (color2str (cdr (assoc 62 ent))))
> (/= (strcase layer)(strcase clayer))
> )
> (progn
> (if (= (logand 4 (cdr (assoc 70 (tblsearch "layer" clayer)))) 4)
> (command "_.layer" "_UNlock" clayer)
> )
> (if (not (tblsearch "layer" layer))
> (command "_.layer" "_New" layer "_Color" layer layer "")
> )
> (entmod (subst (cons 8 layer)(assoc 8 ent) ent))
> )
> )
> )
> (command "_.undo" "_End")
> (setvar "cmdecho" 1)
> (princ)
> )
>
> --
> John Uhden, Cadlantic/formerly CADvantage
> --> mailto:juhden@cadlantic.com
> --> http://www.cadlantic.com
> 2 Village Road
> Sea Girt, NJ 08750
> Tel. 732-974-1711
> FAX 732-528-1332
>
>
> "Tom" wrote in message
> news:4077D381FD236F446B9FB54697220AE0@in.WebX.maYIadrTaRb...
> > I want to sort my file by colors.....I want each color on its
> corresponding
> > layer.
> > i.e.. the color green would go on the layer green
> > How would I do that in a lisp file?
> >
> >
>
>
Message 5 of 9
Anonymous
in reply to: Anonymous

Thanks, but I forgot to change each entity's color to 256 (Bylayer). Do you
think the short form of entmod would work... (entmod (list (cons -1 e)'(62 .
256)))?

Yes it does cover colors >7. Check out the final condition in the color2str
function.

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Doug Barr" wrote in message
news:A5EAA5205DA604B574A54610497444C0@in.WebX.maYIadrTaRb...
> John-
> Nice routine. Cleaner, faster, more complete than the one I came up with.
> It doesn't cover colors past 7...I use a variety of colors all the way up
to
> 255.
> In an extended routine I was working on this morning (after seeing how
well
> yours worked) I was attempting to create new layers for any extant colors
not
> pre-created. Their names would be the color numbers.
> -doug
Message 6 of 9
Anonymous
in reply to: Anonymous

"John Uhden" wrote in message
news:1D9B57B16480FD837D68E69BD868A81B@in.WebX.maYIadrTaRb...
> Thanks, but I forgot to change each entity's color to 256 (Bylayer). Do you
> think the short form of entmod would work... (entmod (list (cons -1 e)'(62 .
> 256)))?
>
> Yes it does cover colors >7. Check out the final condition in the color2str
> function.

Indeed, it is a good routine. I'm not familiar with the entmod form you suggest.
I would likely go through the usual longhand route. I'm also unversed in the use
of logand. What is logand doing in your routine?
I value your tutelage!
-doug
Message 7 of 9
Anonymous
in reply to: Anonymous

Doug:

> ... I'm not familiar with the entmod form you suggest.
I thought for sure you had followed the lengthy discussion on "Group 60 -
visibility" that concluded less than two weeks ago. If not, go back and
look at it.

> ...What is logand doing in your routine?
It's checking to se if the entity's current layer is locked (can't entmod it
if it is). A layer's 70 code is a Boolean value. If bit 4 is set, it's
locked. To derive whether any bit is set, you can use either the logand or
the boole function, or today we can use ActiveX info, but I would bet it's
slower for this particular usage.

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332
Message 8 of 9
Anonymous
in reply to: Anonymous

"John Uhden" wrote in message
news:CB6778526AE8409A01283F340763844D@in.WebX.maYIadrTaRb...
> Doug:
>
> > ... I'm not familiar with the entmod form you suggest.
> I thought for sure you had followed the lengthy discussion on "Group 60 -
> visibility" that concluded less than two weeks ago. If not, go back and
> look at it.

After the NG forced a reset earlier this week, those threads have vanished. Must
I do another reset to retrieve them? Get Headers does nothing... (OE)
-doug
ps I had a friend from SeaGirt years ago. Hoffman?
Message 9 of 9
Anonymous
in reply to: Anonymous

I don't know any Hoffmans in Sea Girt, though there is a B. Hoffman listed
in the white pages just a few blocks away from me. Wonder if it's any
relation to Bob Hoffman (originally from Point Pleasant Beach where I grew
up) who has a pair of ice cream parlors, one in Point Beach and one in
Spring Lake Heights. All these little towns are in a row along the Jersey
shore along with Manasquan, Brielle, Spring Lake, Belmar, etc.

Here's the most valuable response in that Visibility thread, from Art
Cooney:
------- start snip -------
That's "sort of" true. For post-R12 entities, and all symbolTableRecords,
you must include all of the group 100s in order for the code to know what
data should be handled by which entity class (C++ class). If you include all
of the group 100s the partial data will be read by the proper class for that
data, but for post R12 entities, the code used for entmod is the same code
as used for reading the entity in from a DXF file and most of the post-R12
entities were written only with DXF file reading in mind. So, they have
problems when not all of the data is present in the data list. For example,
if you use a partial data list on an AcDbPolyline and your partial data list
doesn't include at least two vertex points, the code will automatically add
one or two <0,0> vertices because the code thinks a polyline is being
created with less than two vertices and that's not allowed.

"Vladimir Nesterovsky" wrote in message
news:853BE0B22988B09BB9E9609CEC8B7CB8@in.WebX.maYIadrTaRb...
> I think you can always use shortened list as long as
> it contains all the object markers (100 code groups).
>
> Correct me if I'm wrong,
> --
> Have fun, 🙂
> Vlad http://vnestr.tripod.com/
> (define (list . args) args)
>
>
> John Uhden wrote in message
> news:23030412BC125B9905843B8A51A6F4D3@in.WebX.maYIadrTaRb...
> > Yes it's been discussed, but "some"where I missed the "some"
> qualification.
> > Guess I'm more of an ordinary rabbit. Now back to entmod.
> >
> > --
> > John Uhden, Cadlantic/formerly CADvantage
> > --> mailto:juhden@cadlantic.com
> > --> http://www.cadlantic.com
> > 2 Village Road
> > Sea Girt, NJ 08750
> > Tel. 732-974-1711
> > FAX 732-528-1332
> >
> >
> > "Frank Oquendo" wrote in message
> > news:47AC8A9450C8B7B75CB5470CEFB270D6@in.WebX.maYIadrTaRb...
> > > What's interesting about it? With some entities, you can use a short
> > > list, with others you must use a full list. I believe that has already
> > > been mentioned.
> >
> >
> >
>
>
------- end snip -------

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332

"Doug Barr" wrote in message
news:F902D4338661A74277806FEEF0EC9594@in.WebX.maYIadrTaRb...
>
> "John Uhden" wrote in message
> news:CB6778526AE8409A01283F340763844D@in.WebX.maYIadrTaRb...
> > Doug:
> >
> > > ... I'm not familiar with the entmod form you suggest.
> > I thought for sure you had followed the lengthy discussion on "Group
60 -
> > visibility" that concluded less than two weeks ago. If not, go back and
> > look at it.
>
> After the NG forced a reset earlier this week, those threads have
vanished. Must
> I do another reset to retrieve them? Get Headers does nothing... (OE)
> -doug
> ps I had a friend from SeaGirt years ago. Hoffman?
>
>

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

Post to forums  

Autodesk Design & Make Report

”Boost