Chapter 36. Exploring Advanced AutoLISP Topics

This chapter builds on the previous two chapters and introduces you to a few advanced AutoLISP topics, including global and local variables, ActiveX, and debugging.

Note

AutoCAD LT does not support AutoLISP, so this entire chapter is for AutoCAD only.

Understanding Global and Local Variables

In this section, you read how global and local variables are accessed within a function, as well as some common syntax. You also discover what can happen when global variables are not properly documented.

Chapter 35 explained that a variable is a symbolic name that you can use in a given function. An important part of using variables is being able to assign values to them. There are two types of variables, global and local.

A global variable is exposed, or available, to all AutoLISP functions that you've loaded into your drawing. A global variable retains its value after the function that defined it is finished. You use a global variable when you want its value to be available while a drawing is open, as opposed to just one function. This allows you to retain a fixed value that might be used and assigned by different functions, or for debugging. Any variable that you don't specifically define as a local variable is a global variable.

A local variable is temporarily assigned a value during a function's ...

Get AutoCAD® 2010 and AutoCAD LT® 2010 Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.