satishrajdev Posted March 20, 2013 Posted March 20, 2013 hi all, i have a attribute block which has two tag Tag 1 = X Tag 2 = Y i am using following code for getting attribute values, but this code is only giving 1 attribute value:- (setq obj (vlax-ename->vla-object theEntity)) (foreach a (vlax-invoke obj 'getattributes) (setq tag_val (vlax-get a 'TagString)) (setq att_val (vlax-get a 'TextString)) can anybody help me to edit this code to get multiple value of a single attribute block I refer my drawing file for more info,in drawing file X=10 & y=3 i want to get that attribute value & finally add it i.e. 10+3=13 Thanks in advance test.dwg Quote
pBe Posted March 20, 2013 Posted March 20, 2013 (setq sum 0 obj (vlax-ename->vla-object theEntity)) (foreach a (vlax-invoke obj 'getattributes) (setq sum (+ (atoi (vlax-get a 'TextString)) sum)) ) or (apply '+ (mapcar '(lambda (a) (atoi (vlax-get a 'TextString))) (vlax-invoke obj 'getattributes))) Quote
satishrajdev Posted March 20, 2013 Author Posted March 20, 2013 thanks a lot pBE for your the help For additional info i want to know that if i want to divide Y value by 10 i.e. 10 + (3/10) = 10.3 For this how the code will change????? Quote
pBe Posted March 20, 2013 Posted March 20, 2013 thanks a lot pBE for your the help For additional info i want to know that if i want to divide Y value by 10 i.e. 10 + (3/10) = 10.3 For this how the code will change????? (Defun c:demo () (setq theEntity (Car (entsel))) (setq obj (vlax-ename->vla-object theEntity)) (setq data (mapcar '(lambda (a) (list (vlax-get a 'TagString) (atoi (vlax-get a 'TextString)))) (vlax-invoke obj 'getattributes) ) ) (+ (cadr (assoc "X" data)) (/ (cadr (assoc "Y" data)) 10.0)) ) Quote
satishrajdev Posted March 20, 2013 Author Posted March 20, 2013 Excellent that is what i wanted Big thankx to you.... pBE:) Quote
satishrajdev Posted March 22, 2013 Author Posted March 22, 2013 again came out with one more query, I have modified above lisp to:- (Defun c:demo () (if (and (setq dta (ssget '((0 . "INSERT") (66 . 1)))) ) (repeat (setq i (sslength dta)) (setq theEntity (ssname dta (setq i (1- i)))) (setq obj (vlax-ename->vla-object theEntity)) (setq data (mapcar '(lambda (a) (list (vlax-get a 'TagString) (atoi (vlax-get a 'TextString)))) (vlax-invoke obj 'getattributes) ) ) (setq att (+ (cadr (assoc "X" data)) (/ (cadr (assoc "Y" data)) 10.0))) (princ att) ))) but when i am selecting a attribute it is providing attribute value 2 times e.g. if i m selecting 10.3(attribute block) it is returning 10.310.3 plz refer above drawing Thanks a lot Quote
satishrajdev Posted March 22, 2013 Author Posted March 22, 2013 Now it is coming to know that even small code can irritate you, i wasn't aware of it... My Coding knowledge is getting increase day by day All thanks to you guys, You really made it simple Quote
pBe Posted March 22, 2013 Posted March 22, 2013 Now it is coming to know that even small code can irritate you, i wasn't aware of it... My Coding knowledge is getting increase day by day You'll get there satishrajdev, practice... practice.... practice. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.