mathieucraveiro Posted July 7, 2013 Posted July 7, 2013 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 ! Quote
marko_ribar Posted July 7, 2013 Posted July 7, 2013 (edited) (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 ] <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? [ [T]racking / [s]hift / [F]irst-light-fitting / [sP]acing / [G]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) Edited July 7, 2013 by marko_ribar changed [S]pacing to [SP]acing and added ... at the end for the rest of the code after while ends (finished settings) Quote
Lee Mac Posted July 7, 2013 Posted July 7, 2013 I would code the loop in the following way: (defun c:test ( / ans ) (initget "Yes No") (if (/= "Yes" (getkword "\nAccept this implantation? [Yes/No] <No>: ")) (while (progn (initget "Tracking Shift First SPacing Gap") (setq ans (getkword "\nChange [Tracking/Shift/First light fitting/SPacing/Gap] <Accept>: ")) ) (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) ) Quote
mathieucraveiro Posted July 7, 2013 Author Posted July 7, 2013 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" ? And since the line "(princ)" included, i don't understand is 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, not all of the drawing 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 function who draw the drawing Thank you soo much Quote
mathieucraveiro Posted July 8, 2013 Author Posted July 8, 2013 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. Quote
neophoible Posted July 9, 2013 Posted July 9, 2013 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" ? And since the line "(princ)" included, i don't understand is 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, not all of the drawing 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 function who draw the drawing 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? Quote
mathieucraveiro Posted July 11, 2013 Author Posted July 11, 2013 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 Quote
neophoible Posted July 12, 2013 Posted July 12, 2013 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 YOUYou are welcome. Hope you get everything worked out now. Quote
mathieucraveiro Posted July 16, 2013 Author Posted July 16, 2013 My program it's not finished but, it's a pleasure to continue when there are some people to help you when you are blocked ! Have a good day ! Quote
mathieucraveiro Posted July 24, 2013 Author Posted July 24, 2013 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. The replacement 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 Quote
Lee Mac Posted July 24, 2013 Posted July 24, 2013 Please study the following example carefully: ([color=BLUE]defun[/color] c:essai ( [color=BLUE]/[/color] col enx pt1 pt2 ) [color=GREEN];; Define function, declare local variable symbols.[/color] [color=GREEN];; To understand why variable declaration is important,[/color] [color=GREEN];; see [url]http://lee-mac.com/localising.html[/url][/color] ([color=BLUE]if[/color] [color=GREEN];; If the following expression returns a non-nil value[/color] ([color=BLUE]and[/color] [color=GREEN];; All of the supplied expressions must return a non-nil[/color] [color=GREEN];; value for AND to return T. AND will cease evaluating[/color] [color=GREEN];; expressions when an expression returns nil, or when[/color] [color=GREEN];; all expressions have been evaluated.[/color] ([color=BLUE]setq[/color] pt1 ([color=BLUE]getpoint[/color] [color=MAROON]"\n1st Point: "[/color])) [color=GREEN];; Prompt user for 1st point[/color] [color=GREEN];; e.g. pt1 = (123.0 456.0 0.0)[/color] ([color=BLUE]setq[/color] pt2 ([color=BLUE]getpoint[/color] [color=MAROON]"\n2nd Point: "[/color] pt1)) [color=GREEN];; Prompt user for 2nd point, rubber-band to 1st point[/color] [color=GREEN];; e.g. pt2 = (567.0 789.0 0.0)[/color] ) [color=GREEN];; end AND[/color] ([color=BLUE]progn[/color] [color=GREEN];; Evaluate the following expressions and return the result[/color] [color=GREEN];; of the last expression evaluated. PROGN is used as a[/color] [color=GREEN];; wrapper function so that we can pass multiple expressions[/color] [color=GREEN];; to the IF function as a single argument constituting the[/color] [color=GREEN];; 'then' parameter.[/color] ([color=BLUE]command[/color] [color=MAROON]"_.pline"[/color] [color=MAROON]"_non"[/color] pt1 [color=MAROON]"_non"[/color] pt2 [color=MAROON]""[/color]) [color=GREEN];; Invoke the PLINE command[/color] [color=GREEN];; Command prefix meanings:[/color] [color=GREEN];; "_" = use the English version of the command/keyword[/color] [color=GREEN];; "." = use a non-redefined version of the command[/color] [color=GREEN];; "non" = Object Snap modifier equal to "None" to ignore Object Snap for the next point[/color] ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]entlast[/color]))) [color=GREEN];; Retrieve the DXF data of the last entity added to the drawing database[/color] [color=GREEN];; More error trapping is potentially required here to ensure that the[/color] [color=GREEN];; LWPolyline was created successfully and is indeed the last entity[/color] [color=GREEN];; added to the drawing database, but I shall omit this to retain the[/color] [color=GREEN];; simplicity of this example.[/color] [color=GREEN];; e.g. enx = ((0 . "LWPOLYLINE") (5 . "ABC") (90 . 2) (70 . 0) ... )[/color] ([color=BLUE]if[/color] ([color=BLUE]setq[/color] col ([color=BLUE]assoc[/color] 62 enx)) [color=GREEN];; If the DXF data contains DXF group 62, assign this pair to the local variable 'col'[/color] [color=GREEN];; Entities with colour set to ByLayer will not contain a[/color][color=GREEN] DXF group 62 pair.[/color] [color=GREEN];; e.g. col = (62 . 3) or col = nil[/color] ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] '(62 . 2) col enx)) [color=GREEN];; If DXF group 62 is present, i.e. 'col' is non-nil,[/color] [color=GREEN];; substitute the DXF group 62 pair for a new pair within the[/color] [color=GREEN];; DXF data, and use ENTMOD to update the DXF data in the drawing database.[/color] ([color=BLUE]entmod[/color] ([color=BLUE]append[/color] enx '((62 . 2)))) [color=GREEN];; Else, the entity colour was set to ByLayer and 'col' = nil[/color] [color=GREEN];; so append a new DXF group 62 pair to the DXF data and use[/color] [color=GREEN];; ENTMOD to update the DXF data for the entity in the drawing database.[/color] ) [color=GREEN];; end IF[/color] ) [color=GREEN];; end PROGN[/color] ) [color=GREEN];; end IF[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Supress the return of the last evaluated expression[/color] ) [color=GREEN];; end DEFUN[/color] Quote
mathieucraveiro Posted July 24, 2013 Author Posted July 24, 2013 Thank You Lee Mac !!! really really good explained, nothing to tell. Quote
Lee Mac Posted July 24, 2013 Posted July 24, 2013 Excellent, I'm glad my explanations were comprehensible. You're very welcome Mathieu. Quote
mathieucraveiro Posted July 27, 2013 Author Posted July 27, 2013 Hello everybody, i come back in this post because , i would like to have a possibility to get back every name's block "assistant" in my drawing to erase it. How i can to do? And if i'ts possible to have some explanation of every details about this function "ssget" because i don't understand for example : "_+.:E:S" there it's that i can find in a french post but i don't understand. Thank you Quote
mathieucraveiro Posted July 28, 2013 Author Posted July 28, 2013 Hello , it's fine i have just find the code to get back my "assistant" blocks. It was to erase it. you can see by the join picture "assistant", my blocks on continuation of the polylign but that it's just a litle help for the user choose which side he wants to have these lightings. Actually the polylign it's the lighting network. After this part, i'm blocked to get back each litle "polylign" who represent the jonction betwen the main network and lightings when you can show in the join picture " explanations". I hope you will understand because i know it's long and maybe i don't use the good word to explain me. So tell me if you are not understand something. I continue my program by steps and there i'm blocked to get back my entities Below the actually code who permit to draw the jonction betwen the main network and my lightings. (defun DECAL_CANDE (/ rep n pt3) ;;rappel : red: en haut ;; blue: en bas (initget "red blue") (setq rep (getkword "\n which side want to put your lightings? [red/blue] <red> : " ) ) (setq jsBlock (ssget "_A" (list '(0 . "INSERT") '(2 . "assistant")))) (command "_erase" jsBlock "") ; there i tell at the program to erase my "assistant" blocks to draw the jonction. (if (or (eq rep "red") (eq rep "R") (eq rep "")); if the answer is red we draw on this side (progn ;draw in the red side (foreach n lst_pt ; lst_pt contain the list with each point of insert lighting blocks, (variable set in other code) (setq pt3 (polar n (+ orient (/ pi 2)) decalageCandelabre) ; "decalageCandelabre" is the distance betwen the main network and the lighting pt4 (polar n (+ orient pi) (/ decalageCandelabre 2)) pt5 (polar n (+ orient 0) (/ decalageCandelabre 2)) ) (command "polylign" n pt3 "") ; i have to get back entitie (command "polylign" n pt4 "") ; i have to get back entitie (command "polylign" pt4 pt3 "") ; i have to get back entitie (command "polylign" n pt5 "") ; i have to get back entitie (command "polylign" pt5 pt3 "") ; i have to get back entitie (command "inserer" ; this command it's for insert the lightings blocks but it doesn't work for the moment "C:/pgn_mat/Blocs/candelabre3.dwg" n 1 1 (* (/ orient pi) 180.0) "" ) ) (progn (foreach n lst_pt (setq pt6 (polar n (+ orient (- (/ pi 2))) decalageCandelabre) pt7 (polar n (+ orient 0) (/ decalageCandelabre 2)) pt8 (polar n (+ orient pi ) (/ decalageCandelabre 2)) ) (command "polylign" n pt6 "");; i have to get back entitie (command "polylign" n pt7 "");; i have to get back entitie (command "polylign" pt7 pt6 "");; i have to get back entitie (command "polylign" n pt8 "");; i have to get back entitie (command "polylign" pt8 pt6 "");; i have to get back entitie ) (command "inserer" ; this command it's for insert the lightings blocks but it doesn't work for the moment "C:/pgn_mat/Blocs/candelabre3.dwg" n 1 1 (* (/ orient pi) 180.0) "" ) ) ) ) THANK YOU I had prepare some pictures to show you but i don't arrive to insert it i'm sorry Quote
mathieucraveiro Posted July 28, 2013 Author Posted July 28, 2013 there is another site in french where we can see the pictures of my program http://cadxp.com/topic/37941-probleme-gisement-abscisse-sur-une-droite/page__st__40 THANk you Quote
mathieucraveiro Posted July 28, 2013 Author Posted July 28, 2013 i'm sorry but you cannot to se pictures in this website because we had to register :/ Quote
Lee Mac Posted July 28, 2013 Posted July 28, 2013 And if its possible to have some explanation of every details about this function "ssget" because i don't understand for example : "_+.:E:S" See the ssget reference I have attached to this post. [ may require membership to view the attachment ] Quote
mathieucraveiro Posted July 28, 2013 Author Posted July 28, 2013 Thank you Lee i understand now but it's strange because in the help documentation of lisp it's not write. So have you read my last post Lee. I'm blocked to get back my entities, i would like to get back it in the list variable with function (list x) ... Thank you Quote
mathieucraveiro Posted September 4, 2013 Author Posted September 4, 2013 Hello Every body i have a problem to break my polylign Actually i want to use this command and to break in two points my polylign But the problem is i don't want that its the user chose two points and the entity polylign with (entsel) and (getpoint) I know already my points (PT2 PT3) and my polylign name's "polyReseau" So when i use the command "_break" : (command "_break" ent "1" PT3 PT4) The command does not recognize PT2 and PT4. Someone can help me ?? Thank you Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.