Jump to content

How to get the block attribute as a list ? (what is the string by vlax-invoke ?)


delight-shadow

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Thanks, Tharwat ! I added the "vla-get-tagstring" and "vla-get-textstring" in my code!

Now the code is working excellent:D

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 9 years later...
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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