Author Topic: Clearing "previous" selection sets  (Read 7375 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #15 on: October 31, 2009, 01:03:38 AM »
I think we need more information.

I'm sorry .. I am trying to explain the isse as precisely as I can but I am obviously falling short


Why use the ' select ' command?

I'd prefer not, in fact the only reason I was using it at all was to keep from having to iterate through thousands of objects moving them from one selection set to another.


What is the final code supposed to do?

The final code should allow the user to specify an arbitrary return value while prompting to select objects for a selection set

I've put together an example working outline of code to return a selection set using some of the ideas we have talked about here.
Code: [Select]
(defun test ( / ans sset filter)
  (setq filter '((0 . "LINE")))
  (setq ans (ssgetEx "Apples Bananas Oranges" filter))
  (cond
    ((= ans "Apples")(setq sset (ssget "_X" '((0 . "LINE")(8 . "APPLES")))))
    ((= ans "Bananas")(setq sset (ssget "_X" '((0 . "LINE")(8 . "BANANAS")))))
    ((= ans "Oranges")(setq sset (ssget "_X" '((0 . "LINE")(8 . "ORANGES")))))
    ((or (= ans nil)(= (type ans) 'PICKSET))(setq sset (getmore ans filter)))
  )
  sset
)

(defun ssgetEx ( options filter / tmp initstr selOpt opCorner rVal prmpt sset)
 (setq initstr options)
 (while (/= tmp options)
  (setq tmp options)
  (setq options (vl-string-subst "/" " " tmp))
 )
 (setq prmpt (strcat "\nSelect Objects ["options"]: "))
 (initget initstr)
 (setq rVal (getpoint prmpt))
 (if (= (type rVal) 'LIST)
   (progn
     (setq opCorner (getcorner rVal "Select opposite corner: "))
     (if (< (car opCorner)(car rVal))
       (setq selOpt "_C")
       (setq selOpt "_W")
     ) 
     (setq sset (ssget selOpt rVal opCorner filter ))
   ) 
   (setq sset rVal)
 )
 sset
)

(defun getmore ( baseset filter / sset )
 (setq sset (ssget filter))
 (if (and baseset sset)
   (cond
     ((<= (sslength baseset)(sslength sset))(while (> (sslength baseset) 0)
     (setq sset (ssadd (ssname baseset 0) sset))
     (setq baseset (ssdel (ssname baseset 0) baseset))
   ))
     ((> (sslength baseset)(sslength sset))(while (> (sslength sset) 0)
     (setq baseset (ssadd (ssname sset 0) baseset))
     (setq sset (ssdel (ssname sset 0) sset))
   )(setq sset baseset))
   )
 )
 sset
)

Maybe we can go about this a different way.  You can select items, add them to a list, highlight them to mimic a selection set option.

I have not added the highlight option, because it will require a forced regen or at very least a re-iteration through the selection set.

Hopefully you can see what I am trying to accomplish. There will be some pre-built filters. In this example, I used lines that are on layers "Apples" "Bananas" or "Oranges" ... or just lines in particular if the user is selecting them.

As you can see, the original input creates a selection set that must be iterated through to combine it with the additional objects selected.

I originally used "select" as a method to keep from having to do that (i.e. to build a single selection set), plus it had the additional effect of highlighting all the selected objects.

One of the things I can live with, but I don't like is that in newer versions of AutoCAD, the selection window is not drawn with the color background and window highlights as is with ssget.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #16 on: October 31, 2009, 01:06:08 AM »
Thinking grread, here is starting point.
http://www.theswamp.org/index.php?topic=29378.0
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
Re: Clearing "previous" selection sets
« Reply #17 on: October 31, 2009, 12:52:52 PM »
I took a closer look at Lee's routine & added comments. Looks like it would be easy to add the variable filter option.

One question popped up: If the user selects objects, can he change the filter option?
If so, do you go back & filter the already selected objects? I think yes.
Or do you remove the filter option once an object is selected?

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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #18 on: October 31, 2009, 05:30:31 PM »
I considered making the selection process dynamic so the user could select additional items based on the prescribed filters. In other words, the user can select a group of objects and then select an additional filter ...

i.e.
Quote
Command: (setq MySSet (test))
Select objects [Apples/Bananas/Oranges]: Specify opposite corner: 41 found
Select objects [Apples/Bananas/Oranges]: Specify opposite corner: 12 found
Select objects [Apples/Bananas/Oranges]: A
17 found
Select objects [Apples/Bananas/Oranges]: A
17 found (17 duplicate), 70 total
Select objects [Apples/Bananas/Oranges]:
<Selection set: D3E1>
Command:

Or at least that is the way I would like it to work

I used the grread function in an earlier incarnation, but it required extensive osnap handling as well as additional overhead to handle keyboard entry and/or mouse clicks on toolbars and such.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #19 on: October 31, 2009, 06:48:15 PM »
OK, you are adding to the already acquired selection set.

The osnap is not a factor in ssget.
The menu click equates to a "Right Click" so just filter it out.
The big draw back is there is no detection for [Shift Click] without express tools.
You could use the Minus key as the "Remove from ss"
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #20 on: October 31, 2009, 09:36:40 PM »
OK, you are adding to the already acquired selection set.

That is how I am handling it in the working example above, but considering that the selecting will be done on a large scale (i.e. 4000+ entities) iterating through the selection set will cause considerable speed issues, which isn't experienced when using select and building a selection set using "previous"


The osnap is not a factor in ssget.
Correct, although I have done considerable work on emulating osnaps, there is missing functionality and quite honestly, I have found it simpler to deal with the other issues than deal with the osnaps.


The menu click equates to a "Right Click" so just filter it out.
The big draw back is there is no detection for [Shift Click] without express tools.
You could use the Minus key as the "Remove from ss"

Yeah, but I don't want to have to retrain the user and in the end they will likely be confused.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #21 on: November 01, 2009, 09:15:26 AM »
With you code you still can not remove items from the selection set.
The problem is detecting the shift click.
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Clearing "previous" selection sets
« Reply #22 on: November 01, 2009, 09:30:00 AM »
You could just use the old R for remove, then if Express Tools is available, give the Shift-Remove option.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #23 on: November 01, 2009, 06:09:11 PM »
I took a run at it.
Code: [Select]
(defun ssget+ (msg data / options filters filter opCorner p1 msg sset ssRet
               ELST ENT ET I INITSTR SELOPT SHIFTWASDOWN )
  (defun FilterTest (ent filter / elst)
    (cond
      ((null filter) t)
      ((setq elst (entget ent))
       (vl-every
         (function
           (lambda (x / tag)
             (and
               (setq tag (assoc (car x) elst))
               (wcmatch (cdr tag) (cdr x)))))
         filter
       )))
  )

  (and (not acet-sys-shift-down)
       (findfile "acetutil.arx")
       (arxload (findfile "acetutil.arx") "Failed to Load Express Tools")
  )
  (setq et (not (vl-catch-all-error-p (vl-catch-all-apply 'acet-sys-shift-down '()))))
  (setq ssRet (ssadd))
  (setq options (mapcar 'car data))
  (setq initstr "")
  (mapcar '(lambda (x) (setq initstr (strcat initstr x " "))) options)
  ;(setq initstr (vl-string-right-trim " " initstr))
  (setq filters (mapcar 'cadr data))
  (setq filter (car filters)) ; start with the first filter
  (sssetfirst)                ; clear any selected objects
  (princ msg)
  (while
    (progn
      (sssetfirst  ssRet ssRet)
      (setvar "errno" 0)      ; must pre set the errno to 0
      (initget 128 initstr)
      (setq ent (entsel ""))
      (setq ShiftWasDown (and et (acet-sys-shift-down)))
      (cond
        ((= (getvar "errno") 52) ; exit if user pressed ENTER
         nil)
        
        ((null ent)           ; picked a point
         (setq data (grread t 8 0))
         (setq p1 (cadr data))
         (vl-catch-all-apply '(lambda()  ; ESC only cancels the getcorner
         (if (setq opCorner (getcorner p1 "\nSelect opposite corner: "))
           (progn
             (if (< (car opCorner) (car p1))
               (setq selOpt "_C")
               (setq selOpt "_W")
             )
             (cond
               ((setq sset (ssget selOpt p1 opCorner filter))
                (setq i -1)
                (while (setq ent (ssname sset (setq i (1+ i))))
                  (if ShiftWasDown
                    (ssdel ent ssRet)
                    (ssadd ent ssRet)
                  )
                )
               )
             )
             (setq sset nil)
           )
         )))
         (princ msg)          ; stay in loop
        )

        ((listp ent)          ; something selected
         (if (FilterTest (car ent) filter)
           (if ShiftWasDown
             (ssdel (car ent) ssRet)
             (ssadd (car ent) ssRet)
           )
         )
         t
        )

        ((vl-position ent options)
         (setq filter (nth (vl-position ent options) filters))
         (princ "\nFilter changed to ")
         (princ filter)
         (princ msg)
        )
        (t)
      )
    )
  )
  ssRet
)


Code: [Select]
(defun c:test (/ input)
  (setq input
         (ssget+
           "\nSelect Objects [All/Blocks/Lines]: " ; prompt string
           ;;  optional filter '((<keyword> <filter>) (<keyword> <filter>) ...)
           (list
             (list "All" '((8 . "0")))
             (list "Blocks" '((0 . "INSERT") (8 . "0")))
             (list "Lines" '((0 . "LINE") (8 . "0")))
           )
         )
  )
  (sssetfirst nil input)      ; highlite objects
  (princ "\nNumber of objects selected: ")
  (princ (if input (sslength input)  "0"))
  (princ)
)
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
Re: Clearing "previous" selection sets
« Reply #24 on: November 01, 2009, 06:13:00 PM »
Just realized that if you change the filter you can not unselect items that do not match the filter.
Not sure if that is a bug or a feature.  :kewl:
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Clearing "previous" selection sets
« Reply #25 on: November 04, 2009, 01:12:58 PM »
Did you get something to work for you yet?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #26 on: November 09, 2009, 10:38:51 AM »
Sorry about the absense, I have come down with some kind of infection in my leg and I have been laid up for over a week.

Yes, I did manage a solution that used parts of the various solutions offered here, but I broke down the selection process into several different loops each verifying the previous selection with the current. The process became pretty convoluted and required I use different parts in several other functions, so it isn't as simple as adding a function to call .. but it works and is marginally bulletproof.

I'd still like to see a robust way to manage it from a single function or group of cascading functions that can be called once and allow the user to manage a selection set with filters.

Anyway, I am back at work today, the leg is still in pain, it is still swollen, none of the 8 medications seem to have had much of an effect ... and while it is improving, it is doing so very slowly ... alas, no more sick days = I must be at work ... and I can't take the pain medication the doctors gave me because it makes me dizzy ... so no driving if I take it ..

Thanks for the help guys, I learned a bit by examining avenues that I hadn't yet considered.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Clearing "previous" selection sets
« Reply #27 on: November 09, 2009, 11:10:21 AM »
Good to hear about the code, sad to hear about the leg.  Hope it heals soon.  If I have some time, I'll see what I can come up with to do what you want.  I might have some time this week.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #28 on: November 09, 2009, 11:27:14 AM »
Glad you are up & around Keith. Don't be too caviler with that infection. Sick days or not.(sounds like your Mom doesn't it! :) )
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #29 on: November 09, 2009, 11:32:44 AM »
funny thing ... white blood cell count is normal, the only thing that seems to be working is an oral steroid, but now that I am nearing the end of that treatment, it seems to be stabilizing and not getting any better ... but the pain is managable with ibuprofen .. at least the 104F fever is gone ;)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie