delight-shadow Posted April 18, 2013 Posted April 18, 2013 I have a dynamic block which have some attributes and I'd like to get the contents of the attributes. For example, if the block has 2 attributes, attr1_size and attr2_color, and the value of attr1_size is small , and the value of attr2_color is red, what I need is a list , (attr1_size small)(attr2_color red) I thought the (vlax-invoke (vlax-ename->vla-object block_name) 'GetAttributes) will do this, but the result was like this. (# #IAcadAttributeReference 0eef3e54>) Is there any way to get the attribute value from the random sequence? Or, any other code to get the value? What I finally want to do is clicking a block and automatically insert some new figures according to the value of an attribute. Thank you! Quote
Tharwat Posted April 18, 2013 Posted April 18, 2013 e.g. (if (setq s (ssget "_+.:S:L" '((0 . "INSERT") (66 . 1)))) (foreach att (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'GetAttributes ) (setq l (cons (list (vla-get-tagstring att) (vla-get-textstring att)) l ) ) ) ) Quote
Lee Mac Posted April 18, 2013 Posted April 18, 2013 These functions may help: Attribute Functions Quote
delight-shadow Posted April 19, 2013 Author Posted April 19, 2013 Thanks, Tharwat ! I added the "vla-get-tagstring" and "vla-get-textstring" in my code! Now the code is working excellent:D Quote
delight-shadow Posted April 19, 2013 Author Posted April 19, 2013 Thanks, Lee, Your website is one of my best textbook, up until now and forever ! I'm trying to substitute the attributes now, for another code. Quote
BIGAL Posted April 19, 2013 Posted April 19, 2013 You can test the value via an If of the tagstring so only return certain attribute values rather than all not sure if this is where your headed. (setq ss2 (ssget "x" '((0 . "INSERT") (2 . "REVTABLE")))) (setq inc (sslength ss2)) (repeat inc (foreach att (vlax-invoke (vlax-ename->vla-object (ssname ss2 (setq inc (1- inc)))) 'getattributes) (if (= oldtag1 (strcase (vla-get-tagstring att))) (vla-put-textstring att newstr1) ) (if (= oldtag2 (strcase (vla-get-tagstring att))) (vla-put-textstring att newstr2) ) (if (= oldtag3 (strcase (vla-get-tagstring att))) (vla-put-textstring att newstr3) ) ) ) ) Quote
Tharwat Posted April 19, 2013 Posted April 19, 2013 Thanks, Tharwat ! I added the "vla-get-tagstring" and "vla-get-textstring" in my code!Now the code is working excellent:D You're welcome . Quote
delight-shadow Posted April 22, 2013 Author Posted April 22, 2013 Thanks, BIGAL ! Now the "vla-put-textstring" is working excellently in my code !! Quote
VVA Posted April 22, 2013 Posted April 22, 2013 In the description of the block may also be present constants attributes (defun get-all-atts (obj) (if (= (type obj) 'ENAME) (setq obj (vlax-ename->vla-object obj))) (if (and obj (vlax-property-available-p obj 'Hasattributes) (eq :vlax-true (vla-get-HasAttributes obj)) ) (vl-catch-all-apply (function (lambda () (mapcar (function (lambda (x) (cons (vla-get-TagString x) (vla-get-TextString x) ) ) ) (append (vlax-invoke obj 'Getattributes) (vlax-invoke obj 'Getconstantattributes) ) ) ) ) ) ) ) Quote
thajmul Posted January 9, 2023 Posted January 9, 2023 On 4/18/2013 at 12:49 PM, Tharwat said: e.g. (if (setq s (ssget "_+.:S:L" '((0 . "INSERT") (66 . 1)))) (foreach att (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'GetAttributes ) (setq l (cons (list (vla-get-tagstring att) (vla-get-textstring att)) l ) ) ) ) hi tharwat, can u explain this("_+.:s:l")? thanks advance Quote
thajmul Posted January 9, 2023 Posted January 9, 2023 On 4/18/2013 at 4:44 PM, Lee Mac said: These functions may help: Attribute Functions hi lee, i have been following your website since i started learning autolisp.its really helping me. (setq sel_ename (car (entsel))) (setq c_vlaobject (vlax-ename->vla-object sel_ename)) (setq obj (vlax-invoke c_vlaobject 'getattributes)) (setq string (vla-get-tagstring obj)) i sure this is not correct.why i did not get tag string? can u explain? thanks advance Quote
dexus Posted January 9, 2023 Posted January 9, 2023 3 hours ago, thajmul said: hi tharwat, can u explain this("_+.:s:l")? thanks advance Lee can explain this very well, he did here: http://www.lee-mac.com/ssget.html Quote
dexus Posted January 9, 2023 Posted January 9, 2023 (vlax-invoke c_vlaobject 'getattributes) 2 hours ago, thajmul said: hi lee, i have been following your website since i started learning autolisp.its really helping me. (setq sel_ename (car (entsel))) (setq c_vlaobject (vlax-ename->vla-object sel_ename)) (setq obj (vlax-invoke c_vlaobject 'getattributes)) (setq string (vla-get-tagstring obj)) i sure this is not correct.why i did not get tag string? can u explain? thanks advance (vlax-invoke c_vlaobject 'getattributes) returns a list of objects. So you will have to loop though them to find the tagstings. 1 Quote
thajmul Posted January 9, 2023 Posted January 9, 2023 26 minutes ago, dexus said: (vlax-invoke c_vlaobject 'getattributes) (vlax-invoke c_vlaobject 'getattributes) returns a list of objects. So you will have to loop though them to find the tagstings. thanks dexus Quote
Lee Mac Posted January 9, 2023 Posted January 9, 2023 8 hours ago, thajmul said: hi lee, i have been following your website since i started learning autolisp.its really helping me. (setq sel_ename (car (entsel))) (setq c_vlaobject (vlax-ename->vla-object sel_ename)) (setq obj (vlax-invoke c_vlaobject 'getattributes)) (setq string (vla-get-tagstring obj)) i sure this is not correct.why i did not get tag string? can u explain? thanks advance I'm pleased that you find my website useful in your studies. As dexus has subsequently pointed out, the getattributes method will return an array (or list when using vlax-invoke) of attribute reference objects; you'll need to obtain the tagstring property for an object in the list returned. It may be clearer to evaluate each expression through the Visual LISP IDE console, so that you can see the value returned by each expression. 1 Quote
thajmul Posted January 10, 2023 Posted January 10, 2023 17 hours ago, Lee Mac said: I'm pleased that you find my website useful in your studies. As dexus has subsequently pointed out, the getattributes method will return an array (or list when using vlax-invoke) of attribute reference objects; you'll need to obtain the tagstring property for an object in the list returned. It may be clearer to evaluate each expression through the Visual LISP IDE console, so that you can see the value returned by each expression. Thanks for the your kind reply. 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.