Jump to content

Temperamental LISP - Sometimes it works, Sometimes it doesn't!


Hachi

Recommended Posts

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 by rkmcswain
add [CODE] tags
Link to comment
Share on other sites

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 by StevJ
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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

  • Thanks 1
Link to comment
Share on other sites

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)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 by Hachi
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))
)

 

image.png.69d517c427394ae1af497992bc6a54d2.png

Link to comment
Share on other sites

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))
)

 

image.png.69d517c427394ae1af497992bc6a54d2.png

 

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...