Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Creating a Custom Entity > Deriving a Custom Entity Class
Deriving a Custom Entity Class

The first step to creating a custom object is to derive a custom entity class from the OdDbEntity class or OdDbObject class. To derive a custom entity class you must declare the following:


class MyEntityObj : public OdDbEntity
{
 public:
   ODDB_DECLARE_MEMBERS(MyEntityObj);

   MyEntityObj();
   ~MyEntityObj();
};

For the custom entity, it is necessary to define a constructor, destructor, and to declare default functions by means of ODDB_DECLARE_MEMBERS macros. Macros are necessary for all database objects.

The implementation for a custom entity must call the ODRX_DXF_DEFINE_MEMBERS macro, which creates implementations for the functions declared by the ODDB_DECLARE_MEMBERS macro used in the class declaration:


ODRX_DXF_DEFINE_MEMBERS(MyEntityObj,                                          // class name
                        OdDbEntity,                                           // parent class name
                        DBOBJECT_CONSTR,                                      // creation pseudo-constructor
                        OdDb::kDHL_CURRENT,                                   // file version
                        OdDb::kMReleaseCurrent,                               // maintenance release version
                        OdDbProxyEntity::kTransformAllowed |
                        OdDbProxyEntity::kColorChangeAllowed |
                        OdDbProxyEntity::kLayerChangeAllowed,                 // proxy flags
                        MYENTITYOBJ,                                          // dxf class name
                        MyCustObjs|Description: Run-time Extension Example)   // application name

Note that the application name MyCustObjs must agree with the name of the shared library that contains the implementation for this object (MyCustObjs.tx).

To implement a minimal custom entity, the following functions must be overridden: worldDraw(), dwgOutFields(), and dwgInFields(). It is also desirable to implement the following functions: dxfOutFields() and dxfInFields().

See Also

Creating a Custom Entity

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