Jump to content

Multiple Math Functions in a Lisp String


Therriault

Recommended Posts

I'm trying to write a routine to draw a style of cover that we use regularly, but I'm having trouble getting past the math functions in lisp. I should clarify that I don't have a clue on .lsp programing; so any help must take that into consideration to save both of us a lot of headaches.

 

Here is what I have so far:

 

(defun c:SBC ()

(defun dtr (deg)

(* deg (/ pi 180))

)

(setvar "cmdecho" 0)

 

; Data Input

 

(prompt "\nENTER ALL DIMENSIONS IN DECIMALS ")

(setq mthk (getreal "\nEnter Material Thickness: "))

(setq ikr (getreal "\nEnter Cover I/S Knuckle Radius: "))

(setq csf (getreal "\nEnter Cover Straight Flange: "))

(setq covrad (getreal "\nEnter Cover I/S Radius: "))

(setq covlng (getreal "\Enter Cover I/S Length: "))

(prompt "\nEnter Lip I/S Dimension: : "))

(if (= lip nil) (setq lip 0.4375))

(prompt "\nEnter Hinge I/S Width: : "))

(if (= hw nil) (setq hw 1.0))

(setq hdp (getreal "\nEnter Hinge I/S Depth: "))

 

; Calculations

 

;Inside Bend Radius

(setq isbr (/ mthk 2))

;Included Bend Angle at Lip

(setq iba1 (dtr 90))

;Centerline Bend Radius

(setq cbr1 (= mthk))

;Centerline Arc Length at Lip

(setq cal1 ((* cbr1 2 pi iba1) / 360)))

;Centerline Arc Length/2 at Lip

(setq hafcal1 (cal1 / 2))

;Centerline Bend Radius at Flange

(setq cbr2 ((mthk / 2) + ikr)

;Included Bend Angle at Flange

(setq iba2 (angle 90))

;Centerline Arc Length at Flange

(setq cal2 (cbr2 * 2 * pi * iba2 / 360))

;Circle Blank Radius

(setq cirbr (covrad - ikr + cal2 + csf))

)

Link to comment
Share on other sites

Assuming your math is correct and your intent, then below should work alright:

;Inside Bend Radius
(setq isbr (/ mthk 2)) 
;Included Bend Angle at Lip
(setq iba1 (dtr 90))
;Centerline Bend Radius
(setq cbr1 mthk)
;Centerline Arc Length at Lip
(setq cal1 (/ (* cbr1 2 pi iba1) 360)))
;Centerline Arc Length/2 at Lip
(setq hafcal1 (/ cal1 2))
;Centerline Bend Radius at Flange
(setq cbr2 (+(/ mthk 2) ikr)
;Included Bend Angle at Flange
(setq iba2 (angle 90))
;Centerline Arc Length at Flange
(setq cal2 (/ (* cbr1 2 pi iba2) 360))
;Circle Blank Radius
(setq cirbr (- covrad (+ ikr cal2 csf)))

Link to comment
Share on other sites

I've gotten past my last hurdle, now after running the routine I am able to input the data, and the all of the drawings from the routine seem to function but I get the following:

 

Pick Formed End View Location: Unknown command "SBC". Press F1 for help.

*Invalid*

*Invalid*

*Invalid*

*Invalid*

*Invalid*

*Invalid*

*Invalid*

Unknown command "SBC". Press F1 for help.

*Invalid*

Unknown command "SBC". Press F1 for help.

The routine is attached.

 

Thanks!

SBC.lsp

Link to comment
Share on other sites

some changes

(setq lip (getreal "\nEnter Lip I/S Dimension: <0.4375>")) 
(setq isbr (/ mthk 2.0)) ; if mthk is a Int value like 3 you may not get 1.5 better to divide with a real
; just me 
(setq dtr90 (/ pi 2.0)) (setq dtr180 pi) (setq dtr270 (* 1.5 pi)); put this at start use variable in code dtr 0 is 0.0
(setq ev2 (polar ev1 dtr90 lbcp))
(command "CLAYER" "03-OBJECT LINE 3" "")  ; me  (setvar "clayer" "CLAYER" "03-OBJECT LINE 3")

 

If your going to do this type of thing all the time you could make a DCL that is a universal multiline input you can pass the request detail so it can ask many questions have a look at this

 

;; Input  Dialog box with variable title
;; By Ah June 2012
;; code (ah:getval title)
(defun AH:getval (title width limit / fo)
(setq fname "C://acadtemp//getval.dcl")
(setq fo (open fname "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "sizze" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
;(write-line "     edit_width = 18;" fo) 
;(write-line "     edit_limit = 15;" fo)
(write-line width fo) 
(write-line limit fo)
(write-line "   is_enabled = true;" fo)        
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_cancel;}" fo)
(close fo)
(setq dcl_id (load_dialog  "c:\\acadtemp\\getval"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "sizze" "(setq item  $value)(done_dialog)")
(mode_tile "sizze" 3)
(start_dialog)
; returns the value of item
)

Link to comment
Share on other sites

Thanks,

 

I'll try those suggestions.

 

Any idea as to the reason for the error after the script runs, just for my information, as I don't know the cause?

Link to comment
Share on other sites

OK, I found the problem. By changing CMDECHO to 1 and following the process I found that I was missing a step in the PLINE ARC, specifically the DIRECTION step. In the PLINE sequence I added "D" after each "A" and solved the issue.

 

Thanks,

 

Bill T.

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