About Converting Between AutoLISP and ActiveX Data Types (AutoLISP/ActiveX)

 
 
 

When working with the ActiveX support and core AutoLISP functions, you will need to convert between data types.

NoteActiveX support in AutoLISP is limited to Windows only.

Adding a circle to a drawing with the AddCircle method requires you to specify a center point and radius for the circle. These arguments are referred to as Center and Radius. Center is defined as a variant (three-element array of doubles), and Radius is listed as a double:

(setq RetVal (vla-AddCircle aMSpace Center Radius))

Elements

RetVal

Object; output only. The resulting circle object from the AddCircle method.

aMSpace

Object; input only. The object that the AddCircle method should work on.

Center

Variant (three-element array of doubles); input only. A 3D WCS coordinate specifying the circle's center.

Variants are essentially self-defining structures that can contain different types of data. For example, strings, integers, and arrays can all be represented by variants. Stored along with the data is information identifying the type of data. This self-defining feature makes variants useful for passing parameters to ActiveX servers, because it enables servers based on any language to understand the data value.

Radius

Double; input only. The radius of the circle. Must be a positive number.

AutoLISP to ActiveX Data Types

ActiveX supports many data types that are similar to those in AutoLISP, but there are a few unique data types that do not directly map to those supported by AutoLISP. The following explains how to convert the data types:

AutoLISP data types accepted in place of an ActiveX data type

 

Integer

Real

String

Ename

VLA-object

Variant

List

:Safe-array

Boolean

:vlax-true

:vlax-false

nil

:vlax-null

Byte

X

 

 

 

 

 

 

 

 

 

 

 

Boolean

 

 

 

 

 

 

 

 

X

X

 

 

Integer

X

 

 

 

 

 

 

 

 

 

 

 

Long

X

 

 

 

 

 

 

 

 

 

 

 

Single/Short

X

 

 

 

 

 

 

 

 

 

 

 

Double

X

X

 

 

 

 

 

 

 

 

 

 

Object

 

 

 

 

X

 

 

 

 

 

 

 

String

 

 

X

 

 

 

 

 

 

 

 

 

Variant

 

 

 

 

 

X

 

 

 

 

 

 

Array

 

 

 

 

 

 

 

X

 

 

 

 

Nothing

 

 

 

 

 

 

 

 

 

 

 

X

Empty

 

 

 

 

 

 

 

 

 

 

X

 

Converting Array and List data types

The ActiveX array data type are similar to a list in AutoLISP. They contain multiple elements that represent different data structures. A common use for an array is to represent a coordinate value. You can use vlax-safearray->list to convert an array to a list. Converting a list to an array requires you to define the data type and number of elements the array should have with vlax-make-safearray, and assign the values of the list to the elements of the array using the vlax-safearray-fill.

Converting Variant data types

Variant data types are used when a method might return or use more than one type of data. You can use vlax-make-variant to create a variant. When creating a variant, you specify the type of data and value it should hold. If a variant is returned by a method or property, you can use the vlax-variant-type and vlax-variant-value functions.

Converting VLA-object, Handles, and Ename data types

There are a number of ways to refer to AutoCAD drawing objects with AutoLISP. These include the following:

VLA-objects

Returned by ActiveX functions. Use vlax-vla-object->ename to convert from the VLA-object to ename (entity name) data type.

(setq MSpace (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))))
#<VLA-OBJECT IAcadModelSpace 0000000030434638>

(setq circObj (vla-AddCircle MSpace (vlax-3d-point '(5.0 5.0 0.0)) 3))
#<VLA-OBJECT IAcadCircle 00000000303b2698>

(vlax-vla-object->ename circObj)
<Entity name: 7ffffb05de0>
Entity names (enames)

Returned by handent, entget, and entsel, identifying objects in an open drawing. Use vlax-ename->vla-object to convert from the ename to VLA-object data type.

(setq en (handent handle-circle))
<Entity name: 27f0538>

(setq en (car (entsel "\nSelect circle: ")))
<Entity name: 27f0538>

(vlax-ename->vla-object en)
#<VLA-OBJECT IAcadCircle 00000000303b3718>
Handles

Returned by vla-get-handle or by retrieving the DXF 5 group code from an entity name’s association list, which entities retain across AutoCAD sessions. Use vla-handleToObject to return the VLA-object that is associated with the handle.

(vla-get-handle vla-circle)
"4F"

(setq handle-circle (cdr (assoc 5 (entget ename-circle))))
"4F"

(setq vla-circle (vla-handleToObject acadDocument handle-circle))
#<VLA-OBJECT IAcadCircle 03642c24>
Object IDs

Used by ActiveX, ObjectARX, and Manage .NET programs to identify objects. Use vla-ObjectIDToObject to convert an object ID to a VLA-object or use vla-get-ObjectID to convert a VLA-object to an object ID.

(setq objid-Circle (vla-get-objectid vla-circle))
41878840

(vla-ObjectIDtoObject acadDocument objid-circle)
#<VLA-OBJECT IAcadCircle 03642c24>