Attribute manipulation with ActiveX

Discussion in 'AutoCAD' started by Nick_Merchant, Jun 30, 2004.

  1. Is there any way (Using VLisp, NOT VBA) to search for an attribute containing a particular "TagString" value in a block reference without having to create a counter and cycle through each of the elements of the "safearray" extracted from the resulting "variant" that is returned from the ( vlax-invoke-method BlockObject "GetAttributes" ) command???

    In other words, I have a block with multiple attributes, each with different tag strings. I want to search for a certain tag string value, then get the value stored in that attribute.

    I can do what I want with a counter, but I'd like to know if there is any way to make ActiveX find that unique TagString FOR me without having to create the counter and increment it. The block I'm using has over 60 attributes in it, so parsing through the safearray's list of VLA Objects seems cumbersome to me. I was just hoping that there is an easier way to do this.

    TIA
     
    Nick_Merchant, Jun 30, 2004
    #1
  2. Nick_Merchant

    David Kozina Guest

    ooooooo, good question...
    I've been wondering about this myself.

    Awhile back, Vladimir Nesterovsky contributed the following code:

    ; Copyright 2002 by Vladimir Nesterovsky
    ; Free for use by any commercial entity with
    ; less then $100 million annual revenue.
    ; The Holy Graal of vla->lisp conversion? ;-)
    (defun vnLispValue (value)
    (cond
    ((= (type value) 'variant)
    (vnLispValue
    (variant-value value)
    )
    );_end case
    ((= (type value) 'safearray)
    (mapcar
    'vnLispValue
    (safearray-value value)
    )
    );_end case
    (T
    value
    );_end case
    );_end cond
    );_end defun


    Which can be used to return a list of vla objects when used with
    'GetAttributes...

    (setq TargetAttrib_objlst
    (vnLispValue
    (vlax-invoke-method
    _obj
    'GetAttributes
    )
    )
    )

    Might the above help to track things down easier?
    (I've been trying to work out a general find'in'da'list case for this
    myself, rather than looping through the entire mess)

    Any ideas?

    Best regards,
    David Kozina



    containing a particular "TagString" value in a block reference without
    having to create a counter and cycle through each of the elements of the
    "safearray" extracted from the resulting "variant" that is returned from the
    ( vlax-invoke-method BlockObject "GetAttributes" ) command???
    different tag strings. I want to search for a certain tag string value, then
    get the value stored in that attribute.
    way to make ActiveX find that unique TagString FOR me without having to
    create the counter and increment it. The block I'm using has over 60
    attributes in it, so parsing through the safearray's list of VLA Objects
    seems cumbersome to me. I was just hoping that there is an easier way to do
    this.
     
    David Kozina, Jun 30, 2004
    #2
  3. Nick_Merchant

    David Kozina Guest

    Untested... but might this work in conjunction with code I posted earlier?

    (setq TargetAttrib_obj
    (car
    (vl-member-if
    '(lambda (ele)
    (eq
    (vlax-get-property
    ele
    'TagString
    )
    <<YOURTAGSTRING>>
    )
    )
    TargetAttrib_objlst
    )
    )
    );_end setq
     
    David Kozina, Jun 30, 2004
    #3
  4. Nick_Merchant

    Jeff Mishler Guest

    Something like this? AFAIK, there is no way to just get the attribute
    similar to a collection ala (vla-item .........

    (setq blk_ent (car (entsel "\nSelect block with attributes: ")))
    (setq blk_vla (vlax-ename->vla-object blk_ent))
    (setq atts (vlax-invoke blk_vla "getattributes")); this returns a list, NOT
    a safearray
    (mapcar '(lambda(x)
    (if (= (vla-get-tagstring x) "TEST2")
    (vla-put-textstring x "Found it!")
    )
    )
    atts)

    Jeff

    containing a particular "TagString" value in a block reference without
    having to create a counter and cycle through each of the elements of the
    "safearray" extracted from the resulting "variant" that is returned from the
    ( vlax-invoke-method BlockObject "GetAttributes" ) command???
    different tag strings. I want to search for a certain tag string value, then
    get the value stored in that attribute.
    way to make ActiveX find that unique TagString FOR me without having to
    create the counter and increment it. The block I'm using has over 60
    attributes in it, so parsing through the safearray's list of VLA Objects
    seems cumbersome to me. I was just hoping that there is an easier way to do
    this.
     
    Jeff Mishler, Jun 30, 2004
    #4
  5. Nick_Merchant

    David Kozina Guest

    So, putting it all together...
    perhaps this would work? (Again, untested)

    hth,
    David Kozina

    ; Find Specific Attribute Reference using Tag String Identifier
    (defun djkGetAttRefTagObject
    (Block_obj ; Block object containing attributes
    Tag_str ; Attribute TagString
    /
    ;
    )
    ; begin
    (car
    (vl-member-if
    '(lambda (ele)
    (eq
    (vlax-get-property
    ele
    'TagString
    )
    Tag_str
    )
    )
    (vnLispValue
    (vlax-invoke-method
    Block_obj
    'GetAttributes
    )
    )
    )
    )
    ; end
    );_end defun
     
    David Kozina, Jun 30, 2004
    #5
  6. Thanks for the response, Jeff.

    When I implemented ( vlax-invoke-method ... ) I get a variant as the result. Does omission of the "-method" return a different type of VLA Object? If so, that's helpful to know.

    I will give a variation of your code a try.
     
    Nick_Merchant, Jun 30, 2004
    #6
  7. David,

    Thanks so much for your response. I will take a good look at your code and give it at try. I'll let you know if I'm sucessful with it.

    Thanks again!
     
    Nick_Merchant, Jun 30, 2004
    #7
  8. Nick_Merchant

    Jeff Mishler Guest

    Well, the (vlax-invoke obj "getattributes") returns a standard list of
    vla-objects. In this sample, my block had 4 attributes.

    (#<VLA-OBJECT IAcadAttributeReference 08bc6954> #<VLA-OBJECT
    IAcadAttributeReference 08bc6834> #<VLA-OBJECT IAcadAttributeReference
    08bc67c4> #<VLA-OBJECT IAcadAttributeReference 08bc2394>)

    Jeff

    result. Does omission of the "-method" return a different type of VLA
    Object? If so, that's helpful to know.
     
    Jeff Mishler, Jun 30, 2004
    #8
  9. Nick_Merchant

    David Kozina Guest

    I've been doing some minimal testing and it does seem to do what *I* need it
    to do.
    YMMV. :)

    Thanks for posing the question Nick, I needed to review that particular
    section of code which has been stinking up things around here for some time
    now.

    (FYI --- I was using an even more bogus method of finding a specific
    attribute tag by making the idiotic ASSumption that they would be the LAST
    tags in the retrieved list. <gagging> Desperation drives men to desperate
    acts, eh? I'm SO ashamed.)

    But I would like to know if there is a neater trick to doing this sort of
    thing.

    Best regards,
    David Kozina


    give it at try. I'll let you know if I'm sucessful with it.
     
    David Kozina, Jun 30, 2004
    #9
  10. Nick_Merchant

    Jürg Menzi Guest

    Hi Nick

    Visit my homepage -> Free Stuff and search for VxGetAtts/VxSetAtts...

    Cheers
     
    Jürg Menzi, Jun 30, 2004
    #10
  11. Thank you, Juerg!
     
    Nick_Merchant, Jun 30, 2004
    #11
  12. Live and learn, eh?

    Thanks for letting me "borrow your brain", Jeff. :)
     
    Nick_Merchant, Jun 30, 2004
    #12
  13. Nick_Merchant

    Jürg Menzi Guest

    Hi Nick

    Glad to help you...:cool:

    Cheers
     
    Jürg Menzi, Jul 1, 2004
    #13
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.