Results 1 to 20 of 21

Thread: Solved: Read field in AUTOCAD block attribute

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Quote Originally Posted by ALe
    I did do ZoomExtents. this is original code (sound it familiar to you? )
        Dim fType(1) As Integer
        Dim fData(1) As Variant
    fType(0) = 0: fType(1) = 2
    fData(0) = "INSERT": fData(1) = "Etichetta Locale" '' <-- change blockname here
    For Each oSset In ThisDrawing.SelectionSets
        If oSset.Name = "$Blocks$" Then
            oSset.Delete
            Exit For
        End If
        Next oSset
        Set oSset = ThisDrawing.SelectionSets.Add("$Blocks$") '' <-- any name is admissible
        On Error GoTo 0
    oSset.SelectOnScreen fType, fData
    I Added the following lines instead of the last original sentence
        Application.ZoomExtents
        oSset.Select acSelectionSetAll, , , fType, fData
    The selection gets the blocks but in such a way that is different from the original code...
    Try this quick example
    Hope this will make a sense
    Sub Example_CompareSelectionModes()
        Dim oSset As AcadSelectionSet
        Dim fType(1) As Integer
        Dim fData(1) As Variant
        With ThisDrawing.SelectionSets
            While .Count > 0
                .Item(0).Delete
            Wend
            Set oSset = .Add("$Parcels$")
        End With
        fType(0) = 0: fType(1) = 2
        fData(0) = "INSERT": fData(1) = "Etichetta Locale" '' <-- change blockname here
        For Each oSset In ThisDrawing.SelectionSets
           If oSset.Name = "$Blocks$" Then
               oSset.Delete
               Exit For
            End If
        Next oSset
        Set oSset = ThisDrawing.SelectionSets.Add("$Blocks$") '' <-- any name is admissible
        On Error GoTo 0
        ''  1st case: Select on screen is means selection in the current layout
        ''  so it is no needs to define selection filter with dxf code for current layout
        oSset.SelectOnScreen fType, fData
        MsgBox "First method: " & vbCr & "Selected on screen manually " & oSset.Count & " blocks" & vbCr & _
        "[ that is means in the current LAYOUT ]"
        '' using the same selection for the second method
        oSset.Clear
        ''  2nd case: Select all in the current layout
        ''  in this case you have to to define selection filter with dxf code for current layout
        Application.ZoomExtents '<-- always use it before of selection without manual interaction
        Dim mode As Integer
        mode = acSelectionSetAll '<-- define mode explicitly
        Dim curTab As Variant
        curTab = ThisDrawing.GetVariable("CTAB")
        Dim dxfType(2) As Integer
        Dim dxfData(2) As Variant
        dxfType(0) = 0: dxfType(1) = 2: dxfType(2) = 410 '<-- 410 is dxf code for layout name
        dxfData(0) = "INSERT": dxfData(1) = "Etichetta Locale": dxfData(2) = CStr(curTab) '<-- dxf value for current layout name
        oSset.Select mode, , , dxfType, dxfData
        MsgBox "Second  method: " & vbCr & "Selected using ""acSelectionSetAll"" mode " & oSset.Count & " blocks" & vbCr & _
        "[ in the current LAYOUT ]"
        '' using the same selection for the third method
        oSset.Clear
        ''  3nd case: Select all in the current drawing
        ''  no need to define selection filter with dxf code for current layout for you
        Dim dxfTyp(1) As Integer
        Dim dxfDat(1) As Variant
        dxfTyp(0) = 0: dxfTyp(1) = 2
        dxfDat(0) = "INSERT": dxfDat(1) = "Etichetta Locale"
        oSset.Select mode, , , dxfType, dxfData
        MsgBox "Third  method: " & vbCr & "Selected using ""acSelectionSetAll"" mode " & oSset.Count & " blocks" & vbCr & _
        "[ in the current DRAWING ]"
    End Sub
    Last edited by Aussiebear; 12-30-2024 at 01:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •