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

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Clearing "previous" selection sets
« on: October 30, 2009, 03:18:49 PM »
I have been looking into how to clear out a previous selection set, and either I am missing an elementary method or it isn't possible ... It seems as though it should be, but alas I can't find it ... you know, its the  trees / forest thingy ... anyway, I have tried iterating through the selection sets and deleting them and I have tried creating a blank selection set, but the way AutoCAD handles the "previous" selection set is obviously a secret beyond my current comprehension.

Is this even possible to do?

The need I have is simple ...
Code: [Select]
(setq sset (ssget "_P" <insert selection filter here> ))
(if sset
  (if (/= (sslength sset) 0)
;;; do stuff here if there is a selection set and if it has passed the filter criteria and there is at least one item
  )
)
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

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Clearing "previous" selection sets
« Reply #1 on: October 30, 2009, 03:41:24 PM »
Wouldn't

(setq sset nil)

do what you need?  Maybe I am missing the question?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Clearing "previous" selection sets
« Reply #2 on: October 30, 2009, 03:42:31 PM »
Use (ssgetfirst) ILO (ssget "_P"), need to adjust syntax.  8-)
Because the selection set is already made you will need to post filter it.
Or did I miss the question.
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 #3 on: October 30, 2009, 03:49:14 PM »
OK, if you use ssget to create a selection set the function (ssget "_P") will return that set but the filter option does not work with "_P".
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 #4 on: October 30, 2009, 04:03:28 PM »
This is a multi-faceted problem that I am trying to code around. Some time ago I needed the ability to allow the user to either select a window of objects or enter arbitrary information at the command line ...

Quote
Command: Select Objects [All/Blocks/Lines]:

since ssget does not allow for arbitrary input, I have to prompt the user and rely instead upon a home-grown solution to allow for the input. This means that the user will likely select a point occasionally. This is fine, except I cannot pass a starting point in a ssget call ...

I could however, grab both points with:

