block definition attribute tagstring

Discussion in 'AutoCAD' started by mblewis, Nov 22, 2004.

  1. mblewis

    mblewis Guest

    need to change the tagstring for Block Definition attribute(s). how do i get the tagstring?

    have successfully used .GetAttributes, attribute array, & attribute array looping to access Block Reference tagstring & revised it.

    now i want to revise Block Definition tagstring & getting to that tagstring is eluding me.

    thanx for help.
    marklewis
     
    mblewis, Nov 22, 2004
    #1
  2. You would iterate thru the Block object's items, looking for Attribute
    objects.

    --
    R. Robert Bell


    need to change the tagstring for Block Definition attribute(s). how do i get
    the tagstring?

    have successfully used .GetAttributes, attribute array, & attribute array
    looping to access Block Reference tagstring & revised it.

    now i want to revise Block Definition tagstring & getting to that tagstring
    is eluding me.

    thanx for help.
    marklewis
     
    R. Robert Bell, Nov 22, 2004
    #2
  3. mblewis

    mblewis Guest

    OK. makes sense.
    can iterate thru block definitions & locate blockdef i need.

    now my next stupid question:
    now how do i get the [24] attribute items into an array to iterate them?

    that's the trick i'm looking to solve.

    marklewis
     
    mblewis, Nov 23, 2004
    #3
  4. You don't.

    Dim anObject As AcadEntity
    For Each anObject in myBlockObject
    If TypeOf anObject Is AcadAttribute Then
    ...
    End If
    Next anObject

    (typed w/o test)

    --
    R. Robert Bell


    OK. makes sense.
    can iterate thru block definitions & locate blockdef i need.

    now my next stupid question:
    now how do i get the [24] attribute items into an array to iterate them?

    that's the trick i'm looking to solve.

    marklewis
     
    R. Robert Bell, Nov 23, 2004
    #4
  5. mblewis

    MP Guest

    It's not a stupid question, but you may want to re-read Robert's answer
    again.
    That's exactly what he told you how to do.
    You don't need them in an array to modify them, you will get each in turn
    when you...
    <quote from roberts' answer>
    "You would iterate thru the Block object's items, looking for Attribute
    objects."
    <end quote>

    ps.
    you don't need to iterate through the block collection to get your block,
    just use the item method
    Dim oMyBlock as acadblock
    ''error trap here incase block doesn't exist
    Set oMyBlock = ThisDrawing.Blocks.Item("MyBlockName")
    Dim oEnt as AcadEntity
    for each oEnt in oMyBlock
    If TypeOf oEnt Is AcadAttribute then
    oEnt.TagString = "MyNewTag"
    end if
    Next
    etc

    hth
    Mark Propst
     
    MP, Nov 23, 2004
    #5
  6. mblewis

    mblewis Guest

    Mark:
    thank you, and Robert, for very good answers. it's your example that broke thru my frustration of being unable to access that attribute. everything i'd tried got REJECTED.

    bad vibes, bad vibes.

    thankyou, again
    marklewis
     
    mblewis, Nov 24, 2004
    #6
  7. mblewis

    mblewis Guest

    finally, i think, understand your code example and put thru testing. will modify to suit [as you expected], but think i've got the .Item concept and iterating to find what i'm looking for.

    as usual, it was simple, but this simpleton....

    now, some further advice, please: during testing .item iteration, execution produced "Run-time error. Automation error."

    i suspected what in myBlock caused Run-time, so i exploded myBlock in acad, removed some RText used to display filename, redefined myBlock, saved, and ran VB code [yours] without Run-time error.

    any suggestions for avoiding Run-time error when .item iteration comes to this RText [diesel code]? any suggestions on detecting/excluding this item?

    really need to automatically display .dwg filename. some other method other than embedding diesel code as RText?

    hopefully this will be my last irritation as restof applicationcode written/passed test. changing these myBlock.Tagstring is last item for application.

    thanx again for pushing my onward.

    marklewis
     
    mblewis, Nov 24, 2004
    #7
  8. mblewis

    mblewis Guest

    since i've run into problem with RText included in oMyBlock, ive decided a different approach based on some previously proven code.

    knowing blockdef/blockref to revise, insteadof manipulating it, will record tagstring/textstring in Array, delete blockRef, purge blockDef, insert fresh block. then populate block attrib's from array data.

    that RText was a deal breaker and really fried the code when execution hit it.

    thanx for your patience. i've learned alot about getting at blockref & blockdef details. very enlightening.

    thank you again.
    marklewis
     
    mblewis, Nov 24, 2004
    #8
  9. mblewis

    MP Guest

    Hi Mark,
    I'm glad you got it to work for your needs.
    I'm curious what your code is that bombed on rtext.
    Do you mind posting that portion?
    I'm not aware of any reason that should cause a problem.
    Thanks
    Mark

    different approach based on some previously proven code.
    record tagstring/textstring in Array, delete blockRef, purge blockDef,
    insert fresh block. then populate block attrib's from array data.
    blockdef details. very enlightening.
     
    MP, Nov 24, 2004
    #9
  10. mblewis

    TomD Guest

    Same here. I'm very curious about that, as well.
     
    TomD, Nov 29, 2004
    #10
  11. mblewis

    mblewis Guest

    OK... i'm back from T'giving off-days & a "bad" Monday.

    here's the code inserted using rtext:
    $(getvar, "dwgname")

    this is placed in the titleblock.dwg & titleblock inserted as block into an Acad .dwg.

    my experimenting showed that if rtext string was deleted from titleblock.dwg, titleblock.dwg insert into Acad .dwg and then code iterated thru block attributes[titleblock.dwg inserted as the block], no problem.

    however, if rtext code remained in titleblock.dwg, titleblock.dwg inserted as block, that produced the code failure in Acad .dwg.

    hope that's clear, if not, ask and i'll try to explain differently.

    i would like to find solution using iteration suggested rather than my "less than elegant" solution that would get the job done.

    thanx for your interest/curiousity.

    marklewis
     
    mblewis, Nov 30, 2004
    #11
  12. mblewis

    TomD Guest

    titleblock.dwg, titleblock.dwg insert into Acad .dwg and then code iterated
    thru block attributes[titleblock.dwg inserted as the block], no problem.
    as block, that produced the code failure in Acad .dwg.
    "less than elegant" solution that would get the job done.
    I guess our (at least my) confusion stems from your assumption: Something
    in what you're saying doesn't add up. If I'm not mistaken, the sample of
    code posted iterated through each entity and performed something if the
    object was an attribute. That being the case, what you're saying shouldn't
    be possible.

    Can you post your code?

    FWIW: I've found that in cases like this, more often that not I find that I
    jumped to an illogical conclusion and based on what seemed to be causing the
    problem, even though I knew it wasn't possible. Point being: I think there
    is some other oddity in your code. It could well be the RTEXT causing the
    grief, but I don't think the problem is occuring where you think it is.
    (All speculation from a novice, of course.)
     
    TomD, Nov 30, 2004
    #12
  13. mblewis

    mblewis Guest

    OK>>>>
    well, here's the Sub written to find a specific blockdef "ELEM" & process each attribute tagname:

    Public Sub Stdz_Malform_Tagnames()
    Dim oMyBlock As AcadBlock
    Dim ThisDrawing as AcadDocument
    Dim oEnt As AcadEntity

    On Error GoTo ERR_HAND
    Set oMyBlock = ThisDrawing.Blocks.Item("ELEM")
    For Each oEnt In oMyBlock
    If TypeOf oEnt Is AcadAttribute Then
    oEnt.TagString = "MyNewTag"
    End If
    Next
    Exit Sub

    ERR_HAND:
    Resume
    End Sub

    the system failure appears to occur on line:
    " If TypeOf oEnt Is AcadAttribute Then"

    it appears that rtext code is being tested by "TypeOf" & that testing causes failure

    obviously i don't want all Tagstrings to be same; this code is just to prove the con, ceptthen will be revised todo what i really am after. just trying to prove a "simple" case before creating a "complex" case.

    "one step at a time in time."

    marklewis
     
    mblewis, Dec 2, 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.