Sponsored links

【AutoLISP FIRST STEP】What is a Return Value?

Sponsored links
English
Sponsored links
Jagaimo
Jagaimo

A Return is a reply from AutoCAD when you use AutoLISP.

Sponsored links

What is a Return Value?

AutoLISP is a language to communicate with AutoCAD.

Therefore, it’s not one-way. We’ll receive reply from AutoCAD. It is called a Return Value.

For Example

If you want to know the current layer, you can get the information with AutoLISP.

(getvar “clayer”) is the code.

Jagaimo
Jagaimo

(getvar “clayer”)

“0”

Please try to input the code below in your command line.

(getvar "clayer")

If your AutoCAD’s current layer is “0”, AutoLISP will return the value “0”.

In this case, “0” is the Return Value of the (getvar “clayer”)

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.

Saving a Return Value

A Return Value is only displayed on the command line.
If you want to use the return Value in the program, you have to keep the information.

In this case, a variable is the way to save it.

Here, lets try to keep the current layer name in symbol Ly.

This code below is the code. Please input it in your command line.

(setq Ly (getvar "clayer"))

Now, the current layer name is in LY.

You can check a value of a variable with !Variable_Name

So, if you want to check the variable LY, you should input….

!Ly

on your AutoCAD’s command line.
Then, the current layer name, the value of LY, will be on the command line.

If you want to know more about Variable, please check this article.

To Sum Up

  • A Return Value is a reply from AutoCAD.
  • A Return Value is only displayed on the command line, so usually it is used with a variable.

Related Articles

In AutoLISP, Yes/No is T/nil

How to save variables on the computer.

Comments