To convert an ename, handle, or object ID to a VLA-object (AutoLISP/ActiveX)

When using the ActiveX functions in AutoLISP, there will be times when you need to convert VLA-objects to enames, handles, or object IDs.

Note: ActiveX support in AutoLISP is limited to Windows only.

Convert an ename to a VLA-object

The vlax-ename->vla-object function allows you to convert an entity name (ename) obtained through functions, such as entget and ssname, to VLA-objects you can use with ActiveX support functions.

  1. In the AutoCAD drawing area, draw a circle.
  2. At the AutoCAD Command prompt, enter (vl-load-com) and press Enter.
  3. Enter (setq ename-circle (car (entsel "\nPick a Circle:"))) and press Enter.
    <Entity name: 27f0538>
  4. Enter (setq vlaobject-circle (vlax-ename->vla-object ename-circle)) and press Enter.
    #<VLA-OBJECT IAcadCircle 03642c24>
  5. Enter (setq new-ename-circle (vlax-vla-object->ename vlaobject-circle)) and press Enter.
    <Entity name: 27f0538>

Convert a handle to a VLA-object

The handent function returns an entity name (ename) based on the handle provided. The entity name can then be converted to a VLA-object you can use with ActiveX support functions.

  1. In the AutoCAD drawing area, draw a circle.
  2. At the AutoCAD Command prompt, enter (vl-load-com) and press Enter.
  3. Enter (setq ename-circle (handent (cdr (assoc 5 (entget (car (entsel "\nPick a Circle:"))))))) and press Enter.
    <Entity name: 27f0538>
  4. Enter (setq vlaobject-circle (vlax-ename->vla-object ename-circle)) and press Enter.
    #<VLA-OBJECT IAcadCircle 03642c24>
  5. Enter (setq new-ename-circle (vlax-vla-object->ename vlaobject-circle)) and press Enter.
    <Entity name: 27f0538>

Convert an object ID to a VLA-object

The vla-get-ObjectID function returns the VLA-object that corresponds to the object ID that was passed to the function. Use vla-ObjectIDToObject to get the object ID for a specified VLA-object.

  1. In the AutoCAD drawing area, draw a circle.
  2. At the AutoCAD Command prompt, enter (vl-load-com) and press Enter.
  3. Enter (setq aDoc (vlax-get-property (vlax-get-acad-object) 'ActiveDocument)) and press Enter.
    #<VLA-OBJECT IAcadDocument 0000000029430508>
  4. Enter (setq aMSpace (vlax-get-property aDoc 'ModelSpace)) and press Enter.
    #<VLA-OBJECT IAcadModelSpace 00000000304d7308>
  5. Enter (setq aObjId (vla-get-ObjectID aMSpace)) and press Enter.
    48
  6. Enter (setq aObj (vla-ObjectIDToObject aDoc aObjId)) and press Enter.
    #<VLA-OBJECT IAcadModelSpace 00000000304d7308>