AutoCAD Map 3D Forum
Welcome to Autodesk’s AutoCAD Map 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assign multiple autocad drawing object layers different colors quickly, how to?

21 REPLIES 21
Reply
Message 1 of 22
jgray
1758 Views, 21 Replies

Assign multiple autocad drawing object layers different colors quickly, how to?

Hey guys,

I have a drawing that is full of autocad drawing layers, not FDO layers, and am looking for a way to get autocad to assign each layer a different color quickly. I know some colors might get reused and I am fine with that.  My current drawing has something like 11,000 layers, yes 11,000.

 

What I want is something very similar to how you can theme FDO connected data, but I just want to do this for autocad drawing

objects. Maybe I could isolate all the layers that I want to change colors on and then issue the command and it go though and start changing the layer value colors.  What would be even neater is if I could choose a color book and it start applying the color changes by layer, of course. Also be extra neat if it would skip maybe ever 20 colors listed in the color book, because a lot of the colors that are next to each other in the color book for lets say "Pantone paper" look almost identical. Really however the color book thing might be to hard, so if I somehow had like 100 different colors and it kept looping through these 100 different looking colors that would be enough.  Shoot honestly like 50 differnt colors it kept looping though would be enough. 

 

Anybody know of a way to do this?  

21 REPLIES 21
Message 2 of 22
parkr4st
in reply to: jgray

interesting

 

is the data from your perevious problem with the layer name creation or something different?

 

 

Message 3 of 22
jgray
in reply to: parkr4st

Yep, from my previous drawing that you helped me with :).  All of our clients only understand what I will refer to as "actual autocad entities" refering to polylines or lines, so when I give them something it has to be all "actual autocad entities" and if it has data attached to the polylines you have to be able to see it using only the properties window.  So now i have this drawing with 11,000 layers in it of polylines that has the data attached to each and I need to do some layer coloring to distingush between the polylines, I feel like 50 different colors or so looped would be enough. 

Message 4 of 22
parkr4st
in reply to: jgray

random colors are ok?

 

how many plines in total?  11,000 layers with how many per layer average or something like that?

Message 5 of 22
parkr4st
in reply to: parkr4st

and is you layer number (205 in your example)  or the OD value for SEAM (205 in your example) unique to each layer after the mapimport?

Message 6 of 22
jgray
in reply to: parkr4st

Mostly each layer has about 5 polylines on it, some more, maybe 20 polylines, some less maybe only one.  Attached is an example of what my current layer manager looks like.   

Message 7 of 22
parkr4st
in reply to: jgray

back to your sdf

 

theme by the layer that you concatted

 

Command: _mapexportcurrentmaptodwg

 

new name for the file

 

try that

Message 8 of 22
jgray
in reply to: parkr4st

I don't think I can do that, because if I do then I will not have data attached to the polylines any more, correct?
Message 9 of 22
parkr4st
in reply to: jgray

you're right

 

sorry about that one

 

I have to finish a report so have to go for now.  Will try it later if you don't post a solution.

 

dave

Message 10 of 22
parkr4st
in reply to: parkr4st

the colors

 

Make a copy of your work to date just in case

 

examine your field layer or field seam

 

if all the values fall between 10 & 249  you can use that value to set colors with.

 

If the values are not in the range, in the sdf table do a simple calc such as round(layer/10,0); changes 230 to 23 for example  or  round ( layer/100, 0 ) *10 ;turns 230 to 20 for example. 

save to a new sdf.  mapimport sdf with OD and set the layer names as before on the import. save & close the dwg and open a new one, map explorer, attach the dwg and query location all and using the new color value to alter property Color.

 

Query mode Draw and execute.  you now have groups of colored lines relative to the value of field layer.  you can experiment with math in the equation to find a range of colors you like.   The best range is 10, 11, 20, 21, 30, 31 etc.  brighter colors. 

 

May not be what just you want, but it can be done by trying calculations to alter data you have.   The OD is attached to the lines also.

 

dave

 

 

 

Message 11 of 22
antoniovinci
in reply to: parkr4st

Nice question, given that 11k layers in a single drawing is really insane...

Maybe the quickest solution is to make a script like this, e.g. with a spreadsheet:

 

_-LA _C _T r,g,b namelayer1 ''

_-LA _C _T r,g,b namelayer2 ''

...

_-LA _C _T r,g,b namelayer11000 ''

 

You can get the list of layers (namelayer1,2,...) thru the attached lisp by Augi.

The column r,g,b would be filled by the "random-within-a-range" function of your spreadsheet.

Message 12 of 22
jgray
in reply to: antoniovinci

Hey guys,
Attached is my current autocad drawing as well as the .sdf file that I used "mapimport" in order to create my current autocad file. To see if you guys can help me. I know some colors might get reused and I am fine with that. What I want is something very similar to how you can theme FDO connected data, but I just want to do this for autocad drawing objects. What would be even neater is if I could choose a color book and it start applying the color changes by layer.

 

Also be extra neat if it would skip maybe ever 20 colors listed in the color book, because a lot of the colors that are next to each other in the color book for lets say "Pantone paper" look almost identical. Really however the color book thing might be to hard, so if I somehow had like 100 different colors and it kept looping through these 100 different looking colors that would be enough.  Shoot honestly like 50 differnt colors it kept looping though would be enough. 

 

