sorting entities

Discussion in 'AutoCAD' started by toddralph, Aug 12, 2004.

  1. toddralph

    toddralph Guest

    Hi,
    I have a requirement to select a series of polylines and sort them from left to right (ie draw the left ones first). To do this I figured I would create a selection set, add the plines to an array, sort the array based on the coordinates(0) property, then add new polylines to the drawing in the sorted array sequence. It seems that the 'Set' statement only creates a reference to the original object and that keeps me from deleting the original plines. Code below... any thoughts? Thanks in advance.

    Todd

    Private Sub cmdOrderWestToEast_Click()
    Dim sset As AcadSelectionSet
    Dim filterTypes(1) As Integer
    Dim filterData(1) As Variant
    Dim PlineObj As AcadPolyline
    Dim PlineArray() As AcadPolyline
    Dim newPline As AcadPolyline
    Dim XdataType(0 To 1) As Integer ' For XData
    Dim Xdata(0 To 1) As Variant ' For XData

    Dim i As Long

    'set the filter to select only polylines
    filterTypes(0) = 0
    filterTypes(1) = 8
    filterData(0) = "POLYLINE"
    filterData(1) = "Center Line"

    Set sset = ThisDrawing.ActiveSelectionSet
    sset.Clear
    Me.Hide
    sset.SelectOnScreen filterTypes, filterData

    ReDim PlineArray(sset.Count - 1)
    i = 0

    For Each PlineObj In sset
    Set PlineArray(i) = PlineObj
    i = i + 1
    Next PlineObj

    Selectionsort PlineArray, 0, sset.Count - 1

    For i = 0 To UBound(PlineArray)
    Set newPline = ThisDrawing.ModelSpace.AddPolyline(PlineArray(i).Coordinates)
    XdataType(0) = 1001: Xdata(0) = "Makkovik_Bank"
    XdataType(1) = 1000: Xdata(1) = UCase(prefix) & "_" & Format(i + 1, "0000")
    newPline.SetXData XdataType, Xdata
    Next i
    Erase PlineArray

    For Each PlineObj In sset
    PlineObj.Delete
    Next PlineObj
    Me.Show
    End Sub
     
    toddralph, Aug 12, 2004
    #1
  2. This probably won't solve your problem but you can replace

    For Each PlineObj In sset
    PlineObj.Delete
    Next PlineObj

    with

    sset.Erase

    Regards - Nathan
     
    Nathan Taylor, Aug 12, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.