Jump to content

Recommended Posts

Posted

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,

Posted
  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

Posted

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.

 

Posted (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 by mhupp
  • Like 1
Posted

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)

 

  • Like 1
Posted
  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.

 

Posted
  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)

Posted

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.

  • Like 1
Posted
  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)

 

Posted

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) )))

 

  • 3 years later...
Posted (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 by Rakesh H M
Drawing added
Posted (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.

image.thumb.png.c445e87d695f1b53edd56b1c2c536510.png

 

Picture 2.

image.thumb.png.89d51417602d5c1afdfe78b0104d01a5.png

 

Picture 3.

image.thumb.png.216745a2bec3f47f85c2b4864c297fc8.png

 

Best regards.

Edited by Saxlle
Posted

@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? 

Posted

Can you upload a drawing with all that blocks on which you want to reorder "TAGS"?

Posted

@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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...