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

LISP for Re-ordering block Attributes

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
udaymach
3608 Views, 8 Replies

LISP for Re-ordering block Attributes

Hi,I am trying to re-order the attributes in the AutoCAD blocks. Everytime i edit a existing block or try to create a new block (part copied from other blocks and renaming it as a new block) the order in which the attributes are displayed is shuffled completely.

This happens because the reference created for each of the attributes gets changed once i try to edit a block.

I have tried options like 'BATTMAN' 'ATTSYNC' 'BATTORDER' but the problem is i have a bunch of blocks each with 96 -150 pins in them (Each pins has an attribute reference). So it is really pain using all the above mentioned commands to arrange all the attributes in Ascending order.

Any ideas on how to resolve this using a LISP program ?! Is there a way to re-order them using the tag names ?!

For Instance, please check for the drawing attached.

I need to have this block's attributes re-ordered from Pin1-Pin90 in an ascending order.

8 REPLIES 8
Message 2 of 9
braudpat
in reply to: udaymach

 

Hello

 

When you create the Block you have to select all graphic and text entities (NO ATTDEF) and then each ATTDEF one by one in the order you need !

 

OK you have 90 clicks but it's one time !

 

Of course if you have a lot of bad blocks to re-order, you need a Lisp/VLisp routine ...

 

Bye, Pat

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 3 of 9
pbejse
in reply to: udaymach


@udaymach wrote:


...... This happens because the reference created for each of the attributes gets changed once i try to edit a block....


 

Makes  me wonder what kind of "EDIT" do you do on the block that it messes up the order, are you introducing new attributes by any chance?

 

Message 4 of 9
3wood
in reply to: udaymach

I saw your post a few days ago here: http://forums.autodesk.com/t5/AutoCAD-2010-2011-2012/Re-orderin-g-block-Attributes/m-p/4804883#M1028...

I thought you had already got the solution.

 

You can try SORTTAG.vlx to sort block attribute tag names in an ascending order. You need got a free registration to utilize it in full function.

After sorting, you can then use ATTSYNCALL to update/synchronize attribute tags in all block inserts.

I have tried your sample drawing and here is the sorted result. I also put a test block in it which only contains 10 attributes so you can test the trial version on it.

Message 5 of 9
pbejse
in reply to: udaymach


@udaymach wrote:


I need to have this block's attributes re-ordered from Pin1-Pin90 in an ascending order.


 

(defun c:oAtt (/ num blk bn all nat blkn)
;;;	pBeFeb2014	;;;
  (setq num (lambda (str)
	    (vl-list->string
	      (vl-remove-if-not '(lambda (s)
				   (<=  48 s 57))
		(vl-string->list str)))))

(if (setq blk (ssget "_:S" '((0 . "INSERT")(66 . 1))))
    (progn
      (vlax-for	itm (setq blkn (vla-item
		      (vla-get-blocks
			(vla-get-ActiveDocument (vlax-get-acad-object))
		      )
		      (setq bn (cdr (assoc 2 (entget (ssname blk 0)))))
		    )
			  )
	(If (eq (vla-get-ObjectName itm) "AcDbAttributeDefinition")
	  (progn
	    (setq all (cons (mapcar '(lambda (x)
				     (vlax-get-property itm x)
				   )
				  '("Tagstring"
				     "TextString"
				     "Height"
				     "Mode"
				     "PromptString"
				     "StyleName"
				     "Layer"
				     "InsertionPoint"
				    )
			  ) all))
	(vla-delete itm)
	    
	    )
	  ))
      

      	(setq all (vl-sort all '(lambda (o p) (< (atoi (num (car o)))
					      (atoi (num (car p)))))))
      (mapcar
    (function
      (lambda (lst)
	(setq nat (vla-AddAttribute
		    blkn
		    (caddr lst)
		    (nth 3 lst)
		    (nth 4 lst)
		    (last lst)
		    (car lst)
		    (cadr lst)
		  )
	)
	(vlax-put nat 'StyleName (nth 5 lst))
	(vlax-put nat 'Layer (nth 6 lst))
      )
    )
    all
  )
      (command "_.attsync" "Name" bn)
      )
      
 )(princ)
)
(vl-load-com)

  


 HTH

Message 6 of 9
hmsilva
in reply to: pbejse

Nicely done, pBe 🙂

 

Cheers

Henrique

EESignature

Message 7 of 9
udaymach
in reply to: 3wood

Thanks 3wood. Your routine works perfectly fine.
Message 8 of 9
udaymach
in reply to: pbejse

Thanks pBe. It works great !
Message 9 of 9
mtaras
in reply to: udaymach

Hello, I'd like to ask two questions:

1. can attribute width factor be added? otherwise it is changed by lisp to 1.

2. if it is possible to modify the lisp to sort tags in multiple blocks (different blocks with same attribute tags in bad order) and set order of a pick-selected or Named block, or at least the order written in a string in the lisp? In other words, non-alphanumeric order. I guess that would be a totally different program from one in first post.

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

Post to forums  

Autodesk Design & Make Report

”Boost