VLX Namespaces
Tuesday, March 17, 2026Let's say you have a first AutoLISP program program1 that displays a message: "Hello".
(defun say-hello ()
(alert "Hello, World!")
)
(defun program1 ()
(say-hello)
)
The main function program1 calls the say-hello function, which displays an alert message.

OK, nothing very interesting here. Now, you have a second AutoLISP program program2:
(defun say-hello ()
(alert "Hello, World!")
)
(defun program2 ()
(say-hello)
)
It's the exact same program here for the sake of this article, but imagine that program1 and program2 are two programs that do different things. The important thing is that they share the same say-hello function.
As long as both say-hello functions are identical, there is no problem. But during development, you might need to modify the say-hello function in one of the programs. In program2, for example, you change say-hello to display "Hello, Universe!" instead of "Hello, World!".
(defun say-hello ()
(alert "Hello, Universe!")
)
(defun program2 ()
(say-hello)
)
And that's where things go wrong — the last function loaded overwrites the other. If you load program1 first, then program2, you'll get "Hello, Universe!" in program2 AND program1. The second program affects the first, and that's a problem. It's a source of bugs that will drive you crazy.
The solution to this problem is to package your programs into a VLX, making sure to enable the Separate Namespace option when creating the VLX.
Creating a VLX with a separate namespace
To create a VLX, run the MAKELISPAPP command in AutoCAD. The Make Application Wizard guides you through several steps. The option we're interested in is on the Application Options page: Separate Namespace.

By checking this option, each VLX will have its own isolated namespace. Functions defined inside a VLX will no longer be visible from the other VLX, or from the command line. No more collision between the two say-hello functions.
The catch: inaccessible functions
We package our two programs, load both VLX files, and... surprise:
(program2)
; error: no function definition: PROGRAM2
The program2 function is nowhere to be found. And if we test program1, same result. It makes sense when you think about it: the separate namespace isolates all functions in the VLX, including the ones we'd like to call from the command line.
The solution: vl-doc-export
To make a function accessible from the document namespace (the command line), you need to explicitly export it with vl-doc-export. Here are our two fixed programs:
(defun say-hello ()
(alert "Hello, World!")
)
(defun program1 ()
(say-hello)
)
(vl-doc-export 'program1)
(defun say-hello ()
(alert "Hello, Universe!")
)
(defun program2 ()
(say-hello)
)
(vl-doc-export 'program2)
The call (vl-doc-export 'program1) exports the program1 symbol from the VLX namespace to the document namespace. After rebuilding the VLX files, we can now call (program1) and (program2) from the command line, and each one will display its own message.
The say-hello function intentionally remains unexported. Each VLX keeps its own version, isolated in its namespace. That's exactly what we wanted.
vl-doc-import: the reverse
There is also the vl-doc-import function which does the opposite: it imports a symbol from the document namespace into the VLX namespace. This is useful if your VLX needs to call a function defined in another VLX or directly in the document.
(vl-doc-import 'a-function-from-the-document)
Summary
- Without a separate namespace, all programs share the same space and functions with the same name overwrite each other.
- With the Separate Namespace option, each VLX is isolated, but its functions are no longer accessible from the command line.
vl-doc-exportallows you to expose the functions you want to make public.vl-doc-importallows your VLX to access functions defined in the document.
Need an AutoCAD (AutoLISP, ObjectARX, .NET, VBA) development? Contact me for a free quote.