MText entity causes loop

Discussion in 'AutoCAD' started by mblewis, Dec 16, 2004.

  1. mblewis

    mblewis Guest

    the following code is based on suggestion by R. Robert Bell
    to get attribute tagstrings from BlockDef:

    Public Sub Stdz_Malform_Tagnames2()
    ' BlockDefinition objects
    ' this Sub selects & modifies BlockDefinition objects, _
    not BlockReference objects

    On Error GoTo ERR_HAND
    Dim oMyBlock As AcadBlock

    Set oMyBlock = ThisDrawing.Blocks.Item(myTBlock)
    Dim oEnt As AcadEntity

    For Each oEnt In oMyBlock
    If TypeOf oEnt Is AcadAttribute Then
    oEnt.TagString = "MyNewTag"
    End If ' AcadAttribute
    Next oEnt
    Exit Sub
    ERR_HAND:
    Resume
    End Sub

    PROBLEM: when oEnt is MText entity, endless loop results when "Next oEnt" is processed; execution causes error which triggers On Error which executes Resume which returns to "Next oEnt" which......
    have set Watch on oEnt and when this trap occurs, oEnt Type=AcadEntity/lAcadMText in Watches box.

    any suggestions for avoiding this debilitating loop?

    marklewis
     
    mblewis, Dec 16, 2004
    #1
  2. mblewis

    fantum Guest

    Click on the word "Resume" in the code window and press the F1 key on your keyboard.
     
    fantum, Dec 16, 2004
    #2
  3. mblewis

    mblewis Guest

    nice touch, fantum.

    will add "Next" after Resume to break outta loop.

    duh, why didn't i think of that? sometimes it takes others to correctly align the mirror for us to see the obvious.

    marklewis
     
    mblewis, Dec 16, 2004
    #3
  4. What purpose do you have the error handler in there for anyway?

    <hint> Look at your function description. Ask yourself "Is it doing too
    much?" </hint>

    --
    R. Robert Bell


    the following code is based on suggestion by R. Robert Bell
    to get attribute tagstrings from BlockDef:

    Public Sub Stdz_Malform_Tagnames2()
    ' BlockDefinition objects
    ' this Sub selects & modifies BlockDefinition objects, _
    not BlockReference objects

    On Error GoTo ERR_HAND
    Dim oMyBlock As AcadBlock

    Set oMyBlock = ThisDrawing.Blocks.Item(myTBlock)
    Dim oEnt As AcadEntity

    For Each oEnt In oMyBlock
    If TypeOf oEnt Is AcadAttribute Then
    oEnt.TagString = "MyNewTag"
    End If ' AcadAttribute
    Next oEnt
    Exit Sub
    ERR_HAND:
    Resume
    End Sub

    PROBLEM: when oEnt is MText entity, endless loop results when "Next oEnt" is
    processed; execution causes error which triggers On Error which executes
    Resume which returns to "Next oEnt" which......
    have set Watch on oEnt and when this trap occurs, oEnt
    Type=AcadEntity/lAcadMText in Watches box.

    any suggestions for avoiding this debilitating loop?

    marklewis
     
    R. Robert Bell, Dec 17, 2004
    #4
  5. mblewis

    mblewis Guest

    back from vacating....
    purpose for ErrorHandler?
    during code trials, to catch any anomalies i didn't thinkof. usually eliminate after code proven.
    in this specific case, it helped me to see endless loop caused by this Sub.
     
    mblewis, Jan 3, 2005
    #5
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.