Jump to content

how to write lisp program


srinu_vasu38

Recommended Posts

Dear Sir,

i had 3 years experience in 2d, but i want to work with less effort and give more out put. To acheive it, i want to learn how to write lisp program. how to write lisp program, please explain in breif to achieve this. I would be great full for u.

thanks

Link to comment
Share on other sites

There are a lot of great sites to learn how to write autolisp and visual lisp including this site. Check out

:http://www.afralisp.net/

http://www.jefferypsanders.com/autolisptut.html

http://ronleigh.info/autolisp/index.htm

 

a good place to start is in autocad itself.

In AutoCAD go to the tools menu then select autolisp the select visual lisp editor.

This will start up the autolisp environment where you can write programs.

In the visual lisp display go to the help menu and start reading. Don’t worry about it masking a lot of sense at first just get acquainted with the help files and how to navigate around in it.

The best way to learn is to have a project in mind that you want to write and start trying to write it and ask questions along the way.

LISP stand for list processing because LISP processes one line at a time. Some will say that it stans for “lost in stupid parentheses” because in lisp for every open parentheses “(“You must have a closed parentheses “)”.

Here is an example of a simple lisp

(defun c:test ( )

(alert “Hello World”)

);_end defun

you start with a open parentheses ( the use the defun function

if you use the C: before the calling text it tells autocad that the following text is the command line text to start the program. So if you load the example and type test on the autocad command line the program will execute.

The open and closed parentheses after the C:test is where you will place arguments and localize variables.

The line (alert “Hello World”) is using the alert function to display the AutoCAD alert dialog box and display the text “Hello World

The closed parentheses is the end of the open parentheses before the word defun. Remember you must have closed parentheses for every open parenthesis.

Here is an example that uses variables

(defun c:test2 ( / var1 var2 result)

(setq var1 1)

(setq var2 3)

(setq result (+ var1 var2))

);_defun

In the above example I have declared 3 variables: var1 & var2 & result

I set var1 to = 1 and var2 to = 3

Then I set the variable result to hold the result of adding var1 and var2

When the program is executed the variable result will equal 4

Here is a example of passing arguments between 2 defuns

 

(defun c:test3 (/ num1 num2 retval)

(setq num1 (getint “Enter A Number”));_ask user to input a number

(setq num2 (getint “Enter Another Number”));_ask for another user number

(setq retval(test4 num1 num2));_call to the test4 defun and return the answer

);_defun

 

(defun test4 (aug1 aug2 / result)

(setq result (+ aug1 aug2));_add 2 numbers together

);_defun

 

In the above example I have made 2 defuns C:test3 and test4. Notice test4 has no c: in front of it because we are using it as a sub-function to be called by the program not the command line.

C:test3 has 3 local variables and ask the uses the getint function to ask the use to type in 2 numbers. Then it makes a call with (setq retval(test4 num1 num2)) to call the defun test4 and passes it 2 variables that now contain the users typed in numbers.

The contents of each variable is passes to aug1 and aug2 of the test4 defun

Then we add them together and the answer is held in the variable

”result”

When the defun test4 is finished it passes back the result to the original calling function

(setq retval(test4 num1 num2)) and stores the answer in the variable retval.

Are you confused yet?

 

Read the help files and ask questions but do the work. You will learn more when you make mistakes than if some one spoon-feeds you answers.

 

Good luck

Link to comment
Share on other sites

  • 9 years later...

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