Code: [Select]
(initget "Some Arbitrary Values")
(setq pt1 (getpoint))
(if (= (type pt1) 'LIST)
  (setq pt2 (getcorner pt1))
  <do other stuff here>
)

and pass those points to ssget, but that will allow only a single try at selecting the objects. But I need to allow the user to select until they don't wish to select any longer ... so I use:

Code: [Select]
(vl-cmdf "select")
  (while (> (logand (getvar"CMDACTIVE") 1) 0)
  (vl-cmdf pause)
)

This allows a "previous" selection set to be created at which point I can filter it using

Code: [Select]
(setq sset (ssget "_P" <insert selection filter here> ))
(if sset
  (if (/= (sslength sset) 0)
;;; do stuff here if there is a selection set and if it has passed the filter criteria and there is at least one item
  )
)

Now, I should have a selection set based on the previous selections from my "select" call.

This works great, except occasionally, the user may not select anything, in that case, we can't peek into the "select" mechanism to see if something was selected, we can only select the previous selection set ... however, if you have not erased anything using the "erase" command, the previous selection set remains active forever, or until you close the drawing. This is a data manipulation function so I don't want any previous selection .. I want either the expressly selected elements or nothing, but I cannot seem to get away from the ssget "_P" call.

Does that make it more clear?
« Last Edit: October 30, 2009, 04:10:26 PM by Keith™ »
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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Clearing "previous" selection sets
« Reply #5 on: October 30, 2009, 04:06:27 PM »
OK, if you use ssget to create a selection set the function (ssget "_P") will return that set but the filter option does not work with "_P".


actually it does ...

Code: [Select]
(setq sset (ssget "_P" '((-4 . "<or")(2 . "SWITCH")(2 . "RECP")(-4 . "or>"))))
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 #6 on: October 30, 2009, 04:29:47 PM »
If you use a ' while ' loop, with a check to the system variable ' errno ', then you can loop until right click is pressed.  Each loop can be a single ' ssget ' call, or whatever, but they user will not know.  Example:
Code: [Select]
(setvar 'ErrNo 0)
(while (not (equal (getvar 'ErrNo) 52))
 (ssget ":s")
)
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 #7 on: October 30, 2009, 04:42:34 PM »
thats cool .. I'll have to see if I can incorporate it, but alas, I would still need to select all objects the user attempted to select, to that end, I suppose I could create an empty selection set then add each subsequent selection set to the previous until errno = 52, but I certainly would not be able to use "_P"

the whole point is to allow the user to generate a selection set or enter arbitrary data ... so I would still have to pass a previous selection set .. unless of course the user missed selecting anything, or they didn't pass the filter .. in which case the previous selection set would be incorrect.

my head hurts ... it is time for the weekend
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 #8 on: October 30, 2009, 04:47:11 PM »
Maybe get the previous selection set when the code is ran, so that if at any time ' p ' is pressed, it will add whatever the previous selection set was.
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 #9 on: October 30, 2009, 05:02:10 PM »
That is the problem, I select the previous selection set .. if the user doesn't select anything, it still returns items from the selection attempt prior to the current selection attempt.

This can be verified by doing the following:

use the select command and select a few objects ...

now use (ssget "_P")

you will get the items selected by "Select"

Now, use select again and simply window in an area where there are no objects
you have selected nothing ... i.e. the last selection set was nothing ..

now use (ssget "_P")

you will get the selection set created by the previous (ssget "_P") call, when you are expecting to have no entities ... this happens regardless of the selection mechanism ... if no objects are selected in the current selection process, when you select "_P" you get items from the previous selection process ...

I know it sounds silly, but the result is annoying as hell
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 #10 on: October 30, 2009, 05:24:32 PM »
That sounds like what should happen.  If you select nothing, then there is no selection set, so that should not be the previous one, as you didn't selection anything.  The only previous selection set that should be nil, is when you just open a drawing, and try to select previous.

What I was talking about though, is right when your command is called, get the previous selection set.  Then do the loop for the selection.  If ' p ' is entered, then run through the previous selection set that you grabbed at the beginning of the code.  This will in essence grab the entities from before your command was called; like one would expect.
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 #11 on: October 30, 2009, 05:29:10 PM »
Problem is that if you select objects & then call the routine the selected objects can only be acquired via ssgetfirst
which is still not the previous selection set.
As you say though you can rule out a previous set by comparing the entities with in both sets. So the forst thing your
routine does is (setq oldss (ssget "_P")).

You could fall back to grread and simulate the ssget.
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 #12 on: October 30, 2009, 05:54:41 PM »
Can't you use ' (ssget "i") ' to get the select objects when the command is called?  Will return a selection set if something is selected, or nil if nothing is selected.  At least it did in my little test here.
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 #13 on: October 30, 2009, 06:10:31 PM »
Tim, I am not sure an implied selection set will resolve the issue.

Either I am missing something or I am not explaining the issue correctly.

When the function is called to select objects, there is nothing selected, and there should be nothing selected. i.e. the user should select the items only when prompted to do so. The idea is that the user either enters a keyword OR begins selecting objects on the screen as prompted ..

Select Objects [Some/Arbitrary/Options/Go/Here]:

Since I cannot use option keywords with ssget, I must through necessity abandon the thought of using ssget for the selection mechanism. So, I use grread to track the mouse and filter all input. If a point is selected, the second corner is immediately prompted for ... but I want to be able to select multiple times before continuing the program ..  since I couldn't use ssget for my first selection set, I have to emmulate a selection window. getcorner works well for that purpose ... so now I have 2 points from my first (emmulated) selection ... those points are passed to ssget "_W" or "_C" depending upon the order of the point selection, thus abiding by the default AutoCAD selection process of crossing or window depending upon the direction of the selection window.

Now I have a selection set ... maybe ... since I am filtering for specific items, the user may think they have selected something when in fact they have not ... if the user continues to select, the subsequent selections can be made with either the code I previously posted OR use a modified version of the code Tim provided. If the user does not attempt to select any further items, the selection set will be empty, but through necessity, since the "select" command is issued immediately following the first selection process, there is no way to know if the user selected anything in the second attempt .. thus I am forced to use ssget "_P" after the select command ends.

Now, keep in mind that the first selection set was empty, thus a new "previous" selection set isn't created ... and "select" didn't select anything ... so in reality there are no items selected, but ssget "_P" returns the items selected the last time a selection set was successfully created ... i.e. from whatever task was previously completed.

It appears as though I have use ssget the entire way, passing the points on the fly and grab selection sets each time, iterate through them, and add them back to the original selection set. This isn't really a problem on small drawings, but when you start having selection sets of 1000 items or more that have to be filtered AND added to another selection set, the process becomes painfully slow... another reason why I preferred to use the internal selection mechanism.

I have found a way to make the previous selection set go away ... but it isn't pretty and I don't like doing it ...

1) entmake a graphical entity in the drawing
2) erase it using (vl-cmdf "erase" (entlast) "")

for obvious reasons that could cause objects to disappear in the drawing ... but it does clear the "previous" selection set
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 #14 on: October 30, 2009, 06:27:49 PM »
I think we need more information.

Why use the ' select ' command?

What is the final code supposed to do?

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.
Tim

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

Please think about donating if this post helped you.