How to search the object of the region ?

I'm using VBA and I want to search some AcadText object within the specified region.
Is there any method in ThisDrawing.Blocks or AcadBlock or other class or somehow to do so ?

Should I search all of object in 'ThisDrawing' collection with such as "For Each" loop ?

Comments

  • You could use something like this:
    
    Option Explicit
    
    Sub Select_Texts()
        ' Create or set the selection set
        Dim ssObj As AcadSelectionSet
        
        On Error Resume Next
        Set ssObj = ThisDrawing.SelectionSets.Add("SSTexts")
        If Err.Number <> 0 Then
            Set ssObj = ThisDrawing.SelectionSets.Item("SSTexts")
        End If
        On Error GoTo 0
        ssObj.Clear
        
        ' Set the type of window selection and the points that define the region
        ' for instance p1 = (800,350,0) and p2 =(-20, -10,0)
        Dim mode As Integer
        Dim p1(0 To 2) As Double
        Dim p2(0 To 2) As Double
        
        mode = acSelectionSetCrossing
        p1(0) = 800: p1(1) = 350: p1(2) = 0
        p2(0) = -20: p2(1) = -10: p2(2) = 0
        ssObj.Select mode, p1, p2
        
        ' Set the filter data
        Dim gpCode(0) As Integer
        Dim dataValue(0) As Variant
        gpCode(0) = 0
        dataValue(0) = "Text"
        
        Dim groupCode As Variant, dataCode As Variant
        groupCode = gpCode
        dataCode = dataValue
        
        ssObj.Select mode, p1, p2, groupCode, dataCode
        
        MsgBox (ssObj.Count)
        
    End Sub
    
  • Hello, Virgil.
    Thank you for answering.

    AcadSelectionSet class and Select method.
    I see.