Tuesday
AutoLISPAutoLISP.2: Programming with Visual LISP editor.
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.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.

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

Color coding

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. An example for a proper coding.
Source: Visual LISP help file.
Viewed 17,036 times so far... This week: 65 Today: 3 Latest: 5 July 2009, 1:06Post Tags:
Related Posts
Popular
- Hip tip: Increasing view resolution with VIEWRES system variable
07/03/2009 04:39 am
7 Comments - Sirince – IZMIR
07/02/2009 11:02 am
1 Comment - Visual LISP: Programming user interfaces with OpenDCL
07/01/2009 10:15 pm
10 Comments - 3D Modeling 7: EXTRUDE
06/30/2009 02:14 pm
10 Comments - Ask DailyAutoCAD: Which Notebook to Buy?
06/30/2009 12:17 pm
1 Comment
Featured Articles
- AutoCAD 2009 Update 3 Released
- Speed Up As AutoCAD 2009 Ribbon Menu Helps You!
- MEP Analysis Extension for AutoCAD MEP extended to March 31, 2009
- Recap of AutoCAD-related technologies on Autodesk Labs
- Technology Preview of MEP Analysis Extension extended to 12/31/08
- Autodesk Labs: Forward and Backward utility for AutoCAD
- Jul 21, 2007 : Daily Autocad » Blog Archive
- Nov 9, 2007 : Daily Autocad » Blog Archive » An AutoLISP program that draws a bubble at the end of axes.
|

Dec 11, 2006
Reply
Are you planning to explain Object DCL later on?
Dec 11, 2006
Reply
Hi Alvaro,
Yes it may be considered despite we left the Object DCL language
Dec 27, 2006
Reply
I would like to know, How I can do to load a cui file menu from LISP code. However, How I can do create a cui file menu easily, is there another tools that do it?.
Thank you for your help.
Dec 28, 2006
Reply
Hi Johnny,
Thanks your comment. Muharrem can answer your questions. Please take a few day after christmas.
Have a nice day…
Jan 3, 2007
Reply
How can I get the line numbers to show up? Thank you.
Jan 21, 2007
Reply
I wanna learn AUTOLisp!!!!!!!!!!!!!
May 3, 2007
Reply
what type of test editing program must be used to edit any of the customizable files for Auto CAD?
May 3, 2007
Reply
Hi Anna,
You can use any kind of text editor (such as notepad) to edit autocad customizable files.
I’m using Notepad++ which you can download from http://notepad-plus.sourceforge.net/uk/site.htm.
Bye
Jun 15, 2007
Reply
I want to read about extracting values from a adrawing to Note Pad and then to Ex cell Sheet
Oct 30, 2007
Reply
How can I protect my codes. How can I make it appear in human unreadable symbols like what I see in other codes
Oct 30, 2007
Reply
First you have to create a new project from Project menu of VLISP editor. Give a name to your new project and include the file that you want to protect its code.
Now you can rebuild your project as FAS (protected) file from Project menu.
Dec 13, 2007
Reply
Hello Orhan,
I´ve seen in your example, you have line numbers in your Editor Windon of Lisp… is this a switchable option i didn’t find yet, or are these manually added for demonstration? If there was a way to turn on line numbers – or there was an other lispeditor with this capability that would be great…
thanks,
Daniel
Dec 14, 2007
Reply
I’m using Notepad++ which can be downloaded from notepad-plus.sourceforge.net
Jul 11, 2008
Reply
thank you very much
Feb 3, 2009
Reply
Sir/Madam,
After writting the vlisp codes in .lsp file.
can you please suggest how to execute the code in order to get the results/
Apr 11, 2009
Reply
hi to all,
am working as a drafts man, i want to learn how to write lisp.
Please send me the correct path