Hi,
I want to make a list of layers due to their index (order) in the "layers combo box" in the AutoCAD.
I prepared this:
(defun c:ListLayers ( / a b) (setq a(list(cdr(assoc 2(tblnext "layer" T))))) (while(setq b(tblnext "layer")) (setq a(append a(list(cdr(assoc 2 b))))) );while );end
But, It's not match with the order of layers.
Does anybody has any idea?
Thanks,
Abbas
Maybe ...
(defun c:Test (/ b l) (while (setq b (tblnext "LAYER" (not b))) (setq l (cons (cdr (assoc 2 b)) l)) ) (reverse l) )
Hi,
Thanks for your code,
but your code has same result as of my code:
(defun c:ListLayers ( / a b) (while(setq b(tblnext "layer" (not b))) (setq a(append a(list(cdr(assoc 2 b))))) );while );end
Thanks,
Hi Abbas,
something like this perhaps...
(defun c:test ( / a b) (while (setq a (tblnext "Layer" (null a))) (setq b (cons (cdr (assoc 2 a)) b)) );; while (setq b (acad_strlsort b)) );; test
HTH
Henrique
Hi Henrique,
Thanks for your code, but the layers are not in alphabetical sort.
I re-order them by colors, so they are not in regular AutoCAD's sort algorithm.
Thanks,
@aqdam1978 wrote:
Hi Henrique,
Thanks for your code, but the layers are not in alphabetical sort.
I re-order them by colors, so they are not in regular AutoCAD's sort algorithm.
Thanks,
Abbas,
sorry , but by color I don't know...
Henrique
@aqdam1978 wrote:
....
Thanks for your code, but the layers are not in alphabetical sort.
I re-order them by colors, so they are not in regular AutoCAD's sort algorithm.
....
For an alphabetical listing, you can use your original followed by:
(vl-sort a '<)
To sort by color, you would probably need to make a list of layer-and-its-color pairs, and sort by the color as one element of each pair. I can figure out how to do that, and will later if someone else doesn't beat me to it.
EDIT: Like this:
(defun C:LLBC ; = List Layers By Color
(/ laydata laynamecolor)
(while (setq laydata (tblnext "layer" (not laydata))); Layers in creation order
(setq laynamecolor
(cons
(cons (cdr (assoc 2 laydata)) (cdr (assoc 62 laydata))); dotted-pair name with color
laynamecolor
); cons
); setq & laynamecolor
); while
(setq laybycolor
(vl-sort
laynamecolor
'(lambda (a b)
(< (cdr a) (cdr b)); sort by color [2nd half of dotted pair]
); lambda
); vl-sort
); setq & laybycolor
); defun -- C:LLBC
Then, if you want a list of just the names, in that order but without the color numbers attached:
(mapcar 'car laybycolor)
Hi Kent,
I don't want to sort by color.
I just want make a list exactly match with order of AutoCAD's "layers combo box".
Because this sort is not by alphabetical sorting. and I sort them by colors.
I just want to make a list of layers name by their index in AutoCAD's layers combo box!
Thanks,
@aqdam1978 wrote:
....
I don't want to sort by color.
I just want make a list exactly match with order of AutoCAD's "layers combo box".
Because this sort is not by alphabetical sorting. and I sort them by colors.
I just want to make a list of layers name by their index in AutoCAD's layers combo box!
....
There seems to be a conflict between your earlier "I re-order them by colors" and this latest "I don't want to sort by color." Can you clarify?
I'm not familiar with a "layers combo box," but I'm on an older version here [and I also wonder whether it's part of an overlay program rather than native to AutoCAD itself]. If it's the same thing as the Layer Manager, that comes up initially in alphabetical order. My suggestion sorts by color, and within any group of multiple Layers of the same color, in Layer-creation order. If you want them sorted by color but alphabetically among any of the same color, that's an easy adjustment. If you can describe what the "combo box" uses for its order, that can probably be emulated. But if you're going to re-order them by color, does it matter what order they're in before the re-ordering?
Hi Kent,
I did re-order the layers by the color before. and now I want to make a layers list by their index in the AutoCAD drop-down layers combo-box!
becuase if you use this code:
(defun c:ListLayers ( / a b) (while(setq b(tblnext "layer" (not b))) (setq a(append a(list(cdr(assoc 2 b))))) );while );end
It will make a layer list by creation time not their re-oredered index in the AutoCAD's drop-down layers menu!
sorry for my english!
Thanks,
Abbas
What precise "index" are you intending to use to order the layers?
The layers in AutoCAD don't make any use of an index value. When sorted in the layer palette/dialog, it is based on the user-provided layer property (layer, ACI, on/off, and so on). There is no separate "index" property to read based on the current display. If you want a similarly arranged list, then you will need to do a sort in the same fashion, including providing the sort criteria.
@aqdam1978 wrote:
.... now I want to make a layers list by their index in the AutoCAD drop-down layers combo-box!
becuase if you use this code:
(defun c:ListLayers ( / a b) (while(setq b(tblnext "layer" (not b))) (setq a(append a(list(cdr(assoc 2 b))))) );while );endIt will make a layer list by creation time not their re-oredered index in the AutoCAD's drop-down layers menu!
....
If the drop-down list in the Layer Properties toolbar is what you mean, that's alphabetical [in my older version]. See the beginning of my first Reply for something you can add to the end of your own routine to sort your 'a' list alphabetically.
@Kent1Cooper wrote:
...
If the drop-down list in the Layer Properties toolbar is what you mean, that's alphabetical [in my older version]. See the beginning of my first Reply for something you can add to the end of your own routine to sort your 'a' list alphabetically.
Kent,
my understanding is, when yhe OP says "layers combo box", means the drop-down list at the Ribbon, but the order is established at "Layer Properties Manager" by clicking at column "Name", "Freeze, "Color"...
When is sorted by name, is not sorted alphabetically, like the way you have shown (vl-sort a '<), is in a diferent "alphabetical order"...
From the Vlisp console:
_$
_$ (setq a '("a-Test" "02" "01" "_01" "a_Color"))
("a-Test" "02" "01" "_01" "a_Color")
_$ (acad_strlsort a)
("_01" "01" "02" "a-Test" "a_Color") << As "mine" "Layer Properties Manager" sort layers by name (not fully tested)
_$ (vl-sort a '<)
("01" "02" "_01" "a-Test" "a_Color")
_$
When is sorted by color, I think the list is created by color name (white, yellow,..., color number, Collor book names, amd HLS numbers)...
Just a thought, not sure...
Henrique