mathieucraveiro 发表于 2022-7-6 06:10:26

Multiple-choice questions

Hello everybody, there are a long time i don't come there. I hope you'll understand because i'm french and so.
 
I would like to make in autolisp a MCQ for my program.To make that, here is my algorithm:
 
ask the question: accept you this implantation? [ Yes / No ]
 
(there i want storing the value in a variable)
 
         if the answer is No, what do you want to change? [ tracking / Shift / first light fitting / Spacing / Gap ]
 
(there i want storing the value in a variable)
             if the answer is tracking> do that
             if the answer is Shift > do that
             if the answer is the first light fitting> do that
             if the answer is spacing> do that
             if the answer is Gap > do that
 
 
         if the answer is Yes, continue the program
 
Actually this MCQ will be in "while fonction" and i would like to have the opportunity to keep several values.
 
To know: each case is a function, first of all the program set all of these cases
and after this MCQ will be into this "while" function to ask customer if it is okay. I want to make that to have a possibility to come back at the desired step (steps)
 
 
Thank you everybody !

marko_ribar 发表于 2022-7-6 06:16:07

(defun c:MCQ ( / tracking shift first-light-fitting spacing gap loop ch change ) (defun tracking ( / )   ... ) (defun shift ( / )   ... ) (defun first-light-fitting ( / )   ... ) (defun spacing ( / )   ... ) (defun gap ( / )   ... ) (setq loop T) (while loop   (initget "Yes No")   (setq ch (getkword "\nAccept this implantation ? [ Yes / No ]: "))   (if (or (eq ch nil) (eq ch "No"))   (progn       (initget 1 "Tracking Shift First-light-fitting Spacing Gap")       (setq change (getkword "\nWhat do you want to change? [ racking / hift / irst-light-fitting / acing / ap ] : "))       (cond         ( (eq change "Tracking")         (tracking)         )         ( (eq change "Shift")         (shift)         )         ( (eq change "First-light-fitting")         (first-light-fitting)         )         ( (eq change "Spacing")         (spacing)         )         ( (eq change "Gap")         (gap)         )       );end cond       (setq loop T)   );end progn   (setq loop nil)   );end if );end while ... (princ));end defun MCQ(prompt "\nInvoke with : MCQ")(princ)

Lee Mac 发表于 2022-7-6 06:17:55

I would code the loop in the following way:

(defun c:test ( / ans )   (initget "Yes No")   (if (/= "Yes" (getkword "\nAccept this implantation? : "))       (while         (progn (initget "Tracking Shift First SPacing Gap")               (setq ans (getkword "\nChange : "))         )         (cond               (   (= ans "Tracking")                   (princ "\nTracking selected.")               )               (   (= ans "Shift")                   (princ "\nShift selected.")               )               (   (= ans "First")                   (princ "\nFirst light fitting selected.")               )               (   (= ans "SPacing")                   (princ "\nSpacing selected.")               )               (   (princ "\nGap selected."))         )       )   )   (princ "\nContinue with program...")   (princ))

mathieucraveiro 发表于 2022-7-6 06:21:28

Thank you very much Marko! it's very nice ! So , i have just some questions for you, i don't understand some things like why the "(setq loop T)" it's again there after the "end cond" ? Andsince the line "(princ)" included, i don't understandis the use ?
 
I would like to add two things :
 
The first : Each time that the customer make this choice for example Spacing , i would like to erase the drawing that the program have made ONLY, notall of thedrawing plan.
The second : Is to tell if the program it's ok we can continue the program
 
And one thing important is , there are a function just after " (defun gap ( / )...)" it's the functionwho draw the drawing
 
 
 
Thank you soo much

mathieucraveiro 发表于 2022-7-6 06:26:09

Thank you Lee Mac !both of your program are good for me but i would like to have a possibility to put inside the "cond" function one test with several results , it's possible or no?
 
 
Thank you soo much.

neophoible 发表于 2022-7-6 06:26:30

mathieucraveiro, have you already written the other functions (defuns) that will be the main part of this program?
 
What marko_ribar and Lee Mac showed you were the part you asked for, and yes, these will allow calls to other functions as marko_ribar shows.They also show that the program can continue.
 
As for princ by itself, it's just a quiet way to end the routine, without printing something extra to the screen at the end, such as "nil".
 
As for loop being set to T or nil, this is just the control variable to keep the while loop going or cause it to finish.
 
As for erasing the objects the program has created, just save the name of the last one using entlast. Do this before your program creates anything; then you can step through from there and delete all the new objects.
 
As for the gap defun, it was not clear to me what you were trying to say.Are you saying it is written or needs to be written or what?

mathieucraveiro 发表于 2022-7-6 06:31:44

Hello neophoible and thank you for your answer i understand better now about these functions. Actually it's not a function "gap" but the function just after "gap" who permit to draw, it's not done again . ThaNK YOU

neophoible 发表于 2022-7-6 06:35:19

You are welcome.Hope you get everything worked out now.

mathieucraveiro 发表于 2022-7-6 06:37:56

My program it's not finished but, it's a pleasure to continue when there are some peopleto help you when you are blocked   ! Have a good day !

mathieucraveiro 发表于 2022-7-6 06:40:29

Hello Everybody , i need to have some help because i would like to change the color of one entity polylign . First of all with an example :
 

(defun c:essai () (setq pt1 (getpoint "\n first point ")) (setq pt2 (getpoint "\n second point ")) (command "polylign" pt1 pt2 "") (setq entCouleur (entget (entlast))) (setq essai(subst '(62 . 2) '(62 . 1) entCouleur)) )
 
I thinking to use the "subst" function to remplace the old color by the new color.
 
Thereplacement into the list it's done but the entity polylign stay with the first color. I don't know why?
 
And after, i would like to tell at the programm to replace the color of the polylign even if the first color isn't inform.
 
 
Thank you
页: [1] 2
查看完整版本: Multiple-choice questions