Author Topic: setting initget within while  (Read 7608 times)

0 Members and 1 Guest are viewing this topic.

SMadsen

  • Guest
setting initget within while
« Reply #15 on: August 10, 2004, 06:19:41 AM »
Daron, I would use the ARC command as you do it, also. About the undo option, I would build a list of points as the command progresses and use those points to backtrace during undo sessions.

Below is my suggestion for implementing the undo mechanism. I'll let the comments take over further explanation:

Code: [Select]
(defun c:aet (/ ptpnt endpnt lpnt stpnt pmpt undolst cmde init omod pmp)
  (setq cmde (getvar "cmdecho")
        omod (getvar "orthomode")
  )
  (setvar "cmdecho" 0)
  (setvar "orthomode" 0)
  ;; instead of LASTPOINT (which can be set by numerous actions), I'd
  ;; suggest that you use a dedicated global point to continue from.
  ;; first, check if the global holds a point list
  (cond ((vl-consp *aet_pt*)
         ;; ok, global point exists (highly probable at least)
         ;; go set up the prompt and initget option .. also set
         ;; lpnt to the global point
         (setq pmp  "\nSelect start point of arc or [<C>ontinue]: "
               init "Continue"
               lpnt *aet_pt*
         )
        )
        ;; no global exists .. just ask for initial point with no
        ;; initget options
        ((setq pmp  "\nSelect start point of arc: "
               init 0
         )
        )
  )
  ;; go ask for point or option
  (initget init)
  (setq stpnt (getpoint pmp))
  ;; check result
  ;; if "Continue" or nothing then simply jump right into the loop
  (cond ((or (not stpnt) (= stpnt "Continue")))
        ;; if not the above, get endpoint and start to build the
        ;; undo data list. Because CMDECHO is off, help the user
        ;; by issuing the standard prompt at the user input
        ((setq endpnt (getpoint stpnt "\nSelect end point of arc: "))
         (princ
           "\nSpecify tangent direction for the start point of arc: "
         )
         (command ".arc" stpnt "e" endpnt "d" pause)
         (setq lpnt    endpnt
               undolst (list stpnt)
         )
        )
  )
  ;; initialize the loop prompt
  (setq pmp "\nSelect end point or [Undo]: ")
  (while
    (progn (initget "Undo")
           (setq pmpt (getpoint lpnt pmp))
    )
     ;; if Undo, then first check the undo data and see if it's
     ;; even possible to undo (otherwise do nothing but tell there
     ;; is nothing to undo)
     (cond ((= pmpt "Undo")
            (cond ((not undolst) (princ "Nothing to undo"))
                  ;; if undo data exists: go erase the last arc,
                  ;; reset lpnt to first occurence in the undo list
                  ;; and chop off the "undid" point from the undo list
                  (T
                   (command ".ERASE" "Last" "")
                   (setq lpnt    (car undolst)
                         undolst (cdr undolst)
                   )
                  )
            )
           )
           ;; if point is received: go draw the arc, append point
           ;; to the undo list and set lpnt to the new point.
           ;; again, help the user by issuing the standard prompt
           (pmpt
            (princ
              "\nSpecify tangent direction for the start point of arc: "
            )
            (command ".ARC" lpnt "E" pmpt "D" pause)
            (setq undolst (cons lpnt undolst)
                  lpnt    pmpt
            )
           )
     )
     ;; adjust prompt to reflect the status of the undo data
     (setq pmp (if undolst
                 "\nSelect end point or [Undo]: "
                 "\nSelect end point: "
               )
     )
  )
  ;; put last point up for later continuance
  (setq *aet_pt* lpnt)
  (setvar "cmdecho" cmde)
  (setvar "orthomode" omod)
  (princ)
)

daron

  • Guest
setting initget within while
« Reply #16 on: August 10, 2004, 07:51:00 AM »
Thank you Stig. I'll go test it and learn to better understand it.

SMadsen

  • Guest
setting initget within while
« Reply #17 on: August 10, 2004, 08:17:02 AM »
You're welcome. Now to the home assignment: Implement a redo mechanism :)

daron

  • Guest
setting initget within while
« Reply #18 on: August 10, 2004, 02:18:18 PM »
Now that's something I hadn't even considered, but I'm not sure I see the need. I'll see what I can do though.

SMadsen

  • Guest
setting initget within while
« Reply #19 on: August 10, 2004, 03:55:58 PM »
Who needs a need?

I was just trying to be amusing. Hope you can use the code I posted, Daron.

daron

  • Guest
setting initget within while
« Reply #20 on: August 10, 2004, 04:20:36 PM »
The code you posted is awesome. I've been using it all day. As far as a need goes, I'm going to try and improve on it by adding a line function and better than a redo function, I'd like to add a close function to it. I hope others find it useful, too.

Thanks again, Stig.

CADaver

  • Guest
setting initget within while
« Reply #21 on: August 11, 2004, 10:56:26 AM »
A possible refinement maybe???

Build a selection set as you go, then PEDIT the whole thing into a single pline when you're done?

daron

  • Guest
setting initget within while
« Reply #22 on: August 11, 2004, 02:42:27 PM »
Good idea. I'd like to get the line portion worked out before attempting that though. If you want to write a module for doing that, it might be a good exercise.

CADaver

  • Guest
setting initget within while
« Reply #23 on: August 11, 2004, 04:17:35 PM »
Quote from: Daron
Good idea. I'd like to get the line portion worked out before attempting that though. If you want to write a module for doing that, it might be a good exercise.
umm... remember who yer talking to??  ...the thief/hack/cad-slug?? ...the only reason I kin rite my name is mom has it stenciled on my boxers.

daron

  • Guest
setting initget within while
« Reply #24 on: August 12, 2004, 08:11:37 AM »
Mmm. I thought you knew a little. No activeX here. All unleaded lisp. We're even using command.