KRBeckman 发表于 2022-7-6 11:27:35

More AutoCAD-like programs

I'm trying to modify some of my lisps to make them look more like standard autocad commands and I'm wondering if anybody has some examples of how to do it.
 
What I'm trying to do is replace the 5 user text inputs with one menu of options that can be changed by first selecting what you want changed, then entering what you want the new value to be.
 
I'm not sure if this explains it very well, so I'll give an example...
 
I have a lisp that makes creating consecutive 3-d faces faster and easier by hidding neccessary edges and saving the verticies of the previous face so that a couple of them can be used for the following face (eliminates having to click on points twice, once for each face).
 
When I activate this lisp it first asks what type of face (first, middle, or last), then type of array (rectangular or circular), after that it asks if you want to switch back and forth between selecting the 3rd point before the 4th point and selecting the 4th point before the 3rd point (makes surfacing larger areas alot faster by eliminating alot of the zoom and panning), then which layer (current, temp, or name), finally whether or not you want to hide the inside edges.
 
What I would like to do is create a menu of options, kinda like the menu that comes up when you do a PEDIT:
 
Enter an option :
 
But have itcome up like this:
 
Enter and option :
 
And the user can change the settings he/she wants to, or just hit enter to continue the lisp.
 
I know how to make the prompt and strings, I just don't know how to loop back to the original prompt once a setting is changed.
 
Any help would be greatly appriciated.

Lee Mac 发表于 2022-7-6 11:31:02

Perhaps make use of the WHILE function coupled with a few conditionals

KRBeckman 发表于 2022-7-6 11:37:06

Any chance you've got an example, I learn easiest from examples.

Lee Mac 发表于 2022-7-6 11:39:25

Silly example:
 

(defun c:test (/ tot choice egg bac) (setq tot 0)(while   (progn   (initget "Checkout Eggs Bacon")   (setq choice (getkword "\nWhat you wanna do? : "))   (cond ((or (eq "Checkout" choice)                  (not choice))            (princ (strcat "\nTotal = £" (itoa tot))) nil)         ((eq "Eggs" choice)            (if (setq egg (getint "\nHow Many Eggs do you want? : "))                (setq tot (+ tot (* 2 egg))))            t)         (t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))                (setq tot (+ tot (* 3 bac))))            t)))) (princ))

KRBeckman 发表于 2022-7-6 11:41:28

lol, didn't mean you had to write it up, but I appriciated it... so what did you have for breakfast this morning?

Lee Mac 发表于 2022-7-6 11:43:57

lol neither eggs or bacon actually
 
This may be a more intuitive approach to follow:
 

(defun c:test (/ tot choice egg bac ExitFlag) (setq tot 0) (while (not ExitFlag)   (initget "Checkout Eggs Bacon")   (setq choice (getkword "\nWhat you wanna do? : "))   (cond ((or (eq "Checkout" choice)                (not choice))            (princ (strcat "\nTotal = £" (itoa tot)))            (setq ExitFlag t))         ((eq "Eggs" choice)            (if (setq egg (getint "\nHow Many Eggs do you want? : "))            (setq tot (+ tot (* 2 egg)))))         (t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))            (setq tot (+ tot (* 3 bac))))))) (princ))

KRBeckman 发表于 2022-7-6 11:48:18

I know in this case it works fine to do it the way you did, but would it make sense to change:
 

(t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))            (setq tot (+ tot (* 3 bac)))))))
 
To:
 

((eq "Bacon" choice)            (if (setq bac (getint "\nHow Many rashers of Bacon? : "))            (setq tot (+ tot (* 3 bac)))))))
 
I didn't know if this would be easier to understand if you came back to your program and needed to make a change a couple years down the road.
 
Also what does the "(t " this line do:
 

(t (if (setq bac (getint "\nHow Many rashers of Bacon? : "))

Lee Mac 发表于 2022-7-6 11:49:52

 
Perhaps, the responses are controlled by the initget function, so it makes no difference.
 
 
It ensures the last condition is met.

KRBeckman 发表于 2022-7-6 11:54:23

gotcha, thanks for you help. Btw, if I ever make it accross the lake to London, I'm buying you a beer.

Lee Mac 发表于 2022-7-6 11:57:33

You're welcome, thanks
页: [1] 2
查看完整版本: More AutoCAD-like programs