Running an Application in Its Own Namespace
 
 
 

You can define a namespace for a VLX application in VLISP. A VLX application defined in this manner is referred to as a separate-namespace VLX. When you load a separate-namespace VLX, it runs in its own namespace, not the namespace of the document from where you loaded the VLX. The option to define a VLX application with its own namespace is part of the Make Application procedure (see Making Application Modules).

If you try to load a separate-namespace VLX that is already loaded, you'll receive an error indicating this. Use the vl-unload-vlx function to unload the application. The function's syntax is

 (vl-unload-vlx“appname” )

For appname, specify the file name of the VLX, without the path or the .vlx extension.

Variables and functions defined in a VLX application's namespace are known only to the application, not to the drawing document that was active when the application was loaded. This allows you to protect your variables from accidentally—or intentionally—being overwritten by other applications or users.

A VLX application can export function names to a document namespace to enable those functions to be accessed within the context of that document. The following diagram illustrates how this works:

The diagram shows an AutoCAD session containing two open drawing documents. A VLX application named “hangman” is loaded with respect to Document1 (for example, a user opened Document1 and then loaded the VLX application from the AutoCAD Command prompt). The hangman application established its own namespace and declared the bar function and the dooley variable in that namespace. The VLX exported the bar function to Document1's namespace. When a user invokes bar from Document1, bar runs in the application's namespace. The bar function is unknown to Document2, and neither document has access to the dooley variable (because the VLX did not export it). You can load another instance of the hangman VLX into Document2, but this instance will have its own namespace and its own copies of bar and dooley.

NoteWhen you load a VLX file that has not been defined as having its own namespace, the environment is similar to that of a loaded file. All functions and variables defined in the VLX are loaded in the document's namespace.