+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member Tuoni's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2006
    Location
    England
    Posts
    21

    Question Order a selctionset by property?

    Registered forum members do not see this ad.

    Does anybody know if it's possible to order a selectionset by a specified property in VBA?

    What I am trying to do:

    I have a collection of polylines on a drawing, all of which are contained in a selection set. I then want to iterate through the selection set, starting with the polyline with the smallest area through to the polyline with the largest area.

    Does anybody know of any way to do this?
    - Tuoni

    Terminat hora diem, terminat author opus

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    I would probably put their values in an array and sort on that.
    Or a sorted list box?

    in the meantime I'd ask here and hope somebody comes up with a sensible answer.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  3. #3
    Junior Member Tuoni's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2006
    Location
    England
    Posts
    21

    Default

    Thanks for your quick response, I am trying to avoid doing that
    as I need several properties on each of the objects - for instance, layer name, area, perimeter/length...

    I was wondering if there was a more efficient way?
    - Tuoni

    Terminat hora diem, terminat author opus

  4. #4
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    As I was typing that I thought "I bet he doesn't want to do this". But having typed I wasn't going to not post!

    However, having now checked the help it doesn't look like there is a method available.

    I would still be inclined to do an array. You only have to store an order, not the objects. Something like....

    Code:
    if object(order(i)).area < object(order(i+1)).area
    then temp = order(i)
    order(i) = order(i+1)
    order(i+1) = temp
    to get an array of order. Then step through by

    mySelectionSet.item(order(i))

    (totally off the top of my head so probably not practical)
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  5. #5
    Junior Member Tuoni's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2006
    Location
    England
    Posts
    21

    Default

    I have checked the help and have searched on other forums (such as the AutoDesk discussion forum) but also to no avail, that's why I aired it here.

    You should know, as well as I (if not better), that VBA is a very impractical language in AutoCAD due to its... "quirks"... shall we say?

    Still, storing (potentially) hundreds of polylines in a selection set, then having to manually trawl through it to find increasing areas is a complete ballache and isn't going to help the execution time of the software

    Thanks for your responses anyway, I think I will end up having to do it this way if you have any other thoughts in the meantime, I'd be grateful
    - Tuoni

    Terminat hora diem, terminat author opus

  6. #6
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    I find VBA easier than LISP. But it is frustrating, especially when that one command that would have saved you SO MUCH TIME isn't on the drop down list but does work if you were just brave enough to try it.

    I agree, storing hundreds of items in an array and manipulating them isn't ideal. I do sometimes resort to writing my own custom control in VB at times but I can only get them to work on my machine. No matter how closly I follow insructions I just can't seem to get them to work reliably on other machines. (not that I can see a use here)
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  7. #7
    Junior Member Tuoni's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2006
    Location
    England
    Posts
    21

    Default

    Quote Originally Posted by dbroada View Post
    I find VBA easier than LISP. But it is frustrating, especially when that one command that would have saved you SO MUCH TIME isn't on the drop down list but does work if you were just brave enough to try it.
    I haven't ever learnt LISP, I must admit (though from doing reading round it seems that VBA is more suited to my task anyway... using ADO and integrating with mirco$0ft office applications etc) but most of my software in recent years has been in languages without drop down lists so I have lost reliance on them - drop down lists being an invention of the devil is shown by the fact that "area" is not on the list for an entity (yes, I understand that it is only applicable in certain cases, but surely the programmer should know what sort of entity is being passed to the function?)

    Also, from my experience, a lot of VBA seems to be somewhat of a "Dark Art", there is little true documentation on a lot of the features - which is exactly why I joined usergroups lol

    anyways </rant>

    I'll keep digging and thinking. Got a few hour's train journey back home yet... I might as well chew it over rather than just purely staring blankly out of the window )
    - Tuoni

    Terminat hora diem, terminat author opus

  8. #8
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    The Collection object may be a good alternative to a dynamic array. It doesn't require "redim"ming , and adding items at a specific spot if a relatively easy task.

    Code:
    Option Explicit
    
    Sub SortByArea()
    Dim intCode(0) As Integer
    Dim varData(0) As Variant
    Dim entLWP As AcadLWPolyline
    Dim entLWPSorted As AcadLWPolyline
    Dim colSmall2Large As New Collection
    Dim intSSCount As Integer
    Dim i As Integer
    Dim j As Integer
    Dim colSS As AcadSelectionSet
          intCode(0) = 0: varData(0) = "LWPOLYLINE"
          intSSCount = SoSSS(intCode, varData) 'create selection
          Set colSS = ThisDrawing.SelectionSets.Item("TempSSet") 
          If intSSCount > 0 Then
             Set entLWP = colSS.Item(0)
             colSmall2Large.Add entLWP 'add first item as baseline
             For i = 1 To intSSCount - 1
                Set entLWP = colSS.Item(i)
                For j = 1 To colSmall2Large.Count
                   If entLWP.Area <= colSmall2Large.Item(j).Area Then
                      colSmall2Large.Add entLWP, , j
                      Exit For
                   ElseIf j = colSmall2Large.Count Then
                      colSmall2Large.Add entLWP, , , j 'current Pline has largest area
                   End If
                Next
             Next
          End If
          For Each entLWP In colSmall2Large
             MsgBox "Area: " & entLWP.Area & vbCr & "Perimeter: " & entLWP.Length & vbCr & "Layer: " & entLWP.Layer
          Next
          Set colSS = Nothing
          Set entLWP = Nothing
    End Sub
    
    '''''''Generic Selection Set creation routine '''''''
    
    Function SoSSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer
       Dim TempObjSS As AcadSelectionSet
       SSClear 'make sure SS doesn't already exist
       Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet")
             'Select on Screen Selection Set
       If IsMissing(grpCode) Then
          TempObjSS.SelectOnScreen
       Else
          TempObjSS.SelectOnScreen grpCode, dataVal
       End If
       SoSSS = TempObjSS.Count
       Set TempObjSS = Nothing
    End Function
    
    Private Sub SSClear()
    Dim SSS As AcadSelectionSets
       On Error Resume Next
       Set SSS = ThisDrawing.SelectionSets
          If SSS.Count > 0 Then
             SSS.Item("TempSSet").Delete
          End If
          Set SSS = Nothing
    End Sub

  9. #9
    Junior Member Tuoni's Avatar
    Using
    AutoCAD 2006
    Join Date
    Nov 2006
    Location
    England
    Posts
    21

    Default

    Thankyou both for your quick responses, and thanks SEANT, that code does exactly what I wanted, and on my "test" drawing, it runs quickly enough for me (I was quite worried at the prospect of sorting an array - not a quick process at the best of times >.<).

    Thanks again

    (Oh, and just so as you know... I did just stare blankly out of the window on the train last night hehe)
    - Tuoni

    Terminat hora diem, terminat author opus

  10. #10
    Super Member SEANT's Avatar
    Using
    AutoCAD 2012
    Join Date
    Aug 2005
    Location
    Rhode Island
    Posts
    1,968

    Default

    Registered forum members do not see this ad.

    I hope the passing scenery, blankly stared upon, was nice.

Similar Threads

  1. Layer Order.
    By Skeeps in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 19th Dec 2006, 03:23 pm
  2. Select ALL by property other than layer?
    By umop-3p!sdn in forum AutoCAD General
    Replies: 1
    Last Post: 16th Jun 2006, 05:36 am
  3. error438:'Object doesn't support this property or method
    By pondy in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 24th May 2006, 02:37 am
  4. object property
    By pimpkiss in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 25th Apr 2006, 10:19 pm
  5. changing property of a line from 2D Polyline to Line
    By a_differently abled_draft in forum AutoCAD General
    Replies: 1
    Last Post: 2nd Apr 2006, 07:45 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts