AutoLISP.2: Programming with Visual LISP editor.



Author Orhan Toker
Profession Architect M.Sc.
  Autodesk Authorized Consultant
  Database Specialist
e-mail  

Autocad 2002 and higher versions

 

Get organized…

Whichever programming language you are using, if you would like to develop programs in a serious manner, you have to be organized. If you want to develop an AutoLISP program with VLISP, you have to go through the stages specified below.

• Determine what your program will do and plan how you will approach to these processes.
• Design your program
• Write code
• Have the code readable and clear
• Check for errors
• Test the program and make debugging

During this lesson, we will learn main aspects of programming with AutoLISP in VLISP environment. Purpose of this lesson is to learn about the VLISP programming environment and standardize our programming practice according to this environment. Let’s get familiar with the console.

Fig.1
Fig.2.1 Visual LISP Console

While you are developing AutoLISP programs, VLISP console is what you will use most. You can write the functions that you want to try or results that you want to see on the right side of the bracket _$. This window has the same functionality with immediate window of Visual Studio. VLISP will keep everything that has happened during your programming practice. So, you can look back and make analysis whenever you want.

Console window is similar to AutoCAD’s command window. Although these two windows are similar to each other, you cannot use the same commands in both windows every time. For example, although it is enough to see what value is assigned to variable a, by writing a inside the VLISP console, you should write !a inside the AutoCAD console in order to learn the value of a. You can manage the below specified processes inside the console window:

• In order to continue a LISP code; if you press CTRL+ENTER together, then you can continue writing your code without running it.
• It is enough to press ENTER to run the code.
• If you select a field and press ENTER, then only the code you have selected is run.

Another difference between the AutoCAD command window and the console window is the use of SPACE button. While SPACE is used for confirmation of the command entered, it is used for SPACE character in console window.

Console window for more than one drawing

No matter how many number of drawings you open in AutoCAD, there is only one console window. You can see the commands that belong to the active drawing in the console window. Or similarly, if you enter a command which will effect AutoCAD, than the command works in the drawing which is currently active. Console window includes the history and files, which belong to the active drawing.

Using console short-cuts

The most frequently used commands that you need while working inside the console menu is placed into a short-cut menu which is activated by a right click of your mouse.

Table.1

Keeping console window log

For the possible analysis you might want to make in the future, you should keep a log file that belongs to the activities of console window. In order to do this, right click with your mouse at any location inside the console window and choose “Toggle Console Log” from the menu. Locate the log file and enter its name. After this, all of the contents and  activities of your console will be saved into this file.

Using the text editor

Fig.2.2
Fig.2.2. VLISP Text Editor

If you only want to try a few LISP commands console is enough. However, if you want to write a program and keep it, then load it into your drawing and run it, then you need the text editor. Text editor is a main component of VLISP, and it is very easy to use for those who are familiar with Windows programs.

VLISP Text Editor is equipped with features like finding parenthesis, coloring the syntax and automatically perceiving the keyboards, which eases programming. In order to open a new file in text editor, File/New File… is enough. Rules of writing are the same as the other editor programs. Similar to console window, there is also a right click menu in the text editor. Contents of the menu which is opened by right clicking is: 

Table.2

Color coding

Table.3

To get help while writing code, press F1 while the cursor is at the end of the function, for which you want to receive help.

Write your code understandable

It is very important to provide the re-readability of your code. For this reason you should write your code readable. You can adjust your text format from Tools > Environment Options > Visual LISP Format Options menu. An understandable LISP code is like it is seen below in Fig. 2.3.
 
Fig.2.3
Fig.2.3. An example for a proper coding.

Source: Visual LISP help file.

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 2.5 out of 5)
Loading ... Loading ...

16 Responses to “AutoLISP.2: Programming with Visual LISP editor.

Leave a Reply