Jump to content

LISP for Select the same entities again...


toberino

Recommended Posts

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • toberino

    16

  • irneb

    7

  • RobDraw

    5

  • rkent

    4

Top Posters In This Topic

Posted Images

If the Select command doesn't do it for you, you could always try the older PSelect command (note also not QSelect). Take note that Lee's PtManager uses ssget in some instances, this might clear the previous selection set - so you might thus loose the selection. If you want a "permanent" selection, you could do something like this:

(setq mySelection (ssget))

Either type that into the command prompt after you've grip-selected (say using QSelect) or type it in and then select. Now the mySelection lisp variable holds that selection until you close the drawing. So you can issue something like this to re-grip-select it:

(sssetfirst nil mySelection)

Or if something (other than a lisp program) is asking you to select something, simply type this

(command mySelection)

Actually, this is one of the reasons I prefer using the Filter command instead of QSelect. It remembers the last filter settings you used, and you can save these settings to a name which you can recall next year in another DWG if you so wish.

Link to comment
Share on other sites

After Select>Previous hit enter, then hit enter again......Get A Grip

Below is a screenshot of three blocks individually selected with the grips showing....

Individual selected.jpg

Below is a screenshot with the select command invoked and the previous option selected...

select invoked previous.jpg

And then with that last enter which just ends the select command...

last enter.jpg

Link to comment
Share on other sites

Must be available in 2011 and newer only. Sorry, sounds like upgrade time.

 

You could try the 30 day trial of 2013.

 

Not my choice. I work for a very large company. I must adapt to the tools provided.

I am not giving up yet though. I know there is a solution.

Link to comment
Share on other sites

Have you tried my suggestions in post #22? E.g. the PSelect was something which worked like the Select does now when PickAdd=2.

 

But I think you may run into the situation as I've described later, seeing as Lee's code "could" issue a ssget which would clear any previous selection - so none of these would do what you want. If this is the case, then try one of my other suggestions: (1) use Filter instead of QSelect (makes reusing the same filter selection a 2 click process instead of multiple clicks and typing as QSelect does); or (2) save a selection set into a lisp variable so you can reuse it whenever, no matter what's happened to any sort of previous selection (add the code to a button in your CUI if you don't want to type it out / copy-paste it each time).

Link to comment
Share on other sites

As an example. Here's what I mean by the filter command:

279.gif

 

Or going with the lisp variable idea:

283.gif

Edited by irneb
Wrong image for the lisp variable, sorry
Link to comment
Share on other sites

Have you tried my suggestions in post #22? E.g. the PSelect was something which worked like the Select does now when PickAdd=2.

 

But I think you may run into the situation as I've described later, seeing as Lee's code "could" issue a ssget which would clear any previous selection - so none of these would do what you want. If this is the case, then try one of my other suggestions: (1) use Filter instead of QSelect (makes reusing the same filter selection a 2 click process instead of multiple clicks and typing as QSelect does); or (2) save a selection set into a lisp variable so you can reuse it whenever, no matter what's happened to any sort of previous selection (add the code to a button in your CUI if you don't want to type it out / copy-paste it each time).

 

I am going to work with filter for a little bit. It is a more pwerful qselect and is transparent, which is a good feature. I just need to find a way to turn on the grips within the previous option in a command. I think it is getting the selection set properly, its just not giving me the visual that I want.

Link to comment
Share on other sites

Moved as requested..................

Thank you.

Hopefully someone that has already found a solution for this type of situation will see this thread and post a reply.

Link to comment
Share on other sites

Try this (haven't tested it at all)

(defun c:SaveSelection  (/ ss n en name enames)
 (if (and (or (setq ss (cadr (ssgetfirst))) (setq ss (ssget)))
          (or (setq name
                     (getstring
                       (strcat "\nEnter a name for this selction <Selection_" (itoa (length *SavedSelections*)) ">: ")))
              (setq name (strcat "Selection_" (itoa (length *SavedSelections*))))))
   (progn (repeat (setq n (sslength ss)) (setq enames (cons (ssname ss (setq n (1- n))) enames)))
          (setq name (strcase (vl-string-translate " _" "--" name)))
          (if (setq ss (assoc name *SavedSelections*))
            (setq *SavedSelections* (subst (cons name enames) ss *SavedSelections*))
            (setq *SavedSelections* (cons (cons name enames) *SavedSelections*)))
          (princ (strcat "\nSelection " name " saved with " (itoa (length enames)) " items selected.")))
   (princ "\nNo selection saved."))
 (princ))

(defun c:ReSelect  (/ name enames ss)
 (if *SavedSelections*
   (if (or (setq name
                  (progn
                    (initget (vl-string-trim
                               " "
                               (apply 'strcat (mapcar '(lambda (sel) (strcat " " (car sel))) *SavedSelections*))))
                    (getkword
                      (strcat "Which selection ["
                              (vl-string-trim
                                "/"
                                (apply 'strcat (mapcar '(lambda (sel) (strcat "/" (car sel))) *SavedSelections*)))
                              "] <"
                              (caar *SavedSelections*)
                              ">: "))))
           (setq name (caar *SavedSelections*)))
     (if (setq enames (cdr (assoc name *SavedSelections*)))
       (progn (setq ss (ssadd))
              (foreach e enames (ssadd e ss))
              (if (> (getvar "CMDACTIVE") 0)
                (command ss)
                (sssetfirst nil ss)))
       (princ (strcat "\nSelection " name " could not be found in the saved selections list."))))
   (princ "\nNo selection saved."))
 (princ))

