Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Sort Selectionset by X coord

Hybrid View

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Sort Selectionset by X coord

    Does anyone know how to sort a selectionset by x coordinate? I assume when one selects objects, the selectionset is ordered based on selection order, I'd like to have mine set up so that it sorts from xlow to x high.
    Christopher T. Cowgill, P.E.
    WIGHTMAN & ASSOCIATES, INC.
    ENGINEERING <> SURVEYING <> ARCHITECTURE
    AutoDesk Infrastructure Design Suite Premium 2013 x64
    Windows 7 Pro x64

  2. #2
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,073

    Default Re: Sort Selectionset by X coord

    1. Create list of enames.
    2. (vl-sort lst (function (lambda (a b) (> (cadr (assoc 10 (entget a))) (cadr (assoc 10 (entget b)))))))
    3. Create new selection set with ssadd.
    4. Step (foreach) through sorted (#2) list and ssadd enames to newly created selection set.
    Civil 3D 2011|2012 ~ Windohz 7
    Dropbox | finding the light…

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Sort Selectionset by X coord

    Thanks for the direction, I'm still having issues though. Perhaps I'm not building my list properly, but for some reason the lambda function grabs the first item, then tries to grab the entire rest of the list as the second item, That obviously doesnt work, as it cant grab the entdata from a list of entities. How do you suggest creating the list, I know that there are multiple ways of doing it, I'm using (setq lst (list ss lst)) which based on my results isnt the proper way to do it.
    here is the error I'm receiving
    ; error: bad argument type: lentityp (nil)

    Nevermind, I figured it out. I had to set each item as a list, then append my lists together. Works great!

    Thanks Alan for the help!
    Last edited by ccowgill; 2012-03-08 at 01:58 PM. Reason: Solution found
    Christopher T. Cowgill, P.E.
    WIGHTMAN & ASSOCIATES, INC.
    ENGINEERING <> SURVEYING <> ARCHITECTURE
    AutoDesk Infrastructure Design Suite Premium 2013 x64
    Windows 7 Pro x64

  4. #4
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,073

    Default Re: Sort Selectionset by X coord

    Untested, but try this...

    Code:
    (defun _SortSSByXValue (ss / lst i e add)
      (if (eq (type ss) 'PICKSET)
        (progn
          (repeat (setq i (sslength ss))
            (setq lst (cons (cons (setq e (ssname ss (setq i (1- i))))
                                  (cadr (asoc 10 (entget e)))
                            )
                            lst
                      )
            )
          )
          (setq add (ssadd))
          (foreach e (vl-sort lst (function (lambda (a b) (< (cdr a) (cdr b))))) (ssadd (car e) add))
          (if (> (sslength add) 0)
            add
          )
        )
      )
    )
    Civil 3D 2011|2012 ~ Windohz 7
    Dropbox | finding the light…

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Sort Selectionset by X coord

    Code:
    (setq ss (ssget '((0 . "TEXT") (8 . "C-ROAD-STAN-OFFS")))) ;_ select all objects
      (setvar "osmode" 64)
      (setq stp (getpoint "\nSelect insert point of first text obj")) ;_ select start point
      (setq    count1 (sslength ss)
        count  1
        xcoord (- (car stp) 0.135)
        ss1    (ssadd)
        ss4    (list (ssname ss (1- count)))
        ss6    (ssadd)
      ) ;_ end of setq
      (while (<= (1+ count) count1)        ;SORT LIST BY X COORD LOW TO HIGH
        (setq ss3 (list (ssname ss count)))
        (setq ss4 (append ss4 ss3))
        (setq count (1+ count))
      ) ;_ end of while
      (vl-sort ss4
           (function (lambda (a b) (> (cadr (assoc 11 (entget a))) (cadr (assoc 11 (entget b))))))
      ) ;_ end of vl-sort
      (setq    count 0
        counta 1
      ) ;_ end of setq
      (foreach ss5 (reverse ss4)
        (setq ss6 (ssadd ss5 ss6))
      )
    Here's the portion of the code I ended up using
    Christopher T. Cowgill, P.E.
    WIGHTMAN & ASSOCIATES, INC.
    ENGINEERING <> SURVEYING <> ARCHITECTURE
    AutoDesk Infrastructure Design Suite Premium 2013 x64
    Windows 7 Pro x64

  6. #6
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,073

    Default Re: Sort Selectionset by X coord

    append = sloooooooooow
    Civil 3D 2011|2012 ~ Windohz 7
    Dropbox | finding the light…

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,086

    Default Re: Sort Selectionset by X coord

    Quote Originally Posted by alanjt View Post
    append = sloooooooooow
    yes, but so is the rest of my program, and it looks cool when it runs:
    http://screencast.com/t/8zeIbpsH
    I'll take a look at it and try to steamline it in a bit. It was just something I tried to throw together quickly so we could save some time on a job.
    Christopher T. Cowgill, P.E.
    WIGHTMAN & ASSOCIATES, INC.
    ENGINEERING <> SURVEYING <> ARCHITECTURE
    AutoDesk Infrastructure Design Suite Premium 2013 x64
    Windows 7 Pro x64

  8. #8
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,073

    Default Re: Sort Selectionset by X coord

    Quote Originally Posted by ccowgill View Post
    yes, but so is the rest of my program, and it looks cool when it runs:
    http://screencast.com/t/8zeIbpsH
    I'll take a look at it and try to steamline it in a bit. It was just something I tried to throw together quickly so we could save some time on a job.
    Nice.
    Glad you got it working.
    Civil 3D 2011|2012 ~ Windohz 7
    Dropbox | finding the light…

  9. #9
    AUGI Addict
    Join Date
    2006-12
    Posts
    1,496

    Default Re: Sort Selectionset by X coord

    I would factor out the the process of extracting the coordinates away from the sort function - the coordinates will not change during the sorting so there isn't much need to get them over and over. Consider extracting the coordinates to a separate list first (perhaps even just the X-coordinate but include the Y if its needed as a tie-breaker), then calling for the sort.
    If you are going to fly by the seat of your pants, expect friction burns.
    Windows XP is now over 10 years old, in software terms it makes Joan Collins look like the new kid on the block. - Statler
    Everyone else being wrong is not the same thing as being right.

  10. #10
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,073

    Default Re: Sort Selectionset by X coord

    Quote Originally Posted by dgorsman View Post
    I would factor out the the process of extracting the coordinates away from the sort function - the coordinates will not change during the sorting so there isn't much need to get them over and over. Consider extracting the coordinates to a separate list first (perhaps even just the X-coordinate but include the Y if its needed as a tie-breaker), then calling for the sort.
    Basically what I did in the subroutine example I posted.
    Civil 3D 2011|2012 ~ Windohz 7
    Dropbox | finding the light…

Page 1 of 2 12 LastLast

Similar Threads

  1. Making a SelectionSet active in GUI
    By ncraig122139 in forum VBA/COM Interop
    Replies: 7
    Last Post: 2012-03-13, 05:47 PM
  2. Select Block with XDATA by selectionset method
    By ptlong04x1 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2011-07-04, 12:29 PM
  3. LISP TO GET COORD POINTS
    By tthomason in forum AutoLISP
    Replies: 7
    Last Post: 2010-01-12, 04:08 PM
  4. SelectionSet are KILLING me
    By jason907238 in forum VBA/COM Interop
    Replies: 22
    Last Post: 2005-07-12, 07:48 PM
  5. SelectionSet Error
    By jason907238 in forum VBA/COM Interop
    Replies: 4
    Last Post: 2005-06-21, 03:18 PM

Posting Permissions

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