Visual LISP, AutoLISP and General Customization

## Visual LISP, AutoLISP and General Customization

Valued Contributor
Posts: 66
Registered: ‎01-22-2010
Message 1 of 4 (214 Views)

# Calculation routine

214 Views, 3 Replies
10-11-2011 10:55 AM

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.

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

*Expert Elite*
Posts: 1,270
Registered: ‎12-29-2009
Message 2 of 4 (210 Views)

# Re: Calculation routine

10-11-2011 11:13 AM 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)
)```

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

With Mathematics there is the possibility of perfect rigour, so why settle for less?
Valued Contributor
Posts: 66
Registered: ‎01-22-2010
Message 3 of 4 (198 Views)

# Re: Calculation routine

10-11-2011 12:06 PM 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.

*Expert Elite*
Posts: 1,270
Registered: ‎12-29-2009
Message 4 of 4 (185 Views)

# Re: Calculation routine

10-11-2011 01:35 PM 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

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

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

With Mathematics there is the possibility of perfect rigour, so why settle for less?
Post to the Community

Have questions about Autodesk products? Ask the community.