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.
Solved! Go to Solution.
Why not to use ATTOUT ??
Where is the ?
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. ?
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.
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.