Accessing AutoCAD Objects
 
 
 

The Application object is the root object for the AutoCAD object model. From the Application object, you can access any of the other objects, or the properties or methods assigned to objects.

Before you can use ActiveX functions with AutoLISP, you need to load the supporting code that enables these functions. Issue the following function call to load ActiveX support:

(vl-load-com)

This function first checks if ActiveX support is already loaded; if so, the function does nothing. If ActiveX support is not already loaded, vl-load-com loads ActiveX and other Visual LISP extensions to the AutoLISP language.

NoteAll applications that use ActiveX should begin by calling vl-load-com. If your application does not call vl-load-com, the application will fail, unless the user has already loaded ActiveX support.

After loading the ActiveX support functions, the first step in accessing AutoCAD objects is to establish a connection to the AutoCAD Application object. Use the vlax-get-acad-object function to establish this connection, as in the following example:

(setq acadObject (vlax-get-acad-object))

The vlax-get-acad-object function returns a pointer to the AutoCAD Application object. In the example above, the pointer is stored in the acadObject variable. This return value exists as a unique VLISP data type called VLA-object (VLISP ActiveX object).

When you refer to AutoCAD objects with ActiveX functions, you must specify a VLA-object type. For this reason, you cannot use entget to access an object and then refer to that object with an ActiveX function. The entget function returns an object of data type ename. Although you cannot use this object directly with an ActiveX function, you can convert it to a VLA-object using the vlax-ename->vla-object function. (See Converting Object References.)