Visual LISP, AutoLISP and General Customization

Reply
Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 1 of 11 (396 Views)
Accepted Solution

get attribute values from multiple blocks with same name?

396 Views, 10 Replies
03-21-2013 04:03 PM

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.

Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 2 of 11 (379 Views)

Re: get attribute values from multiple blocks with same name?

03-21-2013 07:27 PM 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)
Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 3 of 11 (371 Views)

Re: get attribute values from multiple blocks with same name?

03-21-2013 10:03 PM 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 :smileyhappy:

Thank you, I'll look over that mess again in the morning.
*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 4 of 11 (362 Views)

Re: get attribute values from multiple blocks with same name?

03-21-2013 11:04 PM 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. ?

 

Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 5 of 11 (356 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 02:20 AM in reply to: mid-awe

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

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 6 of 11 (344 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 06:19 AM 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.
Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 7 of 11 (333 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 11:21 AM 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.

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 8 of 11 (329 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 11:34 AM 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.

Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 9 of 11 (326 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 11:39 AM in reply to: mid-awe

Too late 

Mentor
mid-awe
Posts: 1,198
Registered: ‎12-08-2004
Message 10 of 11 (315 Views)

Re: get attribute values from multiple blocks with same name?

03-22-2013 04:49 PM in reply to: devitg

:smileyhappy:

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community