Author Topic: Sorting "nested" attributes by name  (Read 5407 times)

0 Members and 1 Guest are viewing this topic.

AcDbZombieEntity

  • Mosquito
  • Posts: 20
Sorting "nested" attributes by name
« on: July 10, 2013, 08:11:47 AM »
Hi,

i've got here many blocks with many attributes, a lot of them have the same attributes but sorted crazy unique in each block definition.

- Is there any method to "resort" them all with lisp, alphabetical order by name and not the promt or value?
- Is there an way to get battman working with command?

P.S. with out an lost of allready entered values  :evil:

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Sorting "nested" attributes by name
« Reply #1 on: July 10, 2013, 08:28:30 AM »
- Is there any method to "resort" them all with lisp, alphabetical order by name and not the promt or value?

e.g .

Code: [Select]
(setq l '("c" "e" "d" "a" "f" "b"))
(acad_strlsort l)

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Sorting "nested" attributes by name
« Reply #2 on: July 10, 2013, 08:51:34 AM »
Are you meaning tagname from attributdefinition you would like sort. Do you want rebuild a block with attributes.
Another way without lisp is, you take a copy of block, explode them and than use command attredef and you can by clicking on attdef byself choice direction which attdef should be sort.
It΄s a bit difficult to do that with lisp, you need a function which sort all tagnames from attdef and than you have to entmod them. I΄m not sure if it΄s the best way.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Sorting "nested" attributes by name
« Reply #3 on: July 10, 2013, 09:24:30 AM »
I don't think the BAttMan options are available to Lisp.

The "simplest" method would be for the lisp to recreate the block definition using the BLOCK command, but select the attdef's in the correct order:
  • Insert a temporary block
  • Explode it
  • Select previous
  • Remove all attdef objects from that selection set and add them to a list
  • Sort the list on the attributes' tag names
  • Add them back in order using ssadd
  • Recreate the block, overwriting the old definition
  • Run attsync to update all the existing block references to the same attribute order
  • Erase the temporary block
Repeat the process for each block definition.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Sorting "nested" attributes by name
« Reply #4 on: July 10, 2013, 09:38:46 AM »
The "simplest" method would be for the lisp to recreate the block definition using the BLOCK command, but select the attdef's in the correct order

However, this method would not work for attributed dynamic blocks.



Try the following:
Code - Auto/Visual Lisp: [Select]
  1. ;; Sort Tags  -  Lee Mac
  2. (defun c:sorttags ( / cmd lst )
  3.         (if
  4.             (and
  5.                 (= :vlax-false (vla-get-isxref blk))
  6.                 (= :vlax-false (vla-get-islayout blk))
  7.             )
  8.             (progn
  9.                 (vlax-for obj blk
  10.                     (if (= "AcDbAttributeDefinition" (vla-get-objectname obj))
  11.                         (setq lst (cons obj lst))
  12.                     )
  13.                 )
  14.                 (foreach att (vl-sort lst '(lambda ( a b ) (< (vla-get-tagstring a) (vla-get-tagstring b))))
  15.                     (vla-copy   att)
  16.                     (vla-delete att)
  17.                 )
  18.                 (setq lst nil)
  19.             )
  20.         )
  21.     )
  22.     (setq cmd (getvar 'cmdecho))
  23.     (setvar 'cmdecho 0)
  24.     (vl-cmdf "_.attsync" "_N" "*")
  25.     (setvar 'cmdecho cmd)
  26.     (princ)
  27. )

AcDbZombieEntity

  • Mosquito
  • Posts: 20
Re: Sorting "nested" attributes by name
« Reply #5 on: July 10, 2013, 10:09:57 AM »
Awesome Lee, thanks a lot. learned something new with

Code: [Select]
               (foreach att (vl-sort lst '(lambda ( a b ) (< (vla-get-tagstring a) (vla-get-tagstring b))))
                   (vla-copy   att)
                   (vla-delete att)
               )


Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Sorting "nested" attributes by name
« Reply #6 on: July 10, 2013, 10:16:03 AM »
You're very welcome.

Great username BTW  :-P

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Sorting "nested" attributes by name
« Reply #7 on: July 10, 2013, 01:45:16 PM »
Welcome to the swamp brother zombie!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Sorting "nested" attributes by name
« Reply #8 on: July 11, 2013, 04:44:30 PM »
Awesome Lee, thanks a lot. learned something new with

Code: [Select]
               (foreach att (vl-sort lst '(lambda ( a b ) (< (vla-get-tagstring a) (vla-get-tagstring b))))
                   (vla-copy   att)
                   (vla-delete att)
               )

 :kewl:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Sorting "nested" attributes by name
« Reply #9 on: July 11, 2013, 07:43:00 PM »
Awesome Lee, thanks a lot. learned something new with

Code: [Select]
               (foreach att (vl-sort lst '(lambda ( a b ) (< (vla-get-tagstring a) (vla-get-tagstring b))))
                   (vla-copy   att)
                   (vla-delete att)
               )

 :kewl:

 :-)