Jump to content

Recommended Posts

Posted

;; ssget - Lee Mac

;; A wrapper for the ssget function to permit the use of a custom selection prompt

;; msg - [str] selection prompt

;; arg - [lst] list of ssget arguments

 

(defun LM:ssget ( msg arg / sel )
   (princ msg)
   (setvar 'nomutt 1)
   (setq sel (vl-catch-all-apply 'ssget arg))
   (setvar 'nomutt 0)
   (if (not (vl-catch-all-error-p sel)) sel)
)

 

 

why ssget needs a wrapper?

Posted

why ssget needs a wrapper?

 

This 'wrapper' allows you to quickly provide a custom Selection Filter, and user prompt, without duplicating the code in each-and-ever-single routine; the wrapper is merely a sub-function.

 

Cheers

 

 

 

[Edit] - Quick examples:

 

(defun c:SelectCircles (/ ss)
 (if (setq ss (LM:ssget "\nSelect circles: " '(((0 . "CIRCLE")))))
   (prompt
     (strcat
       "\nYou selected "
       (itoa (setq ss (sslength ss)))
       " circle"
       (if (= 1 ss)
         ""
         "s "
       )
     )
   )
 )
 (prompt "\nNothing selected ")
 (princ)
)

(defun c:SelectLines (/ ss)
 (if (setq ss (LM:ssget "\nSelect lines: " '(((0 . "LINE")))))
   (prompt
     (strcat
       "\nYou selected "
       (itoa (setq ss (sslength ss)))
       " line"
       (if (= 1 ss)
         ""
         "s "
       )
     )
   )
 )
 (prompt "\nNothing selected ")
 (princ)
)

Posted
why ssget needs a wrapper?

 

Because the standard AutoLISP function does not permit the use of a custom selection prompt, as explained in the code header.

Posted

i see...

 

1.trying to learn how nomutt effect the prompt...but cant really stage a senario when its actually makes a different.

2.what this code is actually saying in plain english?

  • 10 years later...
Posted

I am aware that I am reviving a decade old post. But I found it helpful in understanding the wrapper function.

As an example of good programming technique I am studying and exploring this function in more details. As a result, I have some doubts that I need to be cleared as part of my learning process:
1. What is the purpose of using (vl-catch-all-apply) function? I believe there are no errors that cause the (ssget) function to abort. So what error is this function handling? I am not very experienced user, so I may be missing some situations.
2. If I use (apply) instead of (vl-catch-all-apply) and comment the statement (vl-catch-all-error-p), I do not see any difference in the output. Am I missing something? Here is the modified function.

(defun M:LM:ssget ( msg params / sel )
    (princ msg) 
    (setvar 'nomutt 1) 
    (setq sel (apply 'ssget params)) ; (vl-catch-all-apply) replaced with (apply)
    (setvar 'nomutt 0) 
;;; - Commented    (if (not (vl-catch-all-error-p sel)) sel)
  sel ; Added to ensure return value
)

3. there is one minor problem.
When using (ssget) if you start window selection and press enter without clicking second corner point an error message is displayed and select object prompt is repeated.
In this function, the error message is displayed but prompt is not repeated causing confusion if the command has ended although selection cursor is displayed to know that the selection is continuing.
Is there a way to re-display the msg AFTER the error message to avoid confusion?

4. A related question:
I believe problem 3 is because the function (vl-catch-all-error-p) ignores NOMUTT. What are other commands / functions that are not affected by NOMUTT? 

Posted

(vl-catch-all-apply) is used to catch the error when the user presses Esc during the selection prompt, ensuring NOMUTT is set back to 0.

Posted

Thank you Lee Mac for prompt response. Any thoughts about 3?

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