https://www.dropbox.com/s/lnw91e293hbbvah/test.sdf?dl=0

 

https://www.dropbox.com/s/2ismkmemliwtoqo/KNOWN%20MINED%20OUT%20AREAS%20BY%20SEAM-KY%20SINGLE.dwg?dl...

 

 

The key thing is that the final autocad file has to be made of actual polylines, and that the other data that is attached to each polyline still has to be there when I check the properties of the polyline. 

Message 13 of 22
parkr4st
in reply to: jgray

like this maybe?

 

http://a360.co/1ASkrjW

 

dave

Message 14 of 22
olivier.eckmann
in reply to: jgray

Hi,

 

with this code you can assign a random true color for each layer

 

(defun Rand01 (/ digits)
  (setq digits (substr (rtos (rem (getvar 'date) 1) 2 16) 13))
  (list (atof (strcat "0." (substr digits 3 3) (substr digits 1 3) (substr digits 6)))
	(atof (strcat "0." (substr digits 6 4) (substr digits 1 5) (substr digits 10)))
	(atof (strcat "0." (substr digits 4 4) (substr digits 1 2) (substr digits 7)))
  )
); end defun

(defun c:RndColorLayer() 
  (vl-load-com)
  (setq oApp (vlax-get-Acad-Object) 
        oDoc (vla-get-ActiveDocument oApp) 
  ) 

  (vlax-for oLayer (vla-get-layers oDoc)
    (setq oColor (vlax-get-property oLayer 'TrueColor))
    ;; Set TrueColor to blue (R=0, G=101, B=204)
    (setq lsRnd (Rand01))
    (vlax-invoke-method oColor 'SetRGB (* 255 (nth 0 lsRnd)) (* 255 (nth 1 lsRnd)) (* 255 (nth 2 lsRnd))) 
    (vlax-put-property oLayer 'TrueColor oColor) 
    ;(vla-update oLayer) 
  )
  
) 

 

 

Olivier

Message 15 of 22
jgray
in reply to: olivier.eckmann

oliver.eckmann   that kind of worked but i get alot like the attached image which shows alot of repeat colors. The layers I am showing in the attached image are in order with each other by name, and it applied the same color to several layers one after the other.  Parker4st how did you do yours? oliver.eckmann lisp is more of what I want in that it doesn't change the layer name just the by layer color, however if i got to choose the polyline layers it changed colors on instead of all layers in the drawing, like the border layer, north arrow layer, barscale layer, that would be great.   

Message 16 of 22
olivier.eckmann
in reply to: jgray

Hi,

 

here is another random method which shouldn't generate identical values for true color

 

(defun c:RndColorLayer() 
  (vl-load-com)

  (setq z 362436069 w 521288629)
  (defun MWC (/)
	(fix (abs (/ (+ (lsh (setq z (+ (* 36969 (logand z 65535)) (lsh z -16))) 16)
			(logand (setq w (+ (* 18000 (logand w 65535)) (lsh w -16))) 65535)
		     ) 8421504.0)))
  )
  
  (setq oApp (vlax-get-Acad-Object) 
        oDoc (vla-get-ActiveDocument oApp) 
  ) 

  (vlax-for oLayer (vla-get-layers oDoc)
    (setq oColor (vlax-get-property oLayer 'TrueColor))
    ;; Set TrueColor to blue (R=0, G=101, B=204)
    (setq lsRnd (Rand01))
    (vlax-invoke-method oColor 'SetRGB (MWC) (MWC) (MWC)) 
    (vlax-put-property oLayer 'TrueColor oColor) 
  )
  
) 

 

 

Olivier

Message 17 of 22
jgray
in reply to: olivier.eckmann

I couldn't get that last lisp to work. 

Message 18 of 22
olivier.eckmann
in reply to: jgray

Hi 

 

sorry for code, i forget to remove a line not used. Here is the new code (I don't know how to edit my last message)

 

(defun c:RndColorLayer() 
  (vl-load-com)

  (setq z 362436069 w 521288629)
  (defun MWC (/)
	(fix (abs (/ (+ (lsh (setq z (+ (* 36969 (logand z 65535)) (lsh z -16))) 16)
			(logand (setq w (+ (* 18000 (logand w 65535)) (lsh w -16))) 65535)
		     ) 8421504.0)))
  )
  
  (setq oApp (vlax-get-Acad-Object) 
        oDoc (vla-get-ActiveDocument oApp) 
  ) 

  (vlax-for oLayer (vla-get-layers oDoc)
    (setq oColor (vlax-get-property oLayer 'TrueColor))
    ;; Set TrueColor to blue (R=0, G=101, B=204)
    (vlax-invoke-method oColor 'SetRGB (MWC) (MWC) (MWC)) 
    (vlax-put-property oLayer 'TrueColor oColor) 
  )
  
) 

 

 

Olivier

Message 19 of 22
jgray
in reply to: olivier.eckmann

sorry still can not get that one to work. 

Message 20 of 22
olivier.eckmann
in reply to: jgray

Hi,

 

work for me on MAP 3D 2012 64bit. Is there an error message or something written in command line?

 

here is link to your file modified with the lisp code

 

Olivier

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

Post to forums  

Autodesk Design & Make Report

”Boost