Author Topic: getpoint <hopped-up>  (Read 12088 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getpoint <hopped-up>
« Reply #15 on: October 31, 2005, 05:52:16 PM »
Shoot, I just worked this out.
Code: [Select]
  (setq promptmessage "Select a point"
        default '(0.0 0.0 0.0))

  ;(initget InitBit InitString)
(setq
  returnvalue (if basepoint
                (vl-catch-all-apply 'getpoint (list promptmessage basepoint))
                (vl-catch-all-apply 'getpoint (list promptmessage))
              )
)
(cond
  ((vl-catch-all-error-p returnvalue)
   nil
  )
  (returnvalue)
  (t
   default
  )
)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: getpoint <hopped-up>
« Reply #16 on: October 31, 2005, 05:53:22 PM »
Real close Alan, I believe if the user hit escape you'd want to gracefully exit. It's the right ide, you just need an exit condition for the loop.

Code: [Select]
(defun c:test ( / message point )

    ;;  as long as the user picks points and doesn't
    ;;  press escape stay keep prompting for points ...

    (setq message "Select a point: ")

    (while
        (and
            (null
                (vl-catch-all-error-p
                    (vl-catch-all-apply
                       '(lambda ( )
                            (setq point
                                (getpoint message)
                            )
                        )    
                    )
                )    
            )    
            point
        )    
        ;;  stay the course
    )
    
    (princ "Done.")
    
    (princ)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: getpoint <hopped-up>
« Reply #17 on: October 31, 2005, 05:55:08 PM »
Like this Michael ? <snip>

Ermmm, yeah, that.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #18 on: October 31, 2005, 06:01:48 PM »
I think the speed is pretty irrelevant in a case like this, unless (unlikely) one were going to validate points in the thousands. But to play along --

Further to this point. I am curbing any obsessive inclination I had to wring the last clock click out of procedures.

My priority has shifted to maintainability as a primary .. something to do with my deteriorating memory cells perhaps.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: getpoint <hopped-up>
« Reply #19 on: October 31, 2005, 06:03:49 PM »
<nodding.gif> Diminishing returns et. al. </nodding.gif>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getpoint <hopped-up>
« Reply #20 on: October 31, 2005, 06:15:56 PM »
Real close Alan, I believe if the user hit escape you'd want to gracefully exit. It's the right ide, you just need an exit condition for the loop.
Did i misunderstand your reply?
That will exit on anything but an error.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #21 on: October 31, 2005, 06:25:36 PM »
Nope ; There's a null in there applied to the return

So the good nil is changed to .. (and ( T .....

Quote
Determines whether an argument is an error object returned from vl-catch-all-apply

(vl-catch-all-error-p arg)

Arguments : arg

Any argument.

Return Values

T, if the supplied argument is an error object returned from vl-catch-all-apply; otherwise nil

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: getpoint <hopped-up>
« Reply #22 on: October 31, 2005, 06:28:14 PM »
Sorry Alan, my mistake. I didn't realize you wanted to eliminate the user's ability to escape out of the loop. I had wrongly applied the rationale that if the user hit escape we should gracefully exit, and while that seems a good idea to me, that isn't what you coded for. Somehow I didn't see your preface text or comment. Duh. I'm blaming it on last night's lousy sleep, which, Scout's honour is true, but also completely LAME.

 :whistle:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #23 on: October 31, 2005, 06:30:22 PM »
Quote
I had wrongly applied the rationale that if the user hit escape we should gracefully exit,

 :oops:   Oooops .. Me too
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getpoint <hopped-up>
« Reply #24 on: October 31, 2005, 06:34:27 PM »
OK, How about this?
Code: [Select]
  (setq promptmessage "Select a point"
        default       '(0.0 0.0 0.0)
  )

  (while
    (and
      ;(not (initget initbit initstring))
      (vl-catch-all-error-p
        (setq returnvalue (if basepoint
                             (vl-catch-all-apply 'getpoint (list promptmessage basepoint))
                             (vl-catch-all-apply 'getpoint (list promptmessage))
                          )
        )
      )
      (or
        (initget "Yes No")
        (/= (vl-catch-all-apply
              'getkword
              (list "Are you sure you want to abort?[Yes/No] <No>")
            )
            "Yes"
        )
        (exit)
      )
    )
  )
  (if returnvalue
    returnvalue
    default
  )
)
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #25 on: October 31, 2005, 06:37:56 PM »
Thats pretty close Alan

:)

This scares me a little :

(exit)


This whole topic is really interesting to me ..

« Last Edit: October 31, 2005, 06:46:11 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #26 on: October 31, 2005, 06:44:15 PM »
I supose the question needs to be raised.

What is the users expectation for termination of a routine ?

Should we discourage bashing the ESC key ?

Should we provide a "Quit" keyword ...

.. I think the decision to terminate operation should be made in the main code body .. so we perhaps just pass back a Symbol to reflect the users option .. ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: getpoint <hopped-up>
« Reply #27 on: October 31, 2005, 07:09:08 PM »
Included only for ideas ... I wrote this long ago, like < 1999, and abused it by adding escape code (should be completely rewritten but other stuff demands attention). Anyway, run and and observe the behavior if you wish, this is how I'd expect a function to behave when hitting escape.

Code: [Select]
(defun GetPoints ( / GetPointAux i point result cancelled )

    (defun GetPointAux ( from message / result )
        (setq cancelled ;; note, local global
            (vl-catch-all-error-p
                (vl-catch-all-apply
                   '(lambda ( )
                        (initget 32)
                        (setq result
                            (if from
                                (getpoint from message)
                                (getpoint message)
                            )
                        )
                    )
                )
            )
        )
        result
    )

    (cond

        (   (car
                (setq result
                    (list
                        (GetPointAux
                            nil
                            "\nPick start point: "
                        )
                    )
                )
            )

            (while
                (setq point
                    (GetPointAux
                        (car result)
                        "Next point: "
                    )
                )
                (grdraw point
                    (cadr
                        (setq result
                            (cons point result)
                        )
                    )
                    -7
                )
            )

            (setq i 0)

            (while (< i (1- (length result)))
                (grdraw
                    (nth i result)
                    (nth (setq i (1+ i)) result)
                    -7
                )
            )
           
            (if (null cancelled) ;; the local global
                (reverse result)
            )   
        )
    )
)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: getpoint <hopped-up>
« Reply #28 on: October 31, 2005, 07:14:30 PM »
So, perhaps you need to pass an Exit flag
 Allow Escape
 Prompt for Escape
 Return a flag to calling routine on escape
 Return nil on Escape
 No Escape allowed

Oops, MP snuck in there.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: getpoint <hopped-up>
« Reply #29 on: October 31, 2005, 07:54:36 PM »
........    What happens if the user enters an invalid point like
8 <enter>

I'vecome back to this ...
8 <enter> could be considered valid because of
the AutoCAD direct distance entry mechanism.

ie : return a point 8 units in the direction of the cursor

You were trying to trick me Alan, yes ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.