Creating an Object Data Table

AutoCAD Map 3D ObjectARX

 
Creating an Object Data Table
 
 
 

The following sample creates an object data table called Zones with two columns, Residential and Commercial.

To create an object data table

  1. Include the necessary header files:
    #include "StdAfx.h"
    #include "StdArx.h"
    #include <MapODColumn.h>
    #include <MapArxApi.h>
    #include <MapODDefinition.h>
    #include <MapProj.h>
  2. Create variables for the session, project, object data container, table, and columns. For example, create variables for a table with two columns.
    AcMapSession *mapApi;
    AcMapProject *pProj;
    AcMapODContainer *pODCont;
    AcMapODTableDefinition *pTabDef = NULL;
    AcMapODColumnDefinition *pColDef1 = NULL;
    AcMapODColumnDefinition *pColDef2 = NULL;
  3. Create an AutoCAD Map 3D session and get the top level objects.
    mapApi = AcMapGetSession();
    mapApi->GetProject(pProj);
    pProj->GetODContainer(pODCont);
  4. Allocate memory for table and column objects by calling the table and column constructors with the new operator.
    pTabDef = new AcMapODTableDefinition();
    pColDef1 = new AcMapODColumnDefinition();
    pColDef2 = new AcMapODColumnDefinition();
  5. For each of the columns, set the column name and description and the type of data the column stores. Set the default value for the data.
    pColDef1->SetName("Residential");
    pColDef1->SetDescription("Residential R1-R3");
    pColDef1->SetType(AcMap::kCharacter);
    pColDef1->SetDefaultValue("R1");
    pColDef2 = new AcMapODColumnDefinition();
    pColDef2->SetName("Commercial");
    pColDef2->SetDescription("Commercial C1-C3");
    pColDef2->SetType(AcMap::kCharacter);
    pColDef2->SetDefaultValue("C1");
  6. Add the column definitions to the table definition.
    pTabDef->AddColumn(*pColDef1);
    pTabDef->AddColumn(*pColDef2);
  7. Create the object data table. For example, create a table called Zones to store XData using the following code:
    pODCont->CreateODTable("Zones", *pTabDef, "Zoning of King City",
    Adesk::kTrue); 
  8. Release the memory you allocated for the table and columns in step 4 using the delete operator.
    if (pColDef2) delete pColDef2;
    if (pColDef1) delete pColDef1;
    if (pTabDef) delete pTabDef;