How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
I am new to LISP and was wondering if it is possible to draw a line and then another below that (such as an array) one each for all the layers in a drawing? I would also like to create text next to the line that has the name of the layer. This line and text should be on the layer in question.
I can do it manually but wondered if was easier to automate!
Many thanks for your time
Adam
Solved! Go to Solution.
@Anonymous wrote:
I am new to LISP and was wondering if it is possible to draw a line and then another below that (such as an array) one each for all the layers ...........
Adam
If I understand correctly then something like this may work.
(defun c:somefunc (/ pt dat ln) (setq pt (getpoint "\nSelect insertion point: ")) (while (setq dat (tblnext "layer" (null dat))) (entmake (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0 0))) (cons 8 (setq ln (cdr (assoc 2 dat)))))) (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0 0))) '(40 . 0.1) (cons 1 ln) (cons 8 ln))) (setq pt (mapcar '- pt '(0 0.15 0)))) (princ))
That is exactly what I was looking for! Pure genius. Love the little video too!
Hello Ranjit (The MAPCAR Jedi)
1) Beautiful (and SO SHORT) routine, so Kudos for you !
2) Please may I ask for a few improvments:
- Display Layer Name = OK
- Please display after the Description Layer Name (if there is one)
- Is it possible to have a choice :
-- Either ALL Layers (as your 1st routine)
-- OR select Entities (Classic AutoCAD selection)
so we will get only the Layers used (by the selected entities) ...
Do you see what I mean ?
Thanks in advance, Regards, Patrice
Patrice BRAUD
Hi @braudpat. I assume you meant adding the description column from the layer properties manager. I would recommend adding error trap. Very minimal testing.
(defun c:somefunc (/ pt rsp dat ln lst desln) (initget "All Select") (setq pt (getpoint "\nSelect insertion point: ")) (initget "Select All") (setq rsp (getkword "\nSpecify option [Select / All] <All>:")) (cond ((= rsp "Select") (mapcar '(lambda (x) (setq pt (somefunc2 pt x))) (progn (acad_strlsort (mapcar '(lambda (x) (and (null (member x lst)) (setq lst (cons x lst)))) (mapcar '(lambda (x) (cdr (assoc 8 (entget x)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget))))))) lst))) (t (while (setq dat (tblnext "layer" (null dat))) (setq pt (somefunc2 pt (cdr (assoc 2 dat))))))) (princ)) (defun somefunc2 (pt ln / desln) (entmake (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0))) (cons 8 ln))) (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0))) '(40 . 0.1) (cons 1 ln) (cons 8 ln))) (if (zerop (strlen (setq desln (getpropertyvalue (tblobjname "layer" ln) "Description")))) () (entmake (list '(0 . "text") (cons 10 (mapcar '+ pt '(4.5 0))) '(40 . 0.1) (cons 1 desln) (cons 8 ln)))) (mapcar '- pt '(0 0.15)))
Hello The MAPCAR Jedi
THANKS, it's perfect !
Happy Week-End, Regards, Patrice
Patrice BRAUD
Amazing LISP! Thank you for publishing this!
Any way you could adapt this to do the same for linetypes...?
Very good stuff. I was searching exactly this.
Saved lots of time.
Thanks Bro.
Harish
Hey Ranjit,
this LISP is crazy good, but I was wondering - is it possible to add a keyword that would then draw all layers which contain that keyword?
For e.g.: run the function, it asks you for a keyword, you type in ''CONSTR" and then it creates lines of layers whose name contains that keyword (''CONSTR'').
Thanks and kind regards.
Beautiful! thank you
Can the list be sorted by layer name?
They come out all disorganized.
Try this modified version.
(defun c:test ( / doc lyrs lst pt) (setq doc (vla-get-activedocument (vlax-get-acad-object)) lyrs (vla-get-layers doc) );end_setq (vlax-for lyr lyrs (setq lst (cons (vlax-get lyr 'name) lst))) (setq lst (vl-sort lst '< ) pt (getpoint "\nSelect insertion point: ") );end_setq (foreach lyr lst (entmakex (list '(0 . "line") (cons 10 pt) (cons 11 (mapcar '+ pt '(2.5 0 0))) (cons 8 lyr))) (entmakex (list '(0 . "text") (cons 10 (mapcar '+ pt '(3.0 0 0))) '(40 . 0.1) (cons 1 lyr) (cons 8 lyr))) (setq pt (mapcar '- pt '(0 0.15 0))) );end_foreach (princ) );end_defun
I am not one of the robots you're looking for
That is excellent.
Thank you very much. =]
I press the like button.
But could you add more code for sorting layer names as Anphabe?
Now, they come out all disorganized.
Thank you in advance.
See message 12 by dlanorh
Hi @moon47usaco,
Thanks for your response. However, this code which you mentioned that I found has no option "select" as above message 05 of Mr. Ranjit.Singh.
So, I would like to find that has two options and with Anphabe.
Thanks for your time!
@tranminhthong0993 wrote:
So, I would like to find that has two options and with Anphabe.
What is that?
Yeah, LISP to create a line and text from a layer name which are organized alphabetically.
Something like that... Thanks...
To clarify I bileave tranminhthong0993 wants the best of both worlds.
He wants the list of layers to be alpha ordered like in post #12 and also wants the options available in #05.
IE:
Specify option [Select / All] <All>:
Hopefully someone can mash up the code in those two posts into one nice lisp =]
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name