working with selection set filters

Discussion in 'AutoCAD' started by Mandy, Jan 17, 2005.

  1. Mandy

    Mandy Guest

    I am currently using a loop on all entities in a map to look for entities with certain properties, like this:

    For Each oAcadObj In ThisDrawing.ModelSpace
    '''Look for entities with certain properties, write out some info
    Next

    My processing is kind of slow, and I was thinking that to speed it up, I might be able to restrict my search to entities of certain object types, or which are on certain layers, etc. I haven't used selection sets before, but I'd like to at least try this out and do some timing comparisons to see if this is worth doing or not. I've been looking at some examples, but I'm still having some trouble with this. Let's say I want to loop on only entities which are Lines or Polylines (object type AcDbLine or AcDbPolyline). This is what I'm trying to do, but it's not working (nothing is getting selected):

    Dim ssLines As AcadSelectionSet
    Dim GroupCode(0 To 1) As Integer
    Dim DataValue(0 To 1) As Variant

    Set ssLines = ThisDrawing.SelectionSets.Add("SS1")
    GroupCode(0) = 0
    DataValue(0) = "Line"
    GroupCode(1) = 0
    DataValue(1) = "Polyline"

    '''''Or I also tried doing it this way, which I had also seen in an example
    '''''''GroupCode(0) = 0: DataValue(0) = "Line,Polyline"

    ssLines.Select acSelectionSetAll, , , GroupCode, DataValue

    For Each oAcadObj In ssLines
    '''Look for entities with certain properties, write out some info
    Next


    For the DataValue, in addition to "Polyline", I also tried "AcDbPolyline" and other things. From the examples I saw, I thought that it should be "Line" and "Polyline", but I'm not really sure.

    I'm sure I'm doing something really stupid. Any help in pointing it out would be much appreciated :)
     
    Mandy, Jan 17, 2005
    #1
  2. Mandy

    Oberer Guest

    Here's some code that's been floating around for a while for your selection set creation:

    Code:
    'Simple sel set object creation function.
    'vba will return an error if the sel set object already exists
    'in the SSETS collection
    Public Function vbdPowerSet(strName As String) As AcadSelectionSet
    Dim objSelSet As AcadSelectionSet
    Dim objSelCol As AcadSelectionSets
    Set objSelCol = ThisDrawing.SelectionSets
    For Each objSelSet In objSelCol
    If objSelSet.Name = strName Then
    objSelCol.Item(strName).Delete
    Exit For
    End If
    Next
    Set objSelSet = objSelCol.Add(strName)
    Set vbdPowerSet = objSelSet
    End Function
    

    (usage:
    'create a new selection set object
    Set ssetObj = vbdPowerSet("SS01")
    )
     
    Oberer, Jan 17, 2005
    #2
  3. Hi Mandy,

    Most likely you are running into a non-intuitive aspect of Selection Sets
    The line below can only work once:
    Set ssLines = ThisDrawing.SelectionSets.Add("SS1")
    Each time you try run it after that you have to clear the error and continue
    the program running. There are all sorts of approaches to this problem.

    The one I use is shown below:
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Create a selection set of objects on selected Layer
    'Call with:
    'Dim ssObjects As AcadSelectionSet
    'Dim iTmp As Integer
    'sObjectType = "LWPOLYLINE" ' Object type
    ''sLayer = "Text" ' Object layer
    'iTmp = SelectObjectsOnLayer(ssObjects, spObjectType, spLayer)
    Sub ssTest()
    Dim lTmp As Long
    Dim ssObjects As AcadSelectionSet
    lTmp = SelectObjectsOnLayer(ssObjects, "LWPOLYLINE", "TEXT")
    or
    If SelectObjectsOnLayer(ssObjects, "LINE", "TEXT") > 0 then
    DoSomething
    else
    Exit Sub
    End if
    End Sub ' ssTest()
    ''''''''''''''''''''''''''''' '''''''''''''''''''
    Public Function SelectObjectsOnLayer(ssObs As AcadSelectionSet, spObjectType
    As String, spLayer As String) As Long
    On Error Resume Next
    Dim FilterType(0 To 1) As Integer
    Dim FilterData(0 To 1) As Variant
    Dim sNumber As String
    FilterType(0) = 0: FilterData(0) = spObjectType
    FilterType(1) = 8: FilterData(1) = spLayer
    ' The line below will create an error if the SSET doesn't exist
    ' or delete it if it does exist.
    ' The ON Error will allow the program to continue and create the set
    ThisDrawing.SelectionSets.Item("SSET").Delete
    Set ssObs = ThisDrawing.SelectionSets.Add("SSET")
    ssObs.Select acSelectionSetAll, , , FilterType, FilterData
    SelectObjectsOnLayer = ssObs.Count
    Exit Function
    SOLErrorHandler:
    Err.Clear
    SelectObjectsOnLayer = 0
    End Function ' SelectObjectsOnLayer()

    For passing data, you can use "LINE,POLYLINE,TEXT" to get Lines, Polylines
    and Text
    You can use any wildcards for the layers. An asterisk gets data from all
    layers.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    with certain properties, like this:
    might be able to restrict my search to entities of certain object types, or
    which are on certain layers, etc. I haven't used selection sets before, but
    I'd like to at least try this out and do some timing comparisons to see if
    this is worth doing or not. I've been looking at some examples, but I'm
    still having some trouble with this. Let's say I want to loop on only
    entities which are Lines or Polylines (object type AcDbLine or
    AcDbPolyline). This is what I'm trying to do, but it's not working (nothing
    is getting selected):
    and other things. From the examples I saw, I thought that it should be
    "Line" and "Polyline", but I'm not really sure.
    would be much appreciated :)
     
    Laurie Comerford, Jan 17, 2005
    #3
  4. Mandy

    Mandy Guest

    Thanks for the help.

    Actually, there must just be something strange about Polylines. I was just doing some little tests, and if I just filter on Lines, or just on Text, it works fine. But as soon as I set the filter to Polyline, I get nothing selected. I KNOW the drawing has polylines in it.

    Any idea what the problem might be?
     
    Mandy, Jan 17, 2005
    #4
  5. Mandy

    Jeff Mishler Guest

    Are they Polylines or LWPolylines?
     
    Jeff Mishler, Jan 17, 2005
    #5
  6. Are they LWPOLYLINE's.
    Regards - Nathan
     
    Nathan Taylor, Jan 17, 2005
    #6
  7. Mandy

    Jon Guest

    This works for me, selecting either style of 2d polyline.

    FilterType(0) = 0: FilterData(0) = "POLYLINE,LWPolyline"

    Jon
    just doing some little tests, and if I just filter on Lines, or just on
    Text, it works fine. But as soon as I set the filter to Polyline, I get
    nothing selected. I KNOW the drawing has polylines in it.
     
    Jon, Jan 17, 2005
    #7
  8. Mandy

    Jon Guest

    As a by the way:
    I test the returned entity to determine whether the polyline points list is
    a 3d array or 2d array with:

    If filterent.ObjectName = "AcDbPolyline" Then
    numvert = 2
    Else
    numvert = 3
    End If

    which comes into play as I step thru the vertices:
    vPt = filterent.Coordinates ' array of coords

    For i = 0 To ((UBound(vPt) + 1) / numvert) - 1
    pickpt = Array(vPt(i * numvert), vPt(i * numvert + 1))
    ....

    Jon
     
    Jon, Jan 17, 2005
    #8
  9. Mandy

    Mandy Guest

    Thanks for the help everyone, and all the tips. I think I've got it working now.
     
    Mandy, Jan 18, 2005
    #9
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.