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

Table from layer information of selected polylines

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
sandeep.kumarPKH3F
616 Views, 14 Replies

Table from layer information of selected polylines

Hello,

I am using AutoCAD 2022.

I am checking if there is any lisp available to fetch layer information from selected polylines and create a table showing the layer names (related to selected polylines only).

 

Thanks in advance to all the subject matter experts.

14 REPLIES 14
Message 2 of 15

Dataextraction command is perfect for this.

It opens up a wizard where you can choose to select objects

 

Choose create new and click Next then give it a name like Pline and click Save

paulli_apa_1-1662532405656.png

Then choose the option to Select Objects in current drawing and click on the button right next to it

paulli_apa_2-1662532499476.png

Select the Plines on the screen and hit return when done

click Next 2x

Then for Category only check General & Property only check Layer

paulli_apa_3-1662532655852.png

Click Next button and you should now see the Plines you've selected and the Layer they're on

paulli_apa_4-1662532687020.png

You can remove the Count column by unchecking Show count column and click Next

Lastly select Insert data extraction Table into drawing and click Next

paulli_apa_5-1662532889864.png

You may have to zoom in really tight to see the Table.

 

 

 

 

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 15

Thanks Paulli,

I basically want to eliminate some of the steps from data extraction command. 

I need that it should automatically fetch layer information from  the selected polylines and place a table with the layer information in the drawing.

I am not sure if we could use script to meet this requirement otherwise we need a lisp.

Message 4 of 15

Possibly this simple lisp could do that.

 

(vl-load-com)

(defun c:Layerlist ( / s i y l)
  
  (if (setq s (ssget '((0 . "*POLYLINE"))))
    (progn
      (repeat (setq i (sslength s))
	(setq y (cdr (assoc 8 (entget (ssname s (setq i (1- i)))))))
	(if (not (vl-position y l)) (setq l (cons y l))))
      (entmake (list '(0 .  "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 (getpoint "\nPlace the list: ")) (cons 40 (getvar 'textsize))
		     (cons 1 (strcat "LAYERLIST: " (apply 'strcat (mapcar '(lambda (x) (strcat (chr 10) x)) (vl-sort l '<)))))))))
  (princ)
  )

 

Message 5 of 15

Many thanks @ВeekeeCZ,

It is solving my purpose. Is it possible to show this text with leader.

 

Message 6 of 15

Illustrate how it should look like.

Message 7 of 15

Hello @ВeekeeCZ,

 

I am looking for end results shown in the below image. Arrow shape doesn't matter, I just want to point to a location.

sandeepkumarPKH3F_0-1662974783865.png

 

Thanks for your help.

 

Message 8 of 15

Ok then.

 

(vl-load-com)

(defun c:Layerlist ( / s i y l)
  
  (if (setq s (ssget '((0 . "*POLYLINE"))))
    (progn
      (repeat (setq i (sslength s))
	(setq y (cdr (assoc 8 (entget (ssname s (setq i (1- i)))))))
	(if (not (vl-position y l)) (setq l (cons y l))))
      (command "_mleader" "_h" pause pause (strcat "LAYERLIST: " (apply 'strcat (mapcar '(lambda (x) (strcat (chr 10) x)) (vl-sort l '<)))))))
  (princ)
  )
Message 9 of 15

Hello @ВeekeeCZ,

It is only creating the leader. See below image. I have also attached the screen shot of command line, it is showing invalid input message at few places:

 

sandeepkumarPKH3F_0-1662977015759.png

 

sandeepkumarPKH3F_2-1662977162220.png

Thanks

 

Message 10 of 15

Well, it works for me. You can try to remove "_h" from the code.

Also, you might need to add another pause - it's depending on your style preference.

 

If neither works, post screenshots of your mleader style dialog - the second and third tabs.

Message 11 of 15

Thanks @ВeekeeCZ,

It is working perfectly now. Thanks for your help.

Message 12 of 15
Sea-Haven
in reply to: ВeekeeCZ

Just a suggestion, whilst the code does a sort now should it reflect the layers in the drawn order ? Water Gas Elec Telecomms, more like the multi plines I am used to.

 

(setq s (ssget "F" (list pt1 pt2) '((0 . "*POLYLINE"))))

The pt1 pt2 are pick points for the direction of selection then layers will be in select order.  

Message 13 of 15

@ВeekeeCZ , I am facing an issue with the layerlist lisp. It is working fine for few numbers of layers, but when number of layers are more, it is only printing the leader in the model space and layer names are only showing up at the command bar history.

sandeepkumarPKH3F_3-1673418460514.png

 

sandeepkumarPKH3F_2-1673418394865.png

 

Could you please help me to fix it.

Thanks

 

Message 14 of 15

ALWAY post a sample drawing.

 

Try this if it fixes it.

 

(vl-load-com)

(defun c:Layerlist ( / s i y l)
  
  (if (setq s (ssget '((0 . "*POLYLINE"))))
    (progn
      (repeat (setq i (sslength s))
	(setq y (cdr (assoc 8 (entget (ssname s (setq i (1- i)))))))
	(if (not (vl-position y l)) (setq l (cons y l))))
      (command "_mleader" pause pause "")
      (if (> (getvar 'cmdactive) 0)
	(progn
	  (command)
	  (alert "ERROR: Wrong workflow setting of the MLEADER command.\n\nGoto the MLEADER command and adjust the setting to specify an Arrowhead or Landing first."))
	(setpropertyvalue (entlast) "MText/Contents" (strcat "LAYERLIST: " (apply 'strcat (mapcar '(lambda (x) (strcat (chr 10) x)) (vl-sort l '<))))))))
  (princ)
  )

 

Message 15 of 15

Thanks @ВeekeeCZ , Now it is working perfectly now.

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report