Jump to content

Select objects: or (A)ll


Happy Hobbit

Recommended Posts

This should be easy, however I'm struggling with it. I would like a routine to use as a template that uses the following method:

Prompts: "Select objects: or (A)ll"

A left then click starts the select items by window unless "A" is entered, in which case everything (filters allowing) is selected

 

My code so far is:

 

(defun c:select-opt (/ opt ss)
 (setq opt (cond ((getkword "\nSelect objects: or (A)ll "))("s")))
 (cond
   ((eq opt "a")
          (setq ss (ssget "_X" '((0 . "TEXT,MTEXT"))))
   )
   ((eq opt "s")
    (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
    )
 )
(princ (itoa (sslength ss)))
 (princ)
)

 

This works, but needs a right click first, I would like to do away with the right click

Link to comment
Share on other sites

You can simply use

(setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))

and type "all" when prompt for selection.

 

Or

(princ "\nSelect objects or press enter to select all: ")
(or
 (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
 (setq ss (ssget "_X" '((0 . "TEXT,MTEXT"))))
 )

Link to comment
Share on other sites

That's odd, it works in the Console but comes up with ; error: too few arguments in a lisp:

 

(defun c:select-opt ( ss )
 (princ "\nSelect objects or press enter to select all: ")
(or
 (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
 (setq ss (ssget "_X" '((0 . "TEXT,MTEXT"))))
)
(princ (strcat "\n" (itoa (sslength ss))))
 (princ)
)

Link to comment
Share on other sites

I still think it must be possible to put a 'cond' statement within a command, witness the draw circle, arc or spline for starters.

 

Or Trim which returns "Select objects or

 

Oh well

Link to comment
Share on other sites

I still think it must be possible to put a 'cond' statement within a command, witness the draw circle, arc or spline for starters.

Or Trim which returns "Select objects or

Oh well

With a simple if like that maybe? :)

 

(defun c:select-opt ( / ss)
 (princ "\nSelect objects and press enter or press enter right away to select all: \n")
 (if (not (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))))
     (setq ss (ssget "_X" (list '(0 . "TEXT,MTEXT") (cons 410 (getvar 'ctab)))))
 )
 (princ (itoa (sslength ss)))
 )

 

 

I limited the ssget _x to the current tab only, without it it would select from all tabs and model as well.

 

Cheers!

Jef!

Link to comment
Share on other sites

That does exactly was I am after, thank you Jef!

 

The problem with the

(or
 (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
 (setq ss (ssget "_X" '((0 . "TEXT,MTEXT"))))
 )

method was that a mis-click on a non text item would make the code default to ssget_X

Link to comment
Share on other sites

Aside from the addition of the layout filter for the (ssget "_X") expression, note that an (if (not ... ) ...) statement will operate identically to an (or ) statement.

 

In both cases, the second expression will only be evaluated if the first returns nil.

Link to comment
Share on other sites

You're right Lee, it does.

I did try a

(setq pt (getpoint))
(ssget pt (getpoint))

statement inside an 'if' to take care of a left click, ssget supposedly allowing for:

(ssget [sel-method] [pt1 [pt2]] 

format, but it doesn't work very well. I also tried a grread to detect left or right clicks to decide the left/right click (5 or 25), grread would also supply the starting coordinate for the ssget, I was unsuccessful here too.

Link to comment
Share on other sites

But I always wondered if the objects are already selected - how they can be expressed wih setq ?
I'm not in front of my work computer, but if i were you i'd start by looking at vla-get-activeselectionset. I'M not sure non vlisp could achieve the same but something tells me that could be a viable answer to what you're looking for.

 

note that an (if (not ... ) ...) statement will operate identically to an (or ) statement.

In both cases, the second expression will only be evaluated if the first returns nil.

Thanks for that info. I had a hunch it could do the same but didn't have the time to verify. Beside, i felt a if statement might be easier to understand without further explications. Nonetheless, I always appreciate how in depth you explain things, and the quality of your comments.

 

That does exactly was I am after, thank you Jef!
I'm glad I could assist!

 

Cheers!

Link to comment
Share on other sites

But I always wondered if the objects are already selected - how they can be expressed wih setq ?

 

You could use the Implied Selection mode string ("I"), or you could use the ssgetfirst function.

 

However, note that ssget will honour an implied selection by default providing PICKFIRST=1.

 

I always appreciate how in depth you explain things, and the quality of your comments.

 

Thank you for your positive feedback Jef, I appreciate it.

Link to comment
Share on other sites

Further to my original thread & thinking generally about selecting items I came up with a WIP lisp that selects either multiple text or a single attribute. I haven't finished it yet, it's far from perfect (have to wait until tomorrow, if I get time) but I think it's got potential for various editing functions. One immediate drawback is the lack of a 'window' whilst the text is being selcted for the ssget, no idea how to achieve that. Any thoughts anyone?

 

;; http://www.cadtutor.net/forum/showthread.php?69933-Get-point-via-entsel (pBe #5)
(defun c:Select-Text-or-Attribute (/ ent gr pt ss)
 (if (or (setq ent (nentsel))
       (setq gr (grread t 15 0)))
     (setq pt (if  ent 
                    (cdr (assoc 10 (entget (Car ent))))
                    (cadr gr)))
         )
 (if ent
   (princ (strcat "\nSelected item is a: "(cdr(assoc 0 (entget (car ent))))"UTE"))				;; Anything
    (progn												;; You
    (setq ss (apply 'ssget (append '("_C") (append (list pt) (list (getpoint))) '(((0 . "TEXT"))))))	;; Choose
    (princ (strcat "\nThe number of TEXT items is: " (itoa(sslength ss))))				;; can go
    )													;; in here
   )
(princ)
)

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