Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calculation routine

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tommcgtx
397 Views, 3 Replies

Calculation routine

I am wondering if someone could help me with a lisp routine. I want to calculate GPM from two known factors. The formula I use is GPM = Q x √S, where Q is a factor and S is the slope. I want to be able to type a command, then be prompted to enter Q and then be prompted for S. I am not sure exactly how to go about this.

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: tommcgtx

Perhaps the simplest routine would be:

 

(defun c:gpm ( / q s )
    (initget 3)
    (setq q (getreal "\nSpecify Q: "))
    (initget 7)
    (setq s (getreal "\nSpecify S: "))
    (princ (* q (sqrt s)))
    (princ)
)

 

 

Message 3 of 4
tommcgtx
in reply to: Lee_Mac

Thanks alot! That works great. I hope to use this to learn a little more about AutoLisp, and perhaps modify it to accomplish other calcs. Thanks.

Message 4 of 4
Lee_Mac
in reply to: tommcgtx


@tommcgtx wrote:

Thanks alot! That works great. I hope to use this to learn a little more about AutoLisp, and perhaps modify it to accomplish other calcs. Thanks.


You're very welcome tommcgtx Smiley Happy

 

As I say, the code I posted is probably the most simple way to construct the routine whilst still incorporating all the error trapping required - though it could be expanded a great deal further.

 

To help you understand the code, I would suggest that you study each of the functions being used - the best reference is the Visual LISP IDE Help Documentation - for information on how to access this documentation, see my short tutorial here.

 

If you aren't already using the Visual LISP IDE provided with AutoCAD to write your LISP programs, I would strongly recommend it, since it provides all the syntax highlighting for AutoLISP, Visual LISP and DCL, and the best debugging utilities for AutoLISP among code editors. To help you get started with it, I have also written an introductory tutorial which may be of some help.

 

I hope this helps,

 

Lee

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost