Author Topic: Reverse SSGET  (Read 4434 times)

0 Members and 1 Guest are viewing this topic.

Craig

  • Guest
Reverse SSGET
« on: November 17, 2004, 05:16:44 PM »
Hey guys, I'm working on another program and I've been having a brain fart. This HAS to be written in Autolisp so VL commands won't work. The brain fart is, whats the command that will reverse the selection set of SSGET. I'm not asking for (REVERSE lst) which is for reversing the list of a selected object. I wrote one several years back and have been looking for over an hour trying to remember which one it was but have given up for now and thought I'd just ask you guys.

The scenerio, I want to select (window) a group of text and have each one changed to what I need but they have to go in a certain order. If you window the selection the last or the one at the end of the list is the one that is selected first and I want the selection reversed so the one at the end IS last. Anyone refresh my OLD memory?  :cry:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Reverse SSGET
« Reply #1 on: November 17, 2004, 05:42:23 PM »
Try this
Code: [Select]
(defun ssreverse (ss / idx newss)
  (setq idx (1- (sslength ss))
        newss (ssadd))
  (repeat (sslength ss)
    (ssadd (ssname ss idx) newss)
    (setq idx (1- idx))
  )
  newss
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Reverse SSGET
« Reply #2 on: November 17, 2004, 07:15:33 PM »
Another way is to step through the selction set based on the flag rev-order
Code: [Select]
(if rev-order
  (setq idx  (sslength ss) ;start at end
        step -1 ; and step backward
  )
  ;;  ELSE
  (setq idx -1  ; start at begining
        step 1  ; and step forward
  )
)
(repeat (sslength ss)
  (setq ent (ssname ss (setq idx (+ idx step))))
  ... do stuff with ent ...
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Craig

  • Guest
Reverse SSGET
« Reply #3 on: November 17, 2004, 09:36:34 PM »
Quote from: CAB
Try this
Code: [Select]
(defun ssreverse (ss / idx newss)
  (setq idx (1- (sslength ss))
        newss (ssadd))
  (repeat (sslength ss)
    (ssadd (ssname ss idx) newss)
    (setq idx (1- idx))
  )
  newss
)


Thats it! It's pretty close to what I had before and with a few adjustments to go with this program will work just fine. Thanks CAB! I knew I could count on you!

David Bethel

  • Swamp Rat
  • Posts: 656
Reverse SSGET
« Reply #4 on: November 18, 2004, 10:45:22 AM »
There is really no need in reversing a selection set.  If want the last edited first, use a decremental counter when stepping thru the set, If you want the first, use an incremental counter

Decremental
Code: [Select]

(setq i (sslength ss))
(while (not (minusp (setq i (1- i))))
          (setq en (ssname ss i)))


Incremental
Code: [Select]

(setq i 0)
(while (< i (sslength ss))
          (setq en (ssname ss i)
                    i (1+ i)))


-David
R12 Dos - A2K

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Reverse SSGET
« Reply #5 on: November 18, 2004, 06:10:27 PM »
... and if its critical to you that they be in creation order, throw the handles into a list, sort the handles, and go from there. It's a bit more processing time, but not as lengthy as the time as it takes me to find the h key an a keyboard.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

daron

  • Guest
Reverse SSGET
« Reply #6 on: November 19, 2004, 12:48:58 PM »
Kerry, creation order is brings up a topic I've seen before. Peep's have asked in the past if they could get just the objects added or edited during that session. Your comment seems to tell me that half of this idea is possible. The objects added could definately be found. All I need is to have someone lead me to the tlb or olb that houses the clipboard object. Anybody know where that might be?

David Bethel

  • Swamp Rat
  • Posts: 656
Reverse SSGET
« Reply #7 on: November 19, 2004, 01:20:41 PM »
You could get the enteities added since the drawing was opened.

You would have to record the handle of the last entity each time drawing a drawing is opened.  I would use a global variable.  If the drawing is empty, default to "0".  I would probably put this in your acad.lsp file and make sure acad.lsp runs every time a drawing is opened.


Code: [Select]
(setq fdi_last
   (if (entlast)
       (cdr (assoc 5 (entget (entlast))))
       "0"))


Then run a code similar to this:

Code: [Select]

  (and (setq ss (ssget "X"))
       fdi_last
       (setq i (sslength ss))
       (setq ns (ssadd))
       (while (not (minusp (setq i (1- i))))
              (setq en (ssname ss i))
              (if (> (cdr (assoc 5 (entget en))) fdi_last)
                  (ssadd en ns))))


PICKSET ns would contain the entites created since fdi_last.  For large drawings this could take a while.

As for edited entities, I don't think that is doable without reactors or such.  -David
R12 Dos - A2K