Author Topic: Improving on entsel  (Read 14748 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #45 on: February 29, 2008, 09:21:41 AM »
My last version too. :)
Took yours & gussied up the feed back, also added one.
Rearranged the exit.
Code: [Select]
;;  CAB 02.29.08, rev 02.13.2010
;|
1) allows the user to select a single entity
2) allows the calling function to specify the prompt that will be displayed to the user
3) provides a mechanism for optional filtering of entity types, uses wcmatch filter
4) loops when missed picks
5) differentiates between a missed pick vs. the user pressing the enter key
6) will exit cleanly and return a value to the caller if the user presses the escape key
7) returns a value compatible with what would be returned by the entsel function
|;
;;  Catch escape, allow enter, entity filter or not, wcmatch on type filter
(defun getEntity (msg ; string - select message
                  etypes ; list pf types '("LINE" "CIRCLE") or pattern "Line,*Polyline"
                  /
                  ent
                 )
  (or ; except nil or single string or list of strings, force strings to upper case
    (null eTypes)
    (and (listp eTypes) (setq eTypes (mapcar 'strcase etypes)))
    (setq eTypes (list (strcase eTypes))) ; make into a list
  )
  (setvar "ERRNO" 0) ; reset error flag
  (if  ; this will catch ESCape & return nil
    (vl-catch-all-error-p
      (vl-catch-all-apply
        '(lambda ()
           (while ; return nil to exit
             (cond
               ((and (null (setq ent (entsel msg)))  (/= 52 (getvar "ERRNO")))
                 (princ "\n*-> Missed, Try Again."))
               ((= 52 (getvar "ERRNO")) (prompt "\n*-> User Quit."))
               (etypes
                   (if (vl-some '(lambda(x)
                               (wcmatch (cdr (assoc 0 (entget (car ent)))) x)) etypes)
                       (prompt "\n*-> Selection made successfully.")
                       (princ "\n*-> Wrong entity type, Try Again.")
                   )
               )
                (ent (prompt "\nselection made."))
             )
           ) ; end while
         )
      )
    )
     nil ; error return
     ent
  )
)
« Last Edit: December 06, 2010, 08:33:01 AM by CAB »
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Improving on entsel
« Reply #46 on: February 29, 2008, 10:48:21 AM »
Just for kicks; can i get a brief description of what you want/are thinking of? The reason i ask is because, you guys keep talking about feedback and using `catch-all' -- I was wondering the reason for that...instead of say, just exit on a null user return (esc and enter) -? 

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #47 on: February 29, 2008, 11:48:31 AM »
Just for kicks; can i get a brief description of what you want/are thinking of? The reason i ask is because, you guys keep talking about feedback and using `catch-all' -- I was wondering the reason for that...instead of say, just exit on a null user return (esc and enter) -? 

By feedback, I mean notifying the user that he either missed the pick or selected the wrong type of entity.

The reason for using vl-catch-all-apply is because this function will generally be called by other functions, and it is sometimes useful to let the caller know that the function failed, and decide what to do about it, rather than just aborting everything including the calling function.

So the specification would go something like this:

Provide a function that
1) allows the user to select a single entity
2) allows the calling function to specify the prompt that will be displayed to the user
3) provides a mechanism for optional filtering of entity types
4) is tolerant of missed picks
5) differentiates between a missed pick vs. the user pressing the enter key
6) will exit cleanly and return a value to the caller if the user presses the escape key
7) returns a value compatible with what would be returned by the entsel function

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Improving on entsel
« Reply #48 on: February 29, 2008, 11:57:44 AM »
Just for kicks; can i get a brief description of what you want/are thinking of? The reason i ask is because, you guys keep talking about feedback and using `catch-all' -- I was wondering the reason for that...instead of say, just exit on a null user return (esc and enter) -? 

By feedback, I mean notifying the user that he either missed the pick or selected the wrong type of entity.

The reason for using vl-catch-all-apply is because this function will generally be called by other functions, and it is sometimes useful to let the caller know that the function failed, and decide what to do about it, rather than just aborting everything including the calling function.

So the specification would go something like this:

Provide a function that
1) allows the user to select a single entity
2) allows the calling function to specify the prompt that will be displayed to the user
3) provides a mechanism for optional filtering of entity types
4) is tolerant of missed picks
5) differentiates between a missed pick vs. the user pressing the enter key
6) will exit cleanly and return a value to the caller if the user presses the escape key
7) returns a value compatible with what would be returned by the entsel function


Cool thanx, i might try and get my hands dirty with this after my project goes out. Sounds like fun.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
Re: Improving on entsel
« Reply #49 on: February 29, 2008, 01:37:57 PM »
You know what would be cool? At least I think it would. Add to the return value the converted object. So you would have (<Entity name: blahblahblah> (0.0 0.0 0.0) <VLA-OBJECT IAcadLine blahblahblah>)
I know, easy, but why not?