loop through objects in a block

loop through objects in a block

jeremye86
Advocate Advocate
4,294 Views
2 Replies
Message 1 of 3

loop through objects in a block

jeremye86
Advocate
Advocate

with VBA, how do you loop through all objects in a block and then change the text of only the mtext objects?

0 Likes
Accepted solutions (1)
4,295 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Assume by "... in a block", you mean a block definition, and you know that any change to the block definition will result in changes of all inserted block references to this block definition. 

 

Here is the code that does what you aksed:

 

Private Sub UpdateBlockDefinition(blkName As String)

  Dim ent As AcadEntity

  Dim blk As AcadBlock

  Dim mt As AcadMText

  For Each blk in ThisDrawing.Blocks

    If UCase(blk.Name) = UCase(blkName) Then

      For Each ent In blk

        If TypeOf ent Is AcadMText Then

          Set mt=ent

          mt.TextString="AAAAA"

          mt.Update

        End If

      Next

      Exit For

    End If

  Next

End Sub

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

jeremye86
Advocate
Advocate

Thank you Norman, much appreciated

 

these two lines is what i was missing.

 

For Each ent In blk

If TypeOf ent Is AcadMText Then

0 Likes