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.
Solved! Go to Solution.
Solved by mid-awe. Go to Solution.
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)
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. ?
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.
@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?