Author Topic: SelectionSet order  (Read 2150 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
SelectionSet order
« on: January 02, 2013, 12:13:23 PM »
It's been a while since I've had a need for lisp help, and I seem to be a bit rusty. I had forgotten that (ssget), when used with a window or crossing option, selects the objects in the reverse order in which they were created. What I need to do is allow the user to select objects, in any order they choose, using any method they choose, and return a selection set which maintains that order of selection...with the exception being those objects selected by window/crossing are added in the order in which they were created. I think this can be done by iterating the SS, using ssnamex to determine how the object was selected, and if a window/crossing flag is found compare the polygon list with the next one until a different polygon is found and reverse the order of those within the same polygon.

Has anyone done this before? If not, feel like whipping something up?  :-)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: SelectionSet order
« Reply #1 on: January 02, 2013, 12:41:10 PM »
Can't you just create an empty SS and use SSADD while looping through your selection?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: SelectionSet order
« Reply #2 on: January 02, 2013, 12:52:21 PM »
Yes, Ron, but I think there's a bit more to it than that. Unless I'm over thinking it...

LE3

  • Guest
Re: SelectionSet order
« Reply #3 on: January 02, 2013, 12:55:23 PM »
what it is autolisp?  :-o


recall doing this or something similar many many moons ago... and was about a selection of text objects via simple (ssget) in any form and returned in order from example from the top to bottom... anyway will do a search to see if i can find something.... on the mean time have fun on this task! or maybe the lisp masters will jump with a/the solution :)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: SelectionSet order
« Reply #4 on: January 02, 2013, 01:16:02 PM »
Come to think of it, what I think you are trying to do is automatically done with SSGET. If you pick one item then another then another ... etc. they will be placed in the selection set in the order they are picked. If multiple items are picked then they will be added by creation.

I'm only on my first cup of coffee though so I might be off  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danallen

  • Guest
Re: SelectionSet order
« Reply #5 on: January 02, 2013, 01:32:25 PM »
This is similar but just using fence to select objects in order they are intersected.

Dan

Code: [Select]
(defun-q c:SEF ()
 (princ "\nSelect by Fence")
 (setq ptlist (xyz_GetPointsRB))
 (if ptlist
   (progn
     (command "select" "f")
     (foreach pt ptlist (command pt))
     (command "")
   )
 )
 (princ)
)

;;;=========================================================================
;;; From: Michael Puckett (puckettm@cadvision.com)
;;; Subject: Re: Vlisp Variables
;;; Newsgroups: autodesk.autocad.customization
;;; Date: 1999/09/18
;;;
;;; It will prompt for points, and rubber band between points kinda like
;;; what you'd see if you were drawing a pline.  It will return a list of
;;; all the points selected, in the order selected, else nil.
;;;=========================================================================
(defun-q xyz_GetPointsRB ( / i Point Result )
   ;  gather and return list of
   ;  points selected by user
   ;  written by michael puckett
   (cond
      (  (car (setq Result (list (getpoint "\nPick start point: "))))
         (while
            (progn (initget 32 "C") ;use dashed line
               (setq Point (getpoint (car Result) "Next point: "))
               (if (= point "C")(setq point nil)(setq point point))
            )
            (grdraw Point (cadr (setq Result (cons Point Result))) -7)
         )
         (setq i 0)
         (while (< i (1- (length Result)))
            (grdraw (nth i Result) (nth (setq i (1+ i)) Result) -7)
         )
         (reverse Result)
      )
   )
)


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: SelectionSet order
« Reply #6 on: January 02, 2013, 01:36:19 PM »
Close, Ron, and that's what I thought. But the objects selected by window or crossing get added to the ss in reverse order (i.e. newest first) of creation. I think I have something which pretty much works now (could probably be gussied up a bit):
Code: [Select]
(defun getss_by_order(ss / idx newss ent poly enames)
  (setq idx -1
newss (ssadd)
)
  (while (setq ent (ssnamex ss (setq idx (1+ idx))))
    (if (or (= (caar ent) 2)
    (= (caar ent) 3)
    )
      (progn
(if (not poly)
  (progn
    (setq poly (cadr ent))
    (setq enames (list (cadar ent)))
    )
  ;else
  (if (equal poly (cadr (ssnamex ss (1+ idx))))
    (setq enames (append enames (list (cadar ent))))
    ;;else add the items to the newss
    (progn
    (setq enames (append enames (list (cadar ent))))
      (foreach e (reverse enames)
(ssadd e newss)
)
      (setq poly nil
    enames nil)
      )
    )
)
)
      ;else it was selected individually or by fence so just add it as is
      (ssadd (cadar ent) newss)
)
     
    )
  newss
  )