- slide 1 of 2
AutoCAD is very popular 2d software in the field of drafting and detailing. The later versions of autocad are very user friendly and could be customized as per end user’s special requirements.
What is customization?
Suppose you repeatedly need to draw a 100mm X 100m rectangle and a 25mm dia circle inside it, then instead of drawing a rectangle first and then draw the circle inside it you can think of customizing AutoCAD to make the drawing by a single mouse click. This is a very simple example of customization.
Why to do AutoCAD customization?
The main reason is in this we can save lots of time for drawing creations, also the drawing produced by this way will be having less chance of error thus customization reduce design cost.
How to do AutoCAD customization?
AutoCAD could be customized by using autolisp, visual lisp, VB and C++.Autolisp and visual lisp come inbuilt with AutoCAD.
Some basics of autolisp programming:
Typical AutoLISP program is basically a group of expressions. An AutoLISP expression looks like below:
The opening and closing parenthesis are must also the argument part may again contain one or more functions like below:
(fun1 (fun2 arguments)(fun3 arguments))
Autolisp data types:
Integer: whole numbers
Real: Decimal numbers
String: quotation surrounded group of character
Lists: parenthesis enclosed related values with space separation.
Operators: this are similar to other language (like C ) but need to be placed in front of the operands and whole statement need to be enclosed by parenthesis.
e.g. (+ 3 2) will return 5.
- slide 2 of 2
Getting started with programming:Let’s talk about some important functions to start with:
Setq: can stores values (integer, decimal, string and lists) to a variable.
Example: (setq P “I love India”)
(setq P (list 1 2 3))
defun: It defines a user function.
(defun C:TEST1 ()
(alert “hallo world”))
In this example TEST1 could be used as a AutoCAD command and then “hallo world” statement will pop up in screen.
command: by using command function we can use AutoCAD commands in lisp programming.
(setq pt1 '(1 1) pt2 '(1 5))
(command "line" pt1 pt2 "")
In this example we can draw a line between point 1 1 and 1 5
some basic output functions of autolisp: any of the functions like promt ,princ,prin1 print will print in command window. See the example below:
(setq str "I love my india")
How to run autolisp program: Autolisp program can be loaded to auto cad by the following three ways:
• By directly typing the program statements to AutoCAD command window
• By typing the program statement to a separate notepad or WordPad and save it with a .lsp extension and then load it by following path
• By typing and run the program through visual lisp window.
The discussions I had so far is good to start autolisp programming and by following these one will be able to understand and learn the advanced topics. One can further refer my other articles of this series as well.
AutoCAD Customization using Autolisp - Part 1
This is the series of articles that describe AutoCAD cutomization using the tools like Autolisp, Visual lisp ,VB,C++ used for customization of Autocad.