Jump to content

How to get multiple attribute values


Recommended Posts

Posted

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

Posted

(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)))

Posted

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?????

Posted
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))
)

Posted

Excellent

 

that is what i wanted

 

Big thankx to you.... pBE:)

Posted

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

Posted

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

Posted
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. ;)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...