Terry.T Posted May 13, 2021 Posted May 13, 2021 Hi, I am a beginner and I had a problem about sorting. I had many block with attributes "SORT_ORDER" and "NUMBER" what i want to do is : 1. Select all block in a list (setq lst1 (ssget "x" '((8 . "layer")))) 2. sort list by attributes "SORT_ORDER" (no idea) 3.apply new number by lst1 form 001 to 100 into attributes (3 digit). Because we need to change the number many many time but the number must in order. such as block format:("SORT_ORDER"== "NUMBER") (1==001), (2== 002), (3== 003), (4== 004), (5== 005), (6== 006), (7== 007) we want to del 3 (1== 001), (2==002), (4== 003), (5== 004), (6== 005), (7== 006) and add back 3 and add 2.1 between b and c (1== 001), (2== 002, (2.1== 003), (3== 004), (4== 005), (5== 006), (6== 007), (7== 008) Thanks, Quote
mhupp Posted May 13, 2021 Posted May 13, 2021 (edited) look into this function https://documentation.help/AutoLISP-Functions/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-687f.htm Edited May 13, 2021 by mhupp Quote
hosneyalaa Posted May 13, 2021 Posted May 13, 2021 On 5/13/2021 at 6:52 AM, Terry.T said: Hi, I am a beginner and I had a problem about sorting. I had many block with attributes "SORT_ORDER" and "NUMBER" what i want to do is : 1. Select all block in a list (setq lst1 (ssget "x" '((8 . "layer")))) 2. sort list by attributes "SORT_ORDER" (no idea) 3.apply new number by lst1 form 001 to 100 into attributes (3 digit). Because we need to change the number many many time but the number must in order. such as block format:("SORT_ORDER"== "NUMBER") (1==001), (2== 002), (3== 003), (4== 004), (5== 005), (6== 006), (7== 007) we want to del 3 (1== 001), (2==002), (4== 003), (5== 004), (6== 005), (7== 006) and add back 3 and add 2.1 between b and c (1== 001), (2== 002, (2.1== 003), (3== 004), (4== 005), (5== 006), (6== 007), (7== 008) Thanks, Expand Attached drawing example pls Quote
Terry.T Posted May 14, 2021 Author Posted May 14, 2021 TEST-LSP FOR NUMBING2.dwgFetching info... thanks for the reply. and here is what i am doing yesterday. (defun C:nm ( / sel1 sel2 ) (setq num 0) (setq lop 0) (setq sel1 (ssget "x" '((8 . "NUMBERING")))) (foreach pp1 (ssnamex sel1) (setq num (1+ num)) ) (foreach pp (ssnamex sel1) (setq sel2 (ssname sel1 lop)) (setq a (entnext sel2)) (setq b (entnext a)) (setq c (entget b)) (setq d (assoc 1 c)) (setq e (cdr d)) (setq num (1- num)) (setq lop (1+ lop)) (setq a1 (cons e a1)) ) ;foreach (vl-sort a1 '<) );end defun On 5/13/2021 at 12:36 PM, hosneyalaa said: Attached drawing example pls Expand i am not sure is it a right way to sort the block. Thanks. Quote
Terry.T Posted May 14, 2021 Author Posted May 14, 2021 On 5/13/2021 at 12:14 PM, mhupp said: look into this function https://documentation.help/AutoLISP-Functions/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-687f.htm Expand Thank for the reply, I am trying to use vl-sort, but i can't find the right way to sort it. i think it is sorting the number only, not the block. Thanks. Quote
Terry.T Posted May 14, 2021 Author Posted May 14, 2021 TEST-LSP FOR NUMBING2.dwgFetching info... hi all i think this file will better than before. Thank again. Quote
mhupp Posted May 14, 2021 Posted May 14, 2021 (edited) try this (defun C:nm (/ ss i blk atts lst a1 P O) (vl-load-com) (setq ss (ssget '((0 . "INSERT") (8 . "NUMBERING")))) ;only select blocks on numbering layer (repeat (setq i (sslength ss)) (setq blk (vlax-ename->vla-object (ssname SS (setq i (1- i)))) atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))) ) (foreach x atts (if (= (vla-get-tagstring x) "PORT_NUMBER") (setq P (vla-get-textstring x)) (setq O (vla-get-textstring x)) ) ) (setq lst (list P O)) ;create a mini list (setq a1 (append a1 (list lst))) ;join all mini lists into big list ) (vl-sort a1 '(lambda (x y) (< (car x) (car y)))) ;sort by first item in the mini list ) 3. I don't know what you mean. Edited May 14, 2021 by mhupp 1 Quote
Lee Mac Posted May 16, 2021 Posted May 16, 2021 Another - (defun c:pno ( / a c i l n p q s x ) (if (setq s (ssget "_X" '((0 . "INSERT") (8 . "NUMBERING")))) (progn (repeat (setq i (sslength s)) (setq i (1- i) a (entnext (ssname s i)) x (entget a) ) (while (and (= "ATTRIB" (cdr (assoc 0 x))) (not (and p n))) (cond ( (= "PORT_NUMBER" (cdr (assoc 2 x))) (setq p a) ) ( (= "SORT_ORDER" (cdr (assoc 2 x))) (setq n (atoi (cdr (assoc 1 x)))) ) ) (setq a (entnext a) x (entget a) ) ) (if (and p n) (setq l (cons p l) p nil q (cons n q) n nil ) ) ) (setq c 1) (foreach n (vl-sort-i q '<) (entmod (list (cons -1 (nth n l)) (cons 1 (padz (itoa c) 3)))) (setq c (1+ c)) ) ) ) (princ) ) (defun padz ( x n ) (if (< (strlen x) n) (padz (strcat "0" x) n) x) ) (princ) 1 Quote
Terry.T Posted May 17, 2021 Author Posted May 17, 2021 On 5/16/2021 at 1:24 PM, Lee Mac said: Another - (defun c:pno ( / a c i l n p q s x ) (if (setq s (ssget "_X" '((0 . "INSERT") (8 . "NUMBERING")))) (progn (repeat (setq i (sslength s)) (setq i (1- i) a (entnext (ssname s i)) x (entget a) ) (while (and (= "ATTRIB" (cdr (assoc 0 x))) (not (and p n))) (cond ( (= "PORT_NUMBER" (cdr (assoc 2 x))) (setq p a) ) ( (= "SORT_ORDER" (cdr (assoc 2 x))) (setq n (atoi (cdr (assoc 1 x)))) ) ) (setq a (entnext a) x (entget a) ) ) (if (and p n) (setq l (cons p l) p nil q (cons n q) n nil ) ) ) (setq c 1) (foreach n (vl-sort-i q '<) (entmod (list (cons -1 (nth n l)) (cons 1 (padz (itoa c) 3)))) (setq c (1+ c)) ) ) ) (princ) ) (defun padz ( x n ) (if (< (strlen x) n) (padz (strcat "0" x) n) x) ) (princ) Expand Amazing , that is what exactly i what. thank a lot. Quote
Terry.T Posted May 24, 2021 Author Posted May 24, 2021 On 5/16/2021 at 1:24 PM, Lee Mac said: Another - (defun c:pno ( / a c i l n p q s x ) ;-------------------NEW ADD----------------------------------- (princ "\nPlease pick a block to numbering: ") (setq a1 (car (entsel))) (setq d1 (entget a1)) (setq e (assoc 8 d1)) ;-------------------NEW ADD----------------------------------- ; (if (setq s (ssget "_X" '((0 . "INSERT") (8 . "NUMBERING")))) ; (if (setq s (ssget "_X" '((0 . "INSERT") , e))) ; (if (setq s (ssget "_X" '((0 . "INSERT") (e) ))) (if (setq s (ssget "_X" '((0 . "INSERT") e))) (progn (repeat (setq i (sslength s)) (setq i (1- i) a (entnext (ssname s i)) x (entget a) ) (while (and (= "ATTRIB" (cdr (assoc 0 x))) (not (and p n))) (cond ( (= "PORT_NUMBER" (cdr (assoc 2 x))) (setq p a) ) ( (= "SORT_ORDER" (cdr (assoc 2 x))) (setq n (atoi (cdr (assoc 1 x)))) ) ) (setq a (entnext a) x (entget a) ) ) (if (and p n) (setq l (cons p l) p nil q (cons n q) n nil ) ) ) (setq c 1) (foreach n (vl-sort-i q '<) (entmod (list (cons -1 (nth n l)) (cons 1 (padz (itoa c) 3)))) (setq c (1+ c)) ) ) ) (princ) ) (defun padz ( x n ) (if (< (strlen x) n) (padz (strcat "0" x) n) x) ) (princ) Expand May i learn more about "ssget" I am trying to let the computer know which layer i need and i set a value "E" to keep it, is it possible, if i change the coding like this? (not working) Quote
Lee Mac Posted May 24, 2021 Posted May 24, 2021 The issue is that the ssget filter list is quoted as a literal list, and therefore the symbol 'e' will not be evaluated as a variable to yield the value it has been assigned, but will instead remain as a symbol. To better understand this behaviour, and how to alter the expression to evaluate the variable, you may wish to read my tutorial on The Apostrophe and the Quote Function. 1 Quote
Terry.T Posted May 28, 2021 Author Posted May 28, 2021 On 5/24/2021 at 8:05 AM, Lee Mac said: The issue is that the ssget filter list is quoted as a literal list, and therefore the symbol 'e' will not be evaluated as a variable to yield the value it has been assigned, but will instead remain as a symbol. To better understand this behaviour, and how to alter the expression to evaluate the variable, you may wish to read my tutorial on The Apostrophe and the Quote Function. Expand Thanks a lot about this i have update the app and it is works (defun c:pno ( / a c i l n p q s x ) ;-------------------NEW ADD----------------------------------- (princ "\nPlease pick a block to numbering: ") (setq a1 (car (entsel))) (setq d1 (entget a1)) ;-------------------NEW ADD----------------------------------- ;-------------------change------------------------------------- ; (if (setq s (ssget "_X" '((0 . "INSERT") (8 . "NUMBERING")))) (if (setq s (ssget "_X" (list '(0 . "INSERT") (assoc 8 d1)))) ;-------------------change------------------------------------- (progn (repeat (setq i (sslength s)) (setq i (1- i) a (entnext (ssname s i)) x (entget a) ) (while (and (= "ATTRIB" (cdr (assoc 0 x))) (not (and p n))) (cond ( (= "PORT_NUMBER" (cdr (assoc 2 x))) (setq p a) ) ( (= "SORT_ORDER" (cdr (assoc 2 x))) (setq n (atoi (cdr (assoc 1 x)))) ) ) (setq a (entnext a) x (entget a) ) ) (if (and p n) (setq l (cons p l) p nil q (cons n q) n nil ) ) ) (setq c 1) (foreach n (vl-sort-i q '<) (entmod (list (cons -1 (nth n l)) (cons 1 (padz (itoa c) 3)))) (setq c (1+ c)) ) ) ) (princ) ) (defun padz ( x n ) (if (< (strlen x) n) (padz (strcat "0" x) n) x) ) (princ) Quote
BIGAL Posted May 28, 2021 Posted May 28, 2021 When in doubt I use all filters as cons this supports a variable by name and a value like "abc" or 1. Using '(( takes a little getting use to as per info by Lee. (setq ss (ssget "X" (list (cons 0 "LWPOLYLINE")(cons 8 mylayer) (cons 70 1) ))) (setq ss (ssget "X" (list (cons 0 "LWPOLYLINE")(cons 8 "Design") (cons 70 isClosed) ))) Quote
Rakesh H M Posted March 31 Posted March 31 (edited) Hi, I am a beginner in this, and I have a problem regarding sorting attributes. For example, I have multiple blocks in a single AutoCAD file, and each block contains 18 attributes. Some blocks are arranged in the format below, while others are not. I want all the blocks to be sorted in the same format. Could you please let me know how to sort all the blocks to ensure they display the attributes in the format listed below? Attributes format: UNIT# OPTSTYLE OPTSUFFIX SELFPRICE ZZPART ZZDETAIL ROOM FLOOR BUILDING PHASE KEYING ASSOCIATED HEIGHT DEPTH LENGTH ARCHNO LINE DEALER Drawing added for your reference Thank You! Drawing1.dwgFetching info... Edited March 31 by Rakesh H M Drawing added Quote
Saxlle Posted March 31 Posted March 31 (edited) Hi @Rakesh H M, You can do it on this way (without lisp): 1. Use command "BATTMAN" (picture 1); 2. Choose from "Block:" the desired name of the block (picture 1); 3. Use buttons "Move Up" and "Move down" to sort the attributes tags in desired order (picture 2); 4. After everything is done, use the "Apply" and then "OK" button to apply to every desired block (picture 2). 5. Output (picture 3). I didn't sort everything, just a few. Picture 1. Picture 2. Picture 3. Best regards. Edited March 31 by Saxlle Quote
Rakesh H M Posted April 2 Posted April 2 @Saxlle, I know individual update, i am looking for mass block updates. For example i have 1000 numbers of blocks i can't go each and update each blocks. Is there any option to update all the blocks at a time in these format? Quote
Saxlle Posted Friday at 09:37 AM Posted Friday at 09:37 AM Can you upload a drawing with all that blocks on which you want to reorder "TAGS"? Quote
BIGAL Posted Friday at 10:15 PM Posted Friday at 10:15 PM @Rakesh H M even if you have a 1000 blocks if they are one block name and you do the BEDIT and Battman then as shown above they should be updated, after Apply do Sync. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.