J++ Programming Guidelines

AutoCAD Land Desktop ActiveX & VBA

J++ Programming Guidelines


Importing Type Libraries

After creating a Windows Application project in Visual J++, you can import COM objects through the Type Libraries. Visual J++ creates class wrappers that provide the interface for accessing the COM objects. These class wrappers are added as packages in your project directory.

Note: To access a specific COM object from another project, you can avoid wrapping the objects for each project by placing the COM wrapper classes in the CLASSPATH.

The COM wrappers can be created from the Visual J++ IDE or at the command line using the jactivex.exe utility.

To create the COM wrappers from the command line: Invoke the jactivex.exe utility. For example: jactivex /wfc /w /xi /X:rkc /d "d:\VJ++\COM_Wrappers" landauto46.tlb Build the class files for each COM Wrapper java file using the Java compiler. The *.java files can be removed from the CLASSPATH after the class files have been created.

To generate the COM Wrappers from the Visual J++ IDE: On the COM Wrapper dialog, select the Land Type Library 1.1 check box and click OK. Select the Build menu item to build the solution and generate the class files from the java files The COM wrapper folders may now be removed from the project to prevent the class files from being regenerated during each build. This will reduce the size of the solution and reduce the build time

Getting the Application object

This example shows how to access the AutoCAD Land Desktop Application object through the running object table.

// Import the library packages so objects can be referred by their short names:

// Required Visual J++ imports:

import com.ms.win32.Ole32;

import com.ms.wfc.ui.*;

import com.ms.com.*;


// Required Landauto imports:

import acax16enu.*;

import AecXBase40.*;

import AecXUIBase40.*;

import AxDb16enu.*;

import LandAuto46.*;


public class LandAutoSample extends Object


  private IAeccApplication m_iaecApp;

  private IAeccProjects m_iaecProjects;

  private IAeccProject m_iaecProject;


  // Constructor:

  public LandAutoSample()


    m_iaecApp = GetAeccApplication();

    m_iaecProjects = m_iaecApp.getProjects();

    m_iaecProject = m_iaecApp.getActiveProject();



// Sample class method to get the existing IAeccApplication object:

private IAeccApplication GetAeccApplication()


    // *** Get the existing AutoCAD session:


    Ole32 ole32 = new Ole32();

    String sAcadApp = "AutoCAD.Application";

    _Guid _guid = ole32.CLSIDFromProgID(sAcadApp);

    String sGuidAcad = _guid.toString();

    String sMonikerDispName = "!" + sGuidAcad;

    IRunningObjectTable irot = ole32.GetRunningObjectTable(0);

    IMoniker imoniker = ole32.CreateItemMoniker(sMonikerDispName,"");

    IAcadApplication iacApp = (IAcadApplication) irot.GetObject(imoniker);


    // *** If you are going to use civil enginering feature interfaces, Cross Sections, Profiles, etc.

    // initialize civil engineering features interface in case it has not been initialized.:


    IAcadDocument iacDoc = (IAcadDocument) iacApp.getActiveDocument();

    iacDoc.SendCommand("(cd_mnl) ");


    // *** Get the AeccApplication interface object:


    String sAeccApp = "Aecc.Application";

    IAeccApplication iaecApp = (IAeccApplication) iacApp.GetInterfaceObject(sAeccApp);

    return iaecApp;



  // Sample method that returns a String array containing Project Names

  // that could be displayed in a ListBox control:

  public String[] GetProjectNames()


    IAeccProject proj = m_iaecApp.getActiveProject();

    int iCount = m_iaecProjects.getCount();

    String[] sProjects = new String[iCount];

    String sProjName = "";

    Variant v = new Variant();

    for (int i=0;i<iCount;i++)



      proj = m_iaecProjects.Item(v);

      sProjects[i] = proj.getName();


    return sProjects;



Restricted Properties and Methods

When you import a Type Library into your project, you may seem to have access to read-only properties and be able to invoke methods that are not documented in the AutoCAD Land Desktop ActiveX and VBA Reference. These "restricted" members of the interface are hidden in VBA and other macro languages, but are not filtered out by the import directive.

Be aware that these members cannot be called arbitrarily. Most are used for initializing the COM object, and will not update your project database. Refer to the AutoCAD Land Desktop ActiveX and VBA Reference for the list of supported interface members, or use the OLE Viewer supplied with the Microsoft Visual Studio Tools to determine which members are restricted.