SelectByPolygon - What's Missing?

Discussion in 'AutoCAD' started by Oberer, Nov 8, 2004.

  1. Oberer

    Oberer Guest

    I'm trying to create a selection set of lines and text from LDD's parcel coordinates. I can get the help's example to work, but not my own.... (my sel set count is always 0).

    Any and all help is greatly appreciated.
    TIA!


    Public Function getParcelSelectionSet(strParcelNumber As String) As AcadSelectionSet
    Dim oParcels As AeccParcels
    Dim oParcel As AeccParcel
    Dim oParcelEntities As AeccParcelEntities
    Dim oParcelEntity As AeccParcelEntity
    Dim oParcelSelectionSet As AcadSelectionSet
    Dim vParcelPoints() As Double
    Dim i As Integer
    Dim grpCode(0 To 1) As Integer
    Dim dataVal(0 To 1) As Variant

    Set oParcels = AeccApplication.ActiveProject.Parcels

    Set oParcel = oParcels.Item(strParcelNumber)
    ' get each parcel entity
    Set oParcelEntities = oParcel.ParcelEntities
    ' redim array
    ReDim vParcelPoints((oParcelEntities.Count * 6) - 1) As Double
    For Each oParcelEntity In oParcelEntities
    ' add the start and end points to the array
    vParcelPoints(i) = oParcelEntity.StartEasting
    i = i + 1
    vParcelPoints(i) = oParcelEntity.StartNorthing
    i = i + 1
    vParcelPoints(i) = 0
    i = i + 1
    vParcelPoints(i) = oParcelEntity.EndEasting
    i = i + 1
    vParcelPoints(i) = oParcelEntity.EndNorthing
    i = i + 1
    vParcelPoints(i) = 0
    i = i + 1
    Next

    ' create selection set
    Set oParcelSelectionSet = vbdPowerSet("Parcel_SS")
    ' create sel set filters
    grpCode(0) = 0
    dataVal(0) = "TEXT"
    grpCode(1) = 8
    dataVal(1) = "0"

    ' build sel set
    Application.ZoomAll
    oParcelSelectionSet.SelectByPolygon acSelectionSetFence, vParcelPoints, grpCode, dataVal

    ' if sel set has object, return it
    If oParcelSelectionSet.Count > 0 Then
    Set getParcelSelectionSet = oParcelSelectionSet
    End If

    Set oParcelSelectionSet = Nothing
    Set oParcel = Nothing
    Set oParcels = Nothing
    Set oParcelEntities = Nothing
    Set oParcelEntity = Nothing
    End Function
     
    Oberer, Nov 8, 2004
    #1
  2. Oberer

    Oberer Guest

    I'm stumped here. I was thinking that my problem with the above code is that I have duplicate point values (parcel entity #1's start pt could be ent #2's end point). I tried to create an array of doubles usings coords that on the outskirts of the dwg limits. I still can't get the bypolygon method to work (even with the application.zoomall)
     
    Oberer, Nov 8, 2004
    #2
  3. Oberer

    Oberer Guest

    "I have duplicate point values"
    After further investigation, I found out this is in fact my problem.

    I'd delete the thred if I knew how...
     
    Oberer, Nov 8, 2004
    #3
  4. Oberer

    TomD Guest

    No need for that. I appreciate your posting the solution. That's one I'll
    file away. ;)
     
    TomD, Nov 8, 2004
    #4
  5. Oberer

    Oberer Guest

    Actually TomD, I didn't. Here's what I ended up doing.
    The test to decide if the point was already in my array seemed a little complicated. I decided to import the parcel boundary, and use it's vertices for my selection polygon.

    For those using LDD & parcels..

    Currently, the function returns an array of doubles that can be used for a selection polygon.
    Function psub_returnParcelCoords() As Variant
    Dim oparcel As AeccParcel
    Dim vCoords As Variant
    Dim vCoordsToUse() As Double
    Dim oParcelPrefs As AeccPreferencesParcel
    Dim oParcelPrefsToRestore As AeccPreferencesParcel
    Dim oLWP As AcadEntity
    Dim i As Integer
    Dim j As Integer

    Set oParcelPrefs = AeccApplication.ActiveProject.Preferences.Parcel
    Set oParcelPrefsToRestore = oParcelPrefs
    Set oparcel = AeccApplication.ActiveProject.Parcels.Item(mstrParcelNumber)
    oParcelPrefs.SetInteger kNumberLabelsOn, 0
    oParcelPrefs.SetInteger kSqUnitLabelsOn, 0
    oParcelPrefs.SetInteger kSequentialOn, 0
    oParcelPrefs.SetInteger kAutoLabelPlacement, 0
    oParcelPrefs.SetInteger kLabelParcelsAsDefined, 0
    oParcelPrefs.SetInteger kIncludeParcelLines, 1
    oparcel.Import
    Set oLWP = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
    If TypeOf oLWP Is AcadLWPolyline Then
    vCoords = oLWP.Coordinates
    ReDim vCoordsToUse(((UBound(vCoords)) / 2) * 3)

    j = 0
    For i = 0 To UBound(vCoords)
    vCoordsToUse(j) = vCoords(i)
    i = i + 1
    j = j + 1
    vCoordsToUse(j) = vCoords(i)
    j = j + 1
    vCoordsToUse(j) = 0
    j = j + 1
    Next

    psub_returnParcelCoords = vCoordsToUse
    oLWP.Delete
    Else
    MsgBox "Parcel Boundary not imported. Can't continue" & vbNewLine & _
    "ERROR in returning parcel coordinates"
    End If

    ' restore orig parcel prefs
    With AeccApplication.ActiveProject.Preferences.Parcel
    .SetInteger (kAreaUnitLabelsOn), oParcelPrefsToRestore.GetInteger(kAreaUnitLabelsOn)
    .SetInteger kNumberLabelsOn, oParcelPrefsToRestore.GetInteger(kNumberLabelsOn)
    .SetInteger kIncludeParcelLines, oParcelPrefsToRestore.GetInteger(kIncludeParcelLines)
    End With

    Set oparcel = Nothing
    Set oParcelPrefs = Nothing
    Set oParcelPrefsToRestore = Nothing
    Set oLWP = Nothing

    End Function
     
    Oberer, Nov 9, 2004
    #5
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.