Sponsored links

【AutoLISP FIRST STEP】 Function -Magic Spell to ask AutoCAD What to Do

Sponsored links
English
Sponsored links

With AutoLISP, we use a function to tell the computer what it has to do.

Let’s study from What is a FUNCTION

Sponsored links

Function ?

When I started using AutoCAD, I heard that …..

If you know AutoLISP, you can make your AutoCAD life super duper easy! 

Then I thought

Jagaimo
Jagaimo

Oh, I would like to make my job easier♪

So, I started searching about AutoLISP.

However, since I didn’t have any knowledge of programing, I was limited by terminology such as functions, variables, arguments etc…

Jagaimo
Jagaimo

I’ve heard of them with Mathematics class…. 

are they numbers?  

I was so confused, so I think starting with the terminologies may help beginners to study AutoLISP.

Magic Spell to ask AutoCAD what to do

Jagaimo
Jagaimo

Function is a special word used to perform a specific task.
Programing is gathering functions to make another new function.

Now, Let’s see what kind of magic spells we have.

If you go to Autodesk’s help page, you can see the Index of AutoLISP Functions

There are a looooooooooooooooooots, but most people may use only a part of them.

How to Use a Function

Here, I’ll talk about how to use AutoLISP function.

There are some exceptions, but, basically, one function needs one pair of ( ).

(function ………… )

Start with ( , next function name, then required information for the function, and finish with )

Example of Function “alert”

the role of alert

Let’s see an example of a function called alert in the Autodesk Help page.

The role of alert is

Display a dialog box containing an error or warning message.

For your information,
”a dialog box containing a message” means ↓ this ↓

So, the Magic Spell to ask AutoCAD “Show a Message Dialog box” is alert.

Let’s start AutoLISP programing

What I want to tell the AutoCAD is

Jagaimo
Jagaimo

Display a dialog box with message “Hello World”

We need translate it in AutoLISP language.
Let’s check the Help page about alert again.

You can see

(alert msg)

msg Type: String

It means that to execute alert, you need message which type is String.


In AutoLISP rule, String is texts including spaces and numbers between ” “.

Jagaimo
Jagaimo

(alert “Hello World”)

If AutoCAD understands this AutoLISP, AutoCAD will display

 

Let’s Communicate with AutoCAD

AutoLISP can be read from Command Line in AutoCAD.

Please open your AutoCAD and try to input the code below on the command line and to press Enter.

(alert "Hello World")

Is the command line missing on your AutoCAD?

CTRL+9 is the shortcut to toggle on the command line.

Or, use command “commandline” to display command line.

AutoCAD got your message “Display a dialog box with message Hello AutoLISP”, and AutoCAD shows a dialog box.

You did it!
You could communicate with AutoCAD!!

Like this, AutoLISP is a Language you can tell what you want AutoCAD to do.

If you can communicate correctly, surely AutoCAD can do the work, and it is aciculate and fast.

You might experience a lot of frustration by studying a new language.

Don’t give up.

Use AutoLISP wherever you understood, study diligently to be able to communicate properly with AutoCAD.

Jagaimo
Jagaimo

It’s a language.

The more often you use AutoLISP, more you will get it.

To Sum Up

  • Each Function has own task.
  • Start with (function_name , and finish with )
  • You can tell AutoCAD what to do with AutoLISP Function.
  • For example, you can tell AutoCAD to display a message box with alert.

Related Article

List of my Frequently Use AutoLISP functions

Comments