It gives 2 commands:

 

 

  • SaveSelection: Saves the current selection (or a new one if nothing is currently selected) to a name you specify.
  • ReSelect: Asks for a name and reselects the items which was saved to that name (enter means the last saved one). This command can be run transparently by prefixing a ' (quote) to it.

I'd add these 2 as toolbar buttons / keyboard shortcuts in the cui so its easier to make use of them. Just use SaveSelection sparingly as it keeps the list of selections throughout the dwg's session - i.e. it can grow extremely long.

Link to comment
Share on other sites

@irneb: Thank you for idea.its funny. But I think it's not ok with keyword func. Enter not mean last saved one and getstring should be T arg?

Link to comment
Share on other sites

Thanks, I suppose I could add the T to getstring - so the name could include spaces. I already account for that by using vl-string-translate to convert those to "-". That's so the keywords work correctly, keywords can't have spaces or underscores.

Link to comment
Share on other sites

Try this (haven't tested it at all)
(defun c:SaveSelection  (/ ss n en name enames)
 (if (and (or (setq ss (cadr (ssgetfirst))) (setq ss (ssget)))
          (or (setq name
                     (getstring
                       (strcat "\nEnter a name for this selction <Selection_" (itoa (length *SavedSelections*)) ">: ")))
              (setq name (strcat "Selection_" (itoa (length *SavedSelections*))))))
   (progn (repeat (setq n (sslength ss)) (setq enames (cons (ssname ss (setq n (1- n))) enames)))
          (setq name (strcase (vl-string-translate " _" "--" name)))
          (if (setq ss (assoc name *SavedSelections*))
            (setq *SavedSelections* (subst (cons name enames) ss *SavedSelections*))
            (setq *SavedSelections* (cons (cons name enames) *SavedSelections*)))
          (princ (strcat "\nSelection " name " saved with " (itoa (length enames)) " items selected.")))
   (princ "\nNo selection saved."))
 (princ))

(defun c:ReSelect  (/ name enames ss)
 (if *SavedSelections*
   (if (or (setq name
                  (progn
                    (initget (vl-string-trim
                               " "
                               (apply 'strcat (mapcar '(lambda (sel) (strcat " " (car sel))) *SavedSelections*))))
                    (getkword
                      (strcat "Which selection ["
                              (vl-string-trim
                                "/"
                                (apply 'strcat (mapcar '(lambda (sel) (strcat "/" (car sel))) *SavedSelections*)))
                              "] <"
                              (caar *SavedSelections*)
                              ">: "))))
           (setq name (caar *SavedSelections*)))
     (if (setq enames (cdr (assoc name *SavedSelections*)))
       (progn (setq ss (ssadd))
              (foreach e enames (ssadd e ss))
              (if (> (getvar "CMDACTIVE") 0)
                (command ss)
                (sssetfirst nil ss)))
       (princ (strcat "\nSelection " name " could not be found in the saved selections list."))))
   (princ "\nNo selection saved."))
 (princ))

It gives 2 commands:

 

 

  • SaveSelection: Saves the current selection (or a new one if nothing is currently selected) to a name you specify.
  • ReSelect: Asks for a name and reselects the items which was saved to that name (enter means the last saved one). This command can be run transparently by prefixing a ' (quote) to it.

I'd add these 2 as toolbar buttons / keyboard shortcuts in the cui so its easier to make use of them. Just use SaveSelection sparingly as it keeps the list of selections throughout the dwg's session - i.e. it can grow extremely long.

Dear Sir,

 

Very Very Nice Lisp thx for sharing,

q1) can this i use existing command (example c:copy Select objects: existing selection save name xyz)

q2) can u add dcl for better selection

Link to comment
Share on other sites

Yes you can! :lol:

 

Q1: Consider this:

Command: COPY
Select objects: Specify opposite corner: 4 found
Select objects:
Current settings:  Copy mode = Multiple
Specify base point or [Displacement/mOde] <Displacement>:
Specify second point or [Array] <use first point as displacement>:
Specify second point or [Array/Exit/Undo] <Exit>: *Cancel*

Command: SAVESELECTION
Select objects: p
4 found
Select objects:
Enter a name for this selction <Selection_0>:
Selection SELECTION-0 saved with 4 items selected.

Command:MOVE
Select objects: Specify opposite corner: 8 found
Select objects:
Specify base point or [Displacement] <Displacement>:
Specify second point or <use first point as displacement>:

Command: SAVESELECTION
Select objects: p
8 found
Select objects:
Enter a name for this selction <Selection_1>:
Selection SELECTION-1 saved with 8 items selected.

Command: MOVE
Select objects: 'reselect
Which selection [sELECTION-1/SELECTION-0] <SELECTION-1>:
 8 found
Select objects:
Select objects:
Specify base point or [Displacement] <Displacement>:
Specify second point or <use first point as displacement>:

 

Q2: Can you speak to my boss to give me some more spare time for this? I'd like to do it, just have to do my day-job :ouch: for now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...