About assoc

About assoc

saitoib
Advocate Advocate
967 Views
7 Replies
Message 1 of 8

About assoc

saitoib
Advocate
Advocate
Hi all.

In the following code, the ent in line A is
ent = (-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1)))

I get an error on line B. What is wrong?
What is wrong?

Thank you.

 

(defun _sort_panel ( ss / nn i id ent lay panel_list)
  (setq nn (sslength ss))
  (setq i 0)
  (repeat nn
    (setq id (ssname ss i))
    (setq ent (assoc -3 (entget id '("XData")))) ;A
    (setq ent (assoc 1070 ent)) ;B

  )
)

 

Saitoib
0 Likes
Accepted solutions (1)
968 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

(cdr ent) missing?

0 Likes
Message 3 of 8

cadffm
Consultant
Consultant
Accepted solution

[Typos edited - the third time :-/]

 

Hi,

 

after line a the value is ent = (-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1)))

 

same list, another formatting:

( -3

  ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1))

)

 

So, you have 2 items inside and the list isn't a valid association list (a list with nested listes inside only)

 

Command: (cdr (-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1))))

(("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1)))

Now, there are only ONE list inside, but the assoc-element is "xdata" - what you don't want.

 

Command: (cadr '(-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1))))
 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1))

Not only lists inside

 

Command:: (cdadr '(-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1))))
((1040 . 90.0) (1040 . 4.1) (1070 . 1))

Now, only lists inside (valid association list) and you can use ASSOC!

 

Command:: (assoc 1070 (cdadr '(-3 ("XData" (1040 . 90.0) (1040 . 4.1) (1070 . 1)))))
(1070 . 1)

Sebastian

Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Removed.


Message 5 of 8

cadffm
Consultant
Consultant

thx you, but I was faster 🤣

I had to edit my edit <crazy> 😐

 

Sebastian

0 Likes
Message 6 of 8

saitoib
Advocate
Advocate

@cadffm 

Thank you very much.
I understand now.

Saitoib
0 Likes
Message 7 of 8

diagodose2009
Collaborator
Collaborator
Please you upload a Sample.Dwg with entities + Xdata..
Can you share a your Drawing.dwg?
0 Likes
Message 8 of 8

saitoib
Advocate
Advocate

Would this be of any help to you?

 

Saitoib
0 Likes