- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi ,
I want to remove the text from block reference using selectionsetcrossingpolygon method inside the block . But the code doesnt work properly, instead its deleting the text from modelspace. Help me find the solution
Sub removetext()
Dim acadApp As Object
Dim acadDoc As Object
Set acadApp = GetObject(, "AutoCAD.Application")
Set acadDoc = acadApp.ActiveDocument
acadDoc.SetVariable "PICKSTYLE", 1
On Error GoTo 0
' Create AcadSelectionSet Object
Dim ssetObj As Object
Err.Clear
On Error Resume Next
Set ssetObj = acadDoc.SelectionSets("SS")
If Err Then
Set ssetObj = acadDoc.SelectionSets.Add("SS")
End If
On Error GoTo 0
ssetObj.Clear
ReDim AreaLineCoords(0 To 11) As Double
AreaLineCoords(0) = 9.3196
AreaLineCoords(1) = 5.9139
AreaLineCoords(2) = 0
AreaLineCoords(3) = 18.5304
AreaLineCoords(4) = 5.9139
AreaLineCoords(5) = 0
AreaLineCoords(6) = 18.5304
AreaLineCoords(7) = 9.2155
AreaLineCoords(8) = 0
AreaLineCoords(9) = 9.3196
AreaLineCoords(10) = 9.2155
AreaLineCoords(11) = 0
' Get the block reference for the "new" block
Dim cadBlock As Object
Set cadBlock = acadDoc.Blocks.Item("new")
' Create a new selection set
Dim blockSelSet As Object
On Error Resume Next
Set blockSelSet = acadDoc.SelectionSets("blockSelSet")
On Error GoTo 0
' If the selection set exists, clear it; otherwise, create a new selection set
If Not blockSelSet Is Nothing Then
blockSelSet.Clear
Else
Set blockSelSet = acadDoc.SelectionSets.Add("blockSelSet")
End If
' Select the block reference
blockSelSet.Select acSelectionSetAll, cadBlock
' Display the selected block name
MsgBox "Selected block: " & cadBlock.Name
' Select the text objects within the specified polygonal area in the block reference
blockSelSet.SelectByPolygon acSelectionSetCrossingPolygon, AreaLineCoords
' Display the count of selected objects
MsgBox "Number of selected objects: " & blockSelSet.Count
' Find the type of selected objects
Dim selectedType As String
If blockSelSet.Count > 0 Then
selectedType = TypeName(blockSelSet.Item(0))
Else
selectedType = "None"
End If
' Display the type of selected objects
MsgBox "Selected object type: " & selectedType
' Loop through the selected objects and delete the text objects
Dim obj As Object
For Each obj In blockSelSet
If TypeOf obj Is acadText Then
Dim textObj As acadText
Set textObj = obj
Debug.Print textObj.TextString
textObj.Delete
End If
Next obj
acadDoc.SetVariable "PICKSTYLE", 0
MsgBox "Done"
End Sub
Solved! Go to Solution.