Export txt of blocks sort by attributes

Export txt of blocks sort by attributes

me.deriaz
Participant Participant
480 Views
7 Replies
Message 1 of 8

Export txt of blocks sort by attributes

me.deriaz
Participant
Participant

Good morning,

I am using autocad 2023 window 10.

I want to export a coordinates/attributes file sorted according to 3 block attributes in a txt file The export is operational but I can't find any idea how to configure my list to sort it.

Attached is my code and my exporter blocks.

Sorry for my English I speak French

Thank you and good day.

0 Likes
481 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@me.deriaz wrote:

I want to export a coordinates/attributes file sorted according to 3 block attributes in a txt file T

 Hi @me.deriaz 

Welcome to the forum, where is the file containing the data?

 

EDIT: Hang on, is the first prompt for saving the data? can you show us the resulting txt file after the program successfully export the data?

 

 

0 Likes
Message 3 of 8

me.deriaz
Participant
Participant

I will send you the result file. I changed the extension to be able to reach him.

0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

That is 12 values, I have sorted on up to 5. It is possible to do more . How many levels do you need  ? I suggest 4.

0 Likes
Message 5 of 8

me.deriaz
Participant
Participant

I need 3 values only.
Attribute 1: NO_COMMUNE
Attribute 2: PLAN
Attribute 3: NUMERO
THANKS

0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor

Try this

 

; By Gile
(defun compare-elements (a b sortspec)
  (
   (lambda (x y test)
   (if (and (equal x y ) (cdr sortspec))
    (compare-elements a b (cdr sortspec))
    (apply test (list x y))
   )
   )
    (nth (cdar sortspec) a)
    (nth (cdar sortspec) b)
    (caar sortspec)
  )
)
(defun complex-sort (alst sortspec)
  (vl-sort alst
  '(lambda (a b)
  (compare-elements a b sortspec)
  )
  )
)
(defun comparelems (  / )
(if (and
(= (nth 0 ans)(nth 0 ans2))
(= (nth 1 ans)(nth 1 ans2))
(= (nth 2 ans)(nth 2 ans2))
)
(setq tot (+ tot 1))
)
)

(setq lst (complex-sort lst '((< . 0) (< . 1) (< . 2))))
0 Likes
Message 7 of 8

me.deriaz
Participant
Participant
Good morning,
Sorry but I don't understand this code.
It seems to me that it sorts by coordinates.
I want to sort by attributes.
Could you add comments to the code?
Thank you so much.
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

The lst is just that a List of all the block attributes (("a" "B" "C" "d")("a" "B" "C" "d")("a" "B" "C" "d")("a" "B" "C" "d")........)

 

So you need to read the Block attributes into a list then add to the master list.

 

SeaHaven_0-1702948593876.png

 

In the image the value Block is the same name for 3 objects but the B value is different, 127, 128, 134 ie the sort control.

0 Likes