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

Looping through attributes & store values.

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mid-awe
528 Views, 5 Replies

Looping through attributes & store values.

Hi all,

 

I have an interesting challenge. I am tasked with updating old drawings. The only difficulty that I've run into with the old files are that the TitleBlocks are all done with all of the attributes are named "SPEC". There are 90 attributes. I'm really struggling with getting each attribute's value and then storing the value to a variable so that I can then put that value into a new TitleBlock. The old TB will be deleted to avoid future confusion in the file.

 

(To clearify, the old TitleBlock is in model space, while there are actually nine new TitleBlocks all in seperate paper space Layouts, and this program may have to run on hundreds of files.)

 

I only need help with getting the values from the Old TB. I need them in order of first to last or last to first (either way will work since I have the variable names in a list that can be reversed if necessary.) 

 

Can anyone help with a simple function to read through the block's attributes in order and store the attribute's value to a variable name in the seperate list (also in order)?

 

I've made a few attempt at foreach but I get lost along the way while trying to keep it simple and efficient. (I'm still working on it but some guidance would be greatly appreciated.)

 

Thank you in advance Smiley Happy

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: mid-awe

mid-awe,
perhaps something like

 

(setq sel (entsel "\nSelect a Block: "))
(setq attlst
(mapcar '(lambda (x) (vla-get-TextString x))
(vlax-invoke (vlax-ename->vla-object (car sel)) 'GetAttributes)
)
)

 hope that helps
Henrique

EESignature

Message 3 of 6
mid-awe
in reply to: hmsilva

Thank you. That really does help. I eliminated the need for entsel (user input) with:

 

ENTINFO (ssname (ssget "x" (list (cons 2 BLOCKNAME))) 0)

 

But, now I need to get the values stored.

 

You have got me going in the right direction. Thanks again.

Message 4 of 6
hmsilva
in reply to: mid-awe

You're welcome, mid-awe

 

"But, now I need to get the values stored."

 

the values are stored in "attlst" as a list, you can use its position in the list to fill the new TitleBlocks.

 

Henrique

EESignature

Message 5 of 6
mid-awe
in reply to: hmsilva

I added the foreach and it works great 🙂 thanks again.

Message 6 of 6
hmsilva
in reply to: mid-awe

You're welcome, mid-awe

glad you got a solution

 

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost