Hachi Posted December 17, 2020 Posted December 17, 2020 (edited) Hi guys! I did the first lsp of my life. It’s very simple, yet it doesn’t always work and I don’t understand what could be wrong. I turned off OSNAP. If anyone could help I would be very grateful. LSP: (defun c:LP() (setq a (getreal "Adja meg a profil szélességét:")) ; Add the width of L profile (setq b (getreal "Adja meg a profil magasságát:")) ; Add the length of L profile (setq szigma (getreal "Adja meg a profil vastagságát/lemezvastagságot:")) ; Add the thickness of plate (setq l (getreal "Adja meg a 3D profil hosszát:")); Add the length of 3D object (setq pt1 '(0 0)) (setq pt2 (polar pt1 0 (* szigma 2))) (setq pt3 (polar pt1 0 a)) (setq pt4 (polar pt3 (/ pi 2) szigma)) (setq pt5 (polar pt4 pi (- a (* szigma 2)))) (setq pt9 (polar pt1 (/ pi 2) (* szigma 2))) (setq pt8 (polar pt9 (/ pi 2) (- b (* szigma 2)))) (setq pt7 (polar pt8 0 szigma)) (setq pt6 (polar pt7 (* pi 1.5) (- b (* szigma 2)))) (setq pt10 (polar pt5 (/ pi 2) szigma)) (setq pt12 (polar pt10 (* pi 1.25) (* szigma 2))) (setq pt11 (polar pt10 (* pi 1.25) szigma)) (setq pt13 (polar pt10 (* pi 1.25) (* szigma 1.5))) (setq pt14 (polar pt4 (/ pi 4) szigma)) (setq pt15 (polar pt9 (* pi 0.75) szigma)) (setq k1 (polar pt1 0 (/ a 2))) (setq k2 (polar pt1 (/ pi 2) (/ b 2))) (command "vlánc" pt2 pt3 pt4 pt5 "") ; "polyline" (command "vlánc" pt6 pt7 pt8 pt9 ""); "polyline" (command "ív" pt5 pt11 pt6 ""); "arc" (command "párh" szigma pt11 pt1 ""); "offset" (command "_Join" k1 k2 pt11 pt12 "") (command "tolhúz" pt13 l "") "presspull" (princ) ) PS: Sorry for the not conventional language! Edited December 17, 2020 by rkmcswain add [CODE] tags Quote
StevJ Posted December 17, 2020 Posted December 17, 2020 (edited) Last time I had a program that worked 'sometimes' was because I had not localized my variables, and because some variable names were used in other programs, the initial values were incorrect. Steve Edited December 17, 2020 by StevJ 1 1 Quote
Steven P Posted December 18, 2020 Posted December 18, 2020 2 hours ago, StevJ said: Last time I had a program that worked 'sometimes' was because I had not localized my variables, and because some variable names were used in other programs, the initial values were incorrect. Steve if you change your first line: (defun c:LP() to (defun c:LP( / a b szigma l pt1.....) this localises your variables - meaning that their values will not be saved and carried over to another LISP or next time it is run. If you want a variable to do that, its value saved for later, then don't put it after the '/' if that makes sense 1 Quote
BIGAL Posted December 18, 2020 Posted December 18, 2020 If you open code in Vlide and check code the top line in "build" output will make a list of global variables you can copy and paste into the localise part of the defun saves a bit of time typing. Thanks to Lee-mac for that hint. an example of missing local variables. ; === Top statistic: ; Global variables: (A B K1 K2 L PT1 PT10 PT11 PT12 PT13 PT14 PT15 PT2 PT3 PT4 PT5 PT6 PT7 PT8 PT9 SZIGMA) 1 1 Quote
Hachi Posted December 21, 2020 Author Posted December 21, 2020 On 12/17/2020 at 10:03 PM, StevJ said: Last time I had a program that worked 'sometimes' was because I had not localized my variables, and because some variable names were used in other programs, the initial values were incorrect. Steve Thank you for Your time Steve! This is a very useful comment! Quote
Hachi Posted December 21, 2020 Author Posted December 21, 2020 (edited) On 12/18/2020 at 1:05 AM, Steven P said: if you change your first line: (defun c:LP() to (defun c:LP( / a b szigma l pt1.....) this localises your variables - meaning that their values will not be saved and carried over to another LISP or next time it is run. If you want a variable to do that, its value saved for later, then don't put it after the '/' if that makes sense Steven P thank you for your explanation. It's true! Edited December 21, 2020 by Hachi Quote
Hachi Posted December 21, 2020 Author Posted December 21, 2020 On 12/18/2020 at 1:16 AM, BIGAL said: If you open code in Vlide and check code the top line in "build" output will make a list of global variables you can copy and paste into the localise part of the defun saves a bit of time typing. Thanks to Lee-mac for that hint. an example of missing local variables. ; === Top statistic: ; Global variables: (A B K1 K2 L PT1 PT10 PT11 PT12 PT13 PT14 PT15 PT2 PT3 PT4 PT5 PT6 PT7 PT8 PT9 SZIGMA) BIGAL this is a very useful tool and good to keep in mind! Thank you very much. Quote
BIGAL Posted December 21, 2020 Posted December 21, 2020 Here is another for you.Multi GETVALS.lsp (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter values " "Width " 5 4 "100" "Length " 5 4 "200" "Thickness " 5 4 "10" "Height " 5 4 "100"))) (setq a (atof (nth 0 ans)) b (atof (nth 1 ans)) szigma (atof (nth 2 ans)) l (atof (nth 3 ans)) ) Quote
Hachi Posted December 22, 2020 Author Posted December 22, 2020 11 hours ago, BIGAL said: Here is another for you.Multi GETVALS.lsp (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter values " "Width " 5 4 "100" "Length " 5 4 "200" "Thickness " 5 4 "10" "Height " 5 4 "100"))) (setq a (atof (nth 0 ans)) b (atof (nth 1 ans)) szigma (atof (nth 2 ans)) l (atof (nth 3 ans)) ) Sorry BIGAL, but I'm not sure how to combine those 2 codes and my code together?....maybe all in 2 lisp. like this: 1 - At the begining of my "C:LP" lisp I have to add the block below (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter values " "Width " 5 4 "100" "Length " 5 4 "200" "Thickness " 5 4 "10" "Height " 5 4 "100"))) (setq a (atof (nth 0 ans)) b (atof (nth 1 ans)) szigma (atof (nth 2 ans)) l (atof (nth 3 ans)) ) 2 - After this goes my code 3 - Those two "blocks" are in the same file called: "LP.lsp" 3 - I have to add the "Multi GETVALS.lsp" to be loaded every time simultaneously with my "LP.lsp" file. Am I right? Quote
BIGAL Posted December 24, 2020 Posted December 24, 2020 If you want to use the multi getvals a lot just load it at start up I have it set that way. Just remove your setq a b szigma l and replace with above. You can set the default values to what you want "100" expert mode you can save the value entered so next time run it is the current value as default. Quote
Hachi Posted December 25, 2020 Author Posted December 25, 2020 Thank you BIGAL! A much nicer way to enter data Have a nice day brother 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.