Message 1 of 7
VBA - Selection within a poline

Not applicable
05-13-2016
07:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have this VBA code to select objects within a polyline. It used to work fine, then stopped. Now it only displays the number of items within the polyline in the comand line. I also have the simliar code to earase objects within a polyline, and it works just fine.
Any ideas on how to get this to work?
Code for selection:
Public Sub SELECTCLIP() Dim plineObj As AcadLWPolyline Dim object As Object Dim returnObj As AcadObject Dim PickedPoint As Variant, TransMatrix As Variant, ContextData As Variant Dim basePnt As Variant On Error Resume Next ThisDrawing.Utility.GetSubEntity object, PickedPoint, TransMatrix, "Please select xref polyline:" 'If Err <> 0 Then 'MsgBox "The user did not click on an Entity.(Pressed Esc. or clicked on nothing.....)" 'Exit Sub 'End If On Error GoTo 0 'If returnObj.ObjectName <> "AcDbPolyline" Then 'MsgBox "The user selected an object, but it's not a polyline." 'Exit Sub 'End If Set plineObj = object Dim sset As AcadSelectionSet For Each sset In ThisDrawing.SelectionSets If sset.Name = "BlockPolylineSSet" Then Exit For End If Next sset If sset Is Nothing Then Set sset = ThisDrawing.SelectionSets.Add("BlockPolylineSSet") Else sset.Clear End If Dim i As Integer, j As Integer Dim Coords() As Double ReDim Coords(0 To ((UBound(plineObj.Coordinates) + 1) * 1.5) - 1) j = 0 For i = 0 To UBound(plineObj.Coordinates) Step 2 Coords(j) = plineObj.Coordinates(i) j = j + 1 Coords(j) = plineObj.Coordinates(i + 1) j = j + 1 Coords(j) = 0 j = j + 1 Next i sset.SelectByPolygon acSelectionSetWindowPolygon, Coords ThisDrawing.SendCommand "_.select" + vbCr + "p" + vbCr + vbCr Exit Sub End Sub
Code to earas within a polyline:
Public Sub ERASECLIP() Dim plineObj As AcadLWPolyline Dim object As Object Dim returnObj As AcadObject Dim PickedPoint As Variant, TransMatrix As Variant, ContextData As Variant Dim basePnt As Variant On Error Resume Next ThisDrawing.Utility.GetSubEntity object, PickedPoint, TransMatrix, "Please select xref polyline:" 'If Err <> 0 Then 'MsgBox "The user did not click on an Entity.(Pressed Esc. or clicked on nothing.....)" 'Exit Sub 'End If On Error GoTo 0 'If returnObj.ObjectName <> "AcDbPolyline" Then 'MsgBox "The user selected an object, but it's not a polyline." 'Exit Sub 'End If Set plineObj = object Dim sset As AcadSelectionSet For Each sset In ThisDrawing.SelectionSets If sset.Name = "BlockPolylineSSet" Then Exit For End If Next sset If sset Is Nothing Then Set sset = ThisDrawing.SelectionSets.Add("BlockPolylineSSet") Else sset.Clear End If Dim i As Integer, j As Integer Dim Coords() As Double ReDim Coords(0 To ((UBound(plineObj.Coordinates) + 1) * 1.5) - 1) j = 0 For i = 0 To UBound(plineObj.Coordinates) Step 2 Coords(j) = plineObj.Coordinates(i) j = j + 1 Coords(j) = plineObj.Coordinates(i + 1) j = j + 1 Coords(j) = 0 j = j + 1 Next i sset.SelectByPolygon acSelectionSetWindowPolygon, Coords ThisDrawing.SendCommand "_.erase" + vbCr + "p" + vbCr + vbCr sset.Clear sset.Delete Exit Sub End Sub
Thanks in advnace