Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Combining (ssget) selection methods: Implied, not Locked

12 REPLIES 12
Reply
Message 1 of 13
Kent1Cooper
3670 Views, 12 Replies

Combining (ssget) selection methods: Implied, not Locked

I learned [from Lee Mac, and have since seen it elsewhere], a while back, that this selection-method combination in (ssget) [which includes some methods undocumented in the AutoLISP Reference] will let you pick one thing that's not on a locked Layer, sort of like (car (entsel)) but with the locked-Layer control and putting it into a selection set:

 

(ssget "_+.:E:S:L")

 

So clearly, it's possible to combine selection methods in (ssget).  Clearly you shouldn't be able to combine some of the others, such as X with C, but I haven't found a way to combine the ones I want.

 

I'm trying [in the current effort] to find out whether the implied selection [pre-selected objects with PICKFIRST = 1] includes any Arcs on unlocked Layers, and if so, put them into a selection set.  I can do the two sub-parts of that -- I can find Arcs in an implied selection:

 

(setq arcss (ssget "_I" '((0 . "ARC"))))

 

and I can have the user select Arcs [not pre-selected/implied] while forbidding those on locked Layers:

 

(setq arcss (ssget "_:L" '((0 . "ARC"))))

 

But I haven't found a way, in one (ssget) operation, to find Arcs in the implied selection that are not on locked Layers.  These:

 

(setq arcss (ssget "_:LI" '((0 . "ARC"))))

and

(setq arcss (ssget "_I:L" '((0 . "ARC"))))

 

both get me this message:
 

; error: bad ssget mode string

 

So apparently you can't combine just any selection method options.  Could it be that only the colon-prefixed initial-letter ones can be combined, as in the example at the top, but not those along with un-colon-prefixed letters?  Does anyone know of a way to do this?  Or must I resign myself to just getting all Arcs in an implied selection, whether locked or not, and then eliminating any that are on locked Layers one at a time, as I step through the selection set to work with them?

 

Thanks for any advice,

Kent Cooper, AIA
12 REPLIES 12
Message 2 of 13
phanaem
in reply to: Kent1Cooper

Hi Kent

This works in AutoCAD 2012

(if
    (setq ss (ssget "I" '((0 . "ARC"))))
    (setq ss1 (ssget ":L:P" '((0 . "ARC"))))
    )

 HTH

Message 3 of 13
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:

 

So apparently you can't combine just any selection method options.  Could it be that only the colon-prefixed initial-letter ones can be combined, as in the example at the top, but not those along with un-colon-prefixed letters?  Does anyone know of a way to do this?  Or must I resign myself to just getting all Arcs in an implied selection, whether locked or not, and then eliminating any that are on locked Layers one at a time, as I step through the selection set to work with them?

 

Thanks for any advice,


Its either that or collect names of all locked layer thru tblnext "Layer" , then use exclusion filter

 

(setq arcss (ssget "I"  (list '(0 . "ARC")'(-4 . "<NOT")(cons 8  locklyrlst)'(-4 . "NOT>"))))

 

HTH

 

 

Message 4 of 13
Kent1Cooper
in reply to: phanaem


@phanaem wrote:

This works in AutoCAD 2012

(if
    (setq ss (ssget "I" '((0 . "ARC"))))
    (setq ss1 (ssget ":L:P" '((0 . "ARC"))))
    )

Thanks for that suggestion -- I didn't reply sooner because I've been experimenting.  It didn't turn out to be the solution, directly, but it led me to try some variations, through which I found a way to do what I want.

 

The 😛 option is to reject ViewPorts, and isn't the same as the P [without the colon] option for the Previous selection.  Using ":LP" [or "P:L"], to combine locked-Layer rejection with the Previous option rather than with Viewport rejection, gives the same error as my previous try using ":LI" [or "I:L"].  So the reason that "works" isn't because of the 😛 in there, and it works just as well without it [since Viewports are disallowed by the filter anyway].  Also, it doesn't work if you clear the pre-selection [e.g. with Esc] in between -- (ssget ":L:P"...) then asks the User to select things, rather than using what was found by the (ssget "I") before, since the 😛 doesn't refer to the Previous selection.

 

But it does work if there's an active PICKFIRST pre-selection -- (ssget) with just the ":L" option works to select things that are not on locked Layers from such a pre-selection, if it exists, without asking the User to select objects, since they already did.  I hadn't epected that.  It's using the implied selection because that's active, an not because it's the Previous selection from the preceding (ssget "I").

 

I tried it, at first without success, in my longer routine.  But I had a (command) function in there prior to that point, and if I called up the routine with a pre-selection, that (command) function was clearing out the pre-selection, so I wasn't getting the selection out of it.

 

But that (command) function is just Undo Begin, which can also be done otherwise, but which in any case I don't need to do until after I establish a selection, before doing anything with it.  When that is moved to after the selection portion, then the function retains the active pre-selection, and gets the things from it that are not on locked Layers, without further asking the User to select things, just as intended.

 

This is an abbreviated version [the real thing actually allows certain other entity types, too] of what I ended up with:

 

(if (ssget "_I" '((0 . "ARC"))); there's a pre-selection with Arc(s) [doesn't need to be (setq)'d into a variable]
  (setq ss (ssget "_:L" '((0 . "ARC")))); then -- get those not on locked Layers [no further User selection]

  (progn ; else -- no pre-selection, or one without Arc(s)
    (sssetfirst nil); un-select pre-selection without Arc(s), if any [no effect if no pre-selection]
    (prompt "\nTo [...do what the routine does with...] Arc(s),")
    (setq ss (ssget "_:L" '((0 . "ARC")))); User select -- accept only Arcs not on locked Layers
  ); progn -- else
); if

Kent Cooper, AIA
Message 5 of 13
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....

But it does work if there's an active PICKFIRST pre-selection -- (ssget) with just the ":L" option works to select things that are not on locked Layers from such a pre-selection, if it exists, without asking the User to select objects, since they already did.  ....


A variant on that, with a different combination of methods:

 

I was trying to find all [in this instance] Mtext and Dimensions not on locked Layers in the entire drawing, rather than in a PICKFIRST User pre-selection.  Again, you can't combine the "_:L" method [to exclude things on locked Layers] with the "_X" method [for everything in the drawing] into one (ssget) operation.  But you can make an equivalent to the above approach by forcing a pre-selection, coming not from the User but via (sssetfirst):

 

(setq
  filter '((0 . "MTEXT,DIMENSION")); just to shorten next line
  ssmtd (if (sssetfirst nil (ssget "_X" filter)) (ssget ":L" filter))

    ;; ssmtd = Selection Set of MText & Dimension entities;

    ;; pre-selects all Mtext/Dimensions in drawing, then from those, the ones not on locked Layers

); setq

Kent Cooper, AIA
Message 6 of 13
dbroad
in reply to: Kent1Cooper

I admit that I haven't read the whole thread.  IMO, I can't see any reason why implied selection sets would include items on locked layers.  That said, they do.  This selection should get you arcs in an implied selection set, not on a locked layer.  Note the dash.  This is undocumented.

 

(sslength (setq ss (ssget ":L-I" '((0 . "arc")))))

Architect, Registered NC, VA, SC, & GA.
Message 7 of 13
marko_ribar
in reply to: dbroad

Thanks for the info and research Kent, but instead of :

 

(if (sssetfirst nil (ssget "_X")) (setq ss (ssget "_:L")))

 

I would suggest this snippet :

 

(if (not (equal '(nil nil) (sssetfirst nil (ssget "_X")))) (setq ss (ssget "_:L")))

 

I've tested those above and I created my ss subfunction... Unless you write something with which you can control and manipulate database as you/user wish/es you'll have headaches, believe me... So I'll post my sub in order to be used - I've loaded ss.lsp into my acaddoc.lsp so from now I'll write lisps much smarter than before...

 

HTH, Regards, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 8 of 13
marko_ribar
in reply to: marko_ribar

As I am currently on my vacation and as I wrote my ss.lsp too quickly without thorough testing, I've found some issues (minor - the concept is the same) that I fixed I hope for now correctly... So I am posting my ss.lsp.txt file, just reneme it to ss.lsp... Sorry for delay, you know beach, swimming, ... no time for real devotion...

 

Sincerely my appology for inconvenience and spoted bugs...

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 9 of 13
Kent1Cooper
in reply to: dbroad


@dbroad3 wrote:

....  This selection should get you arcs in an implied selection set, not on a locked layer.  Note the dash.  This is undocumented.

 

(sslength (setq ss (ssget ":L-I" '((0 . "arc")))))


That's very handy to know.  I was hoping the same approach would, but find that it doesn't, work with ":L-X" to find everything in the drawing fitting the filter criteria that's not on a locked Layer -- it goes into "Select objects: " mode, so it's not reading the X as it reads the I.  Maybe it has something to do with the fact that an implied selection can exist only in the current space, but the X method can of course reach beyond that.  If you know of another way to accomplish that than what I described earlier, I'd be very interested.

Kent Cooper, AIA
Message 10 of 13
dbroad
in reply to: Kent1Cooper

I admit that your application logic puzzles me a bit. Most of the time, I either want to process the whole drawing or have the user select it.  Your fallback of processing the whole drawing if the user doesn't pre-select objects is non-standard.  It would be more standard to allow the user to use the "all" keyword if they want to process everything or to allow them to select what they should process.  That said, this might suit your needs.  It was very lightly tested.

 

(cond
  ((and
   (cadr(ssgetfirst))
   (setq ss (ssget ":L-I" '((0 . "arc"))))
   )
   ss)
  (t
    (setq ss (ssget "X" '((0 . "arc"))))
    (sssetfirst nil ss)
    (setq ss (ssget ":L-I" ))
   )
  )
Architect, Registered NC, VA, SC, & GA.
Message 11 of 13
Kent1Cooper
in reply to: dbroad


@dbroad3 wrote:

....  Your fallback of processing the whole drawing if the user doesn't pre-select objects is non-standard.  ....

 


That's not what either of them does.  The original one involving possible pre-selection [Arcs] asks them to select things if they haven't selected them first, but if they have, works from their selection -- it doesn't have a fallback to do the whole drawing, but only the User option to choose ALL if that's what they want.  The one involving the whole drawing [Mtext/Dimensions] always does that, and doesn't include any User-pre-selection possibility.  [Admittedly, it doesn't quite fit the Subject line -- maybe I should have started a different thread.]

Kent Cooper, AIA
Message 12 of 13
marko_ribar
in reply to: Kent1Cooper

Discussion continued here :

http://www.cadtutor.net/forum/showthread.php?98255-Lisp-For-Select-Less-than-specified-Length-Lines&...

 

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 13 of 13
john.uhden
in reply to: Kent1Cooper

What I have done for years is to process the selection set and create a list of any locked layers, and then ask the user if he wishes to unlock them. I guess I still think that the user should have some say in his work.

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost