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

get attribute values from multiple blocks with same name?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
mid-awe
1203 Views, 10 Replies

get attribute values from multiple blocks with same name?

Hi all,

 

I have another block attribute question.

 

This time I'm wrestling with getting the values from multiple blocks. The blocks all have the same name but at least the attributes have names this time. Each block have exactly 4 attributes, like: att1 (a number representing chronological order), att2 (some data), att3 (the actual date as a string of when the data was added), att4 (some more data)

 

I need to get and store the attribute's values. I was hoping to make a selectionset of the blocks and step through using the chronological order number.

 

At this point I have tried several combinations of foreach and ssget "x" (list (cons 2 MYBLOCK)), but I keep getting errors that I'm sure are telling me that I'm not passing the correct information to the function for iterating through. I'm banging my head.

 


(DEFUN c:GFOR (/ ATTLST REVBLK CNT CNT1 BLK RBLK ATTVAL ATT REV#)
(SETQ ATTLST (LIST "R#" "INIT" "DATE" "DESC") REVBLK (ssget "x" (list (cons 0 "INSERT") (cons 2 "REVISION"))) CNT 0 CNT1 0 )
(vlax-ldata-put "dict" "RevTotal" (BLKCNT "REVISIONS")) (FOREACH BLK REVBLK (SETQ RBLK (ssname BLK CNT1)) (setq ATTVAL (mapcar '(lambda (x) (vla-get-TextString x)) (vlax-invoke (vlax-ename->vla-object RBLK) 'GetAttributes))) (foreach ATT ATTLST (SETQ REV# (STRCAT "REVISION" (1+ CNT)))
(vlax-ldata-put "dict" REV# (member ATTVAL)) (setq CNT (1+ CNT)) ) (SETQ CNT1 (1+ CNT1)) ) (PRINC) )

 

Please help, any advice is greatly appreciated.

 

Thank you.

10 REPLIES 10
Message 2 of 11
devitg
in reply to: mid-awe

Why not to use ATTOUT ??

 

Where is the ? 

 

BLKCNT 

 

Defun

 

You can not Strcat a string with a number 

 

(SETQ REV# (STRCAT "REVISION" (1+ CNT)))

 

 

 

(vlax-ldata-put "dict" REV# (member ATTVAL))

 

 

Member shall get 2 arguments 

 

 

 

(member expr lst)
Message 3 of 11
mid-awe
in reply to: mid-awe

Attout won't help me move the values from the old block and into the new block.

Boy, I really must have tired when I made that mistake with member; I know that šŸ™‚

Thank you, I'll look over that mess again in the morning.
Message 4 of 11
pbejse
in reply to: mid-awe

You dont use foreach for PICKSET, its either repeat or while.

 

Whats the deal with  move the values from the old block and into the new block. ?

 

Message 5 of 11
devitg
in reply to: mid-awe

Mid Awe , you can change it in XLS and enter with attin 

Message 6 of 11
mid-awe
in reply to: pbejse

The company I'm with now has decided to change their drawing template. All new drawings USE papers pace. Before now all drawings used only model space. So any old projects that get revisions also get conversion. I'm tasked with collecting and converting all revision notes and moving to values to the new revision blocks in paper space. "Sounds fun right?" This is actually the final step for full conversion to the new standard format.

I'll change the loop to while or repeat, since it would make sense that is the issue with error listp I get.

Thank you.
Message 7 of 11
mid-awe
in reply to: devitg


@devitg wrote:

Where is the ? 

 

BLKCNT 


(DEFUN BLKCNT (BLKNM / N SS)
  (IF (TBLSEARCH "BLOCK" BLKNM)
    (setq SS (ssget "X" (list (cons 0 "INSERT") (cons 2 BLKNM)))
	  N  (sslength SS)
    )
  )
  N
)

Just in case you really need it.

Message 8 of 11
mid-awe
in reply to: mid-awe

Ok, Thank you all for your help in nudging me the right direction. I got it worked out and because I believe in sharing (that's how I learn) below is the working code still utilizing vlax-ldata.

(DEFUN c:GFOR (/ SS IDX ENT ATTVAL)
  (if (setq SS (ssget "x" (list (cons 0 "INSERT") (cons 2 "REVISION"))))
    (progn
      (setq IDX (sslength SS))
      (vlax-ldata-put "Revision" "total" IDX)
      (repeat IDX
	(setq IDX (1- IDX)
	      ENT (ssname SS IDX)
	      ATTVAL (mapcar '(lambda (x) (vla-get-TextString x)) (vlax-invoke (vlax-ename->vla-object ENT) 'GetAttributes))
	)
	(vlax-ldata-put (strcat "Revision" (car ATTVAL)) "WHO" (cadr ATTVAL))
	(vlax-ldata-put (strcat "Revision" (car ATTVAL)) "WHEN" (caddr ATTVAL))
	(vlax-ldata-put (strcat "Revision" (car ATTVAL)) "WHAT" (cadddr ATTVAL))
      )
    )
  )
  (princ)
)

 Again thank you all.

Message 9 of 11
devitg
in reply to: mid-awe

Too late 

Message 10 of 11
mid-awe
in reply to: devitg

Smiley Happy

Message 11 of 11
pbejse
in reply to: mid-awe


@mid-awe wrote:
The company I'm with now has decided to change their drawing template. All new drawings USE papers pace. Before now all drawings used only model space. So any old projects that get revisions also get conversion. I'm tasked with collecting and converting all revision notes and moving to values to the new revision blocks in paper space. "Sounds fun right?" This is actually the final step for full conversion to the new standard format.

I'll change the loop to while or repeat, since it would make sense that is the issue with error listp I get.

Thank you.

Besides collecting values for dictionary you need to assign the values to a new block? 

 

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

Post to forums  

Autodesk Design & Make Report

ā€Boost