How to generate text list in model space of all current layers

How to generate text list in model space of all current layers

tomhY595S
Enthusiast Enthusiast
1,357 Views
4 Replies
Message 1 of 5

How to generate text list in model space of all current layers

tomhY595S
Enthusiast
Enthusiast

Hi, I'm re-working the office template, I've got approx 120 Layers. I want to be able to use/create a LISP command that essentially exports all the existing layers from the drawings into an external text/ spreadsheet file which I can then copy back in and assign each of the layers to. (alternatively, if there is a smarter way to do it am all ears. 

 

Essentially I want to end up with all the layers with the text description and assigned properties, so we can have the info ready to match/ use in model space)

 

I've found a few resources but when trying to implement ran into issues that would not work - don't fully understand them so if someone can explain would great.  

https://jtbworld.com/autocad-layer-list-lsp 

https://www.theswamp.org/index.php?topic=45334.0 

 

 

tomhY595S_0-1656346601392.png

 

0 Likes
1,358 Views
4 Replies
Replies (4)
Message 2 of 5

pendean
Community Legend
Community Legend

Open your layer command palette.
select ALL (CTRL+A)
CTRL+C
then CTRL+V into modelspace or whatever other application window you want to use.
Done.

 

Read this to learn about how to use LISP http://www.lee-mac.com/runlisp.html

 

 

0 Likes
Message 3 of 5

tomhY595S
Enthusiast
Enthusiast

Hi Pendean, 

Thanks for this. so it does copy them all as 1 text but as one layer too. Is there a way to have them in individual colours/layers? 

tomhY595S_0-1656348956938.png

 

Tom 

(will take a look at the lee-mac link) 

0 Likes
Message 4 of 5

hak_vz
Advisor
Advisor

@tomhY595S 

Here is code you are looking for.

It generates MText with names of all layers in current drawing colored to individual layer color.

Hope this is what you want.

 

Changed code

Opted for plane TEXT object since MTEXT has limit in number of paragraphs (lines)

 

 

(defun c:AllLayers ( / collectLayerObjects layerObjects layerNames colorList ts i p1)
	(defun collectLayerObjects ( / ret) 
		(reverse (vlax-for lay (vlax-get (vla-get-activedocument (vlax-get-acad-object)) 'Layers) 
		(setq ret (cons (cons (vlax-get lay 'Name) lay)ret))))
	)
	(setq 
		layerObjects(collectLayerObjects)
		layerNames (mapcar 'car layerObjects)
		layerObjects (mapcar 'cdr layerObjects)
		colorList (mapcar '(lambda (x)(vlax-get x 'Color)) layerObjects)
		i -1
		ts (* 1.5 (getvar 'Textsize))
	)
	(setq p1 (getpoint "\nPick text insert point >"))
	(while (< (setq i (1+ i)) (length layerNames))
		(entmakex
			(list
				 (cons 0   "TEXT")         
				 (cons 100 "AcDbEntity")          
				 (cons 100 "AcDbText")    
				 (cons 10 p1)        
				 (cons 1 (nth i layerNames))
				 (cons 40 (getvar 'Textsize))
				 (cons 50 0)
				 (cons 62 (nth i colorList))
			)
		)
		(setq p1 (mapcar '- p1 (list 0 ts)))
	)	
	(princ)
)

 

Your modified file is in attachment

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Quick and dirty note no check for rgb colors 

 

(defun c:Layers2csv ( /  fo )
	(setq fo (open  "D:\\acadtemp\\lays.csv" "W"))
	(vlax-for lay (vlax-get (vla-get-activedocument (vlax-get-acad-object)) 'Layers)
     (write-line (strcat (vla-get-name lay) ","  (rtos (vla-get-color lay) 2 0) ","  (vla-get-linetype lay) ) fo)
	)
   (close fo)
(princ)
)
(c:Layers2csv  )

 

Look into the =concatenate command in excel, you can make your layer changes in excel and just copy a column back to command line. Just have to get correct sequence. Use paste, special, script text.

0 Likes