Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Associative Arrays > Creating Associative Arrays
Creating Associative Arrays

To create an associative array, use the static method createInstance() of the OdDbAssocArrayActionBody class:

OdDbObjectId arrayId, bodyId; 
 OdDbObjectIdIdArray srcEntIds; 
  { 
 OdDbCirclePtr pCircle = OdDbCircle::createObject(); 
 pCircle->setCenter(OdGePoint3d(100, 100, 0)); 
 pCircle->setRadius(10); 
 pCircle->setDatabaseDefaults(m_mDb); 
 
 OdDbBlockTableRecordPtr pModelSpace = m_pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
 pModelSpace->appendOdDbEntity(pCircle);
 
 srcEntIds.append(pCircle->objectId());
 }
 
 OdDbVertexRefPtr pBasePointRef = OdDbVertexRef::createObject(OdGePoint3d(0, 0, 0));
 
 OdDbAssocArrayPolarParametersPtr pPolarParam = OdDbAssocAraayPolarParameters::createObject();
 
 OdString paramName = OD_T("Origin");
 OdDbGeomRefPtr pOriginRef = OdDbVertexRef::createObject (OdGePoint3d(100, 200, 0));
 OdDbObjectId paramId;
 pPolarParam->setGeomParam(paramName, pOriginRef, paramId);
 
 OdDbAssocArrayActionBody::createInstance(srcEntIds, *pBasePointRef.get(), pPolarParam, arrayId, bodyId);

After executing the code sample, a polar array will be created:

An example of a polar array

Checking if an entity is an associative array

To check whether an entity is an associative array, use the static method isAssociativeArray() of the class OdDbAssocArrayActionBody.

Implementation of ARRAY command

You can find a code example that implements the ARRAY command in Drawing\Examples\ExCommands\ExArray.cpp.

See Also

Working with Associative Arrays

Associative Arrays Architecture

Editing Associative Array Parameters

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.