×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to sort items in a selection set

How to sort items in a selection set

How to sort items in a selection set

(OP)
I am looking for a vba program that will add numbers to all of the items in a selection set.  The only problem is when I do this with a simple program I have to pick the items one by one in order to get the numbering in order is there anyway way to get the numbers to be in numeric order.  


Sub numdemo()
Dim objSset As AcadSelectionSet
Dim objEnt As Object
Dim count As Integer
Dim textObj As AcadText
Dim textString As String
Dim height As Double
Dim minExt As Variant
Dim maxExt As Variant
Set objSset = ThisDrawing.SelectionSets.Add("ss")
objSset.SelectOnScreen

count = 0
For Each objEnt In objSset
objEnt.GetBoundingBox minExt, maxExt
minExt(0) = minExt(0) + 5
minExt(1) = minExt(1) + 5
count = count + 1
minExt(0) = minExt(0) + 5
minExt(1) = minExt(1) + 5
textString = count

height = 6

    Set textObj = ThisDrawing.ModelSpace.AddText(textString, minExt, height)

Next 'objEnt
objSset.Delete
End Sub

RE: How to sort items in a selection set

There are a few ways. From your code, you are outputting the info and it cycles through the selection set one by one. You would need to store all of the info first, sort it, and then output the info. You could store the info into a dynamic array, or place it in a listbox (hidden or not) and then sort it, or place it on screen and then go back and get all of the text and work through them to sort them and then move them around. A few ideas.

"Everybody is ignorant, only on different subjects." — Will Rogers

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources