How To Create A Custom Entity Level

How To Create A Custom Entity Level

BIMCAD Journalist 16/03/2026
custom title.png

Guide to Creating a Project


Create a C++ Project

1.Open Visual Studio 2022 and select New → Project. Then choose the project template “CLR Empty Project (.NET Framework)”

custom entity level.png

2. Change the project configuration accordingly

3. Right-click on the Project → select Properties, then modify the settings as shown below.

4. Add the Ares SDK to the project

Ares SDK download link:

C:\\Program Files\\Graebert GmbH\\ARES Commander 2024 SDK\\Libraries\\lib
C:\\Program Files\\Graebert GmbH\\ARES Commander 2024 SDK\\Libraries\\dd_lib

 

C:\\Program Files\\Graebert GmbH\\ARES Commander 2024 SDK\\Headers\\dd_inc
C:\\Program Files\\Graebert GmbH\\ARES Commander 2024 SDK\\Headers\\inc

5. Add the static library file to the linker

$(CoreLibraryDependencies);ddkernel.lib;TD_Root.lib;TD_DbCore.lib;TD_DbEntities.lib;TD_Dbroot.lib;TD_Br.lib;TD_Db.lib;
TD_Ge.lib;TD_Gi.lib;TD_Gs.lib;TD_Alloc.lib;%(AdditionalDependencies)

Create a C# Project

1. In the Solution, select Add → New Project. Then choose the project template “Class Library (.NET Framework)”.

2. Right-click on the Project → select Properties, then modify the settings as shown below.

3. Add a Post-build event command line:

chcp 65001
      echo NETLOAD $(TargetPath)> $(TargetDir)$(ProjectName).scr

4. In Debug → Start external program, select the path to C:\Program Files\Graebert GmbH\ARES Commander 2024\BIN\ARESC.exe
and add "/b <path to the .scr file>" in Start Options → Command line arguments

5. Add DLL files to References: Add TD_Mgd_x.xx_xx.dll* and FxCoreMgd_x.xx_xx.dll from ARES Commander
(C:\Program Files\Graebert GmbH\ARES Commander 2024\BIN)

6. Add the previously created C++ project to References → Projects.

Guide to Creating a Custom Entity Level


CustomEntity.h : file header của custom entity:

class CustomEntity : public OdDbEntity
{
	ODDB_DECLARE_MEMBERS(CustomEntity);
	CustomEntity();
	virtual ~CustomEntity();

    /**
   Function dung de ve Entity Custom.

   @param [in] Pointer to the OdGiWorldDraw object.

   @return \\c true neu entity custom khong khong co lien ket view voi bat ki enity khac.
   Nguoc lai return \\c false va ham subViewportDraw phai duoc trien khai   
   */
    bool subWorldDraw(OdGiWorldDraw* pWd) const override;
    /**
    Function la tuy chon (optional), dung de ve Entity Custom co chua lien ket
    voi entity khac. ( Co the la chua cac entity khac ben trong)
    @param [in] Pointer to the OdGiViewportDrawobject.
    **/
    void subViewportDraw(OdGiViewportDraw* pVd) const override;
    /**
    Reads the DXF data for our new entity.

    @param [in] Pointer to the OdDbDxfFiler object.

    @return \\c eOk if successful.
    */
    OdResult dxfInFields(OdDbDxfFiler* filer) override;

    /**
    Writes the DXF data for our new entity.

    @param [in] Pointer to the OdDbDxfFiler object.
    */
    void dxfOutFields(OdDbDxfFiler* filer) const override;

    /**
    Reads the DWG data of this object.

    @param [in] Pointer to the OdDbDwgFiler object.

    @return \\c eOk if successful.
    */
    OdResult dwgInFields(OdDbDwgFiler* pFiler) override;

    /**
    Writes the DWG data for our new entity.

    @param [in] Pointer to the OdDbDwgFiler object.
    */
    void dwgOutFields(OdDbDwgFiler* pFiler) const override;

    /**
    Function dung de ap dung chuyen doi 3D cho entity theo mot ma tran cu the.

    @param [in] A transformation matrix.

    @return \\c eOk if successful.
    */
    //
    OdResult subTransformBy(const OdGeMatrix3d& xform) override;

    /**
    Function is called to get the grip points for an entity object.

    @param [in/out] Receives an array of WCS grip points.

    @return \\c eOk if the gripPoints contain grip points.
    */
    /**
    Function dung de lay cac vi tri co the chon ( dung click chuot hoac cach khac)
    */
    OdResult subGetGripPoints(OdGePoint3dArray& gripPoints) const override;

    /**
    Function is called to move the specified grip points of this entity.

    @param [in] Array of indices.
    @param [in] The direction and magnitude of the grip points offset (WCS).

    @return \\c eOk if successful.
    */
    /**
    Function duoc goi khi diem duoc chon di chuyen.
    */
    OdResult subMoveGripPointsAt(const OdIntArray& indices, const OdGeVector3d& offset) override;

    /**
    Function is called to get the snap points for the current mode.

    @param [in] The object snap mode being queried.
    @param [in] The GS marker of the subentity being queried.
    @param [in] The WCS point being queried.
    @param [in] The WCS point picked before pickPoint.
    @param [in] The WCS->DCS transformation matrix.
    @param [in/out] Receives an array of UCS object snap points.

    @return \\c eOk if successful.
    */
    /**
    Nếu bạn muốn custom entity  hỗ trợ các chế độ chụp nhanh thực thể, 
    bạn phải ghi đè hàm subGetOsnapPoints(). 
    Thư viện Teigha C++ gọi subGetOsnapPoints() để thu được các điểm chụp nhanh 
    có liên quan cho chế độ hiện tại.
    Nếu nhiều chế độ chụp nhanh đối tượng đang hoạt động, chức năng này được
    gọi một lần cho mỗi chế độ chụp nhanh đối tượng.
enum OsnapMode
	{
  kOsModeEnd      = 1,  // Endpoint
  kOsModeMid      = 2,  // Midpoint
  kOsModeCen      = 3,  // Center
  kOsModeNode     = 4,  // Node
  kOsModeQuad     = 5,  // Quadrant
  kOsModeIntersec = 6,  // Intersection
  kOsModeIns      = 7,  // Insertion point
  kOsModePerp     = 8,  // Perpendicular
  kOsModeTan      = 9,  // Tangent
  kOsModeNear     = 10, // Nearest
  kOsModeApint    = 11, // Apparent intersection
  kOsModePar      = 12, // Parallel
  kOsModeStart    = 13  // Startpoint
};
    */
    OdResult subGetOsnapPoints(OdDb::OsnapMode osnapMode, OdGsMarker gsSelectionMark,
        const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint,
        const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const override;

    /**
    Function is called to explode this custom entity into a set of simpler entities.

    @param [in/out] Receives an array of pointers to the new entities.

    @return \\c eOk if successful, or an appropriate error code if not.
    */
    /**
    Phan tach custom entity thanh cac phan don gian nhu duong tron, vong cung,
     diem, duong thang,....
    */
    OdResult subExplode(OdRxObjectPtrArray& entitySet) const override;
private:
    OdGePoint3d m_center;
    double m_radius;
};

/** \\typedef OdSmartPtr<CFxPIEntity> CFxPIEntityPtr
    CFxPIEntity smart pointer, used later to create the object
*/
typedef OdSmartPtr<CustomEntity> OdBbCustomLevelPtr;

The public class in the Entity.h file is used to wrap the CustomEntity so that it can be called and used from C#

using namespace Teigha::Geometry;
using namespace Teigha::DatabaseServices;

public ref class CustomLevel :Entity
{
public:
	CustomLevel(CustomEntity*, bool bol);
	CustomLevel();
	~CustomLevel();
/**
Function nay dung de tao chuc nang wrapper de thao tac voi CustomEntity
**/
	void functionEdit();
private:
	CustomEntity* GetImpObj()
	{
		return  static_cast<CustomEntity*>(UnmanagedObject.ToPointer());
	}
};

The InitCLI.h header file contains declarations used to initialize the CustomEntity classes

#pragma once
public ref class InitCLI
{
public:
	static void Init();
	static void UnInit();
};
#include "InitCLI.h"
#include "OdBbCustomLevel.h"

void InitCLI::Init()
{
    CustomEntity::rxInit();
// neu co nhieu entity chung ta se khoi tao tat ca chung tai day
#if defined _AutoCad
    acrxBuildClassHierarchy();
#endif
}

void InitCLI::UnInit()
{
// neu co nhieu entity chung ta se pha huy tat ca chung tai day
    CustomEntity::rxUninit();
}

The Wrapper.cs file adds commands and executes them together with ARES

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.ApplicationServices;
using Teigha.DatabaseServices;
using Teigha.EditorInput;
using Teigha.Geometry;
using Teigha.Runtime;
using Aplication = Teigha.ApplicationServices.Application;
namespace Wrapper
{
    public class Class1 : IExtensionApplication
    {
        [CommandMethod("TestCustomEntity")]
        public void Test11()
        {
            // Get Active Document and Database
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            // Starts a Transaction
            using (Transaction trans = doc.TransactionManager.StartTransaction())
            {
                // Open Block Table in Read Mode
                BlockTable blkTbl = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord blkTblRec = (BlockTableRecord)trans.GetObject(blkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                CustomLevel customObj = new CustomLevel();
                customObj.functionEdit();
                // Add Solid Entity to Block table Record
                blkTblRec.AppendEntity(customObj);
                trans.AddNewlyCreatedDBObject(customObj, true);
                trans.Commit();
            }
        }

        public void Initialize()
        {
            InitCLI.Init();
        }

        public void Terminate()
        {
            InitCLI.UnInit();
        }
    }
}

Are you facing difficulties implementing BIM, Revit, CDE, or any technology and technical aspects related to BIM for your project?

Don’t worry— BIMCAD Vietnam is always ready to support and accompany you!

CONTACT US NOW →

References

https://graebert.atlassian.net/wiki/spaces/ACPD/pages/576618573/Introduction+to+.NET+API+Plugins

https://graebert.atlassian.net/wiki/spaces/ACPD/pages/1339752463/CFx+Developer+s+Guide

https://graebert.atlassian.net/wiki/spaces/ACPD/pages/1351483659/Creating+Custom+Objects

https://graebert.atlassian.net/wiki/spaces/ACPD/pages/1469907008/Examples+CFx

Share:
Get a free consultation
contact us
Fill out the form and contact us today for an absolutely free consultation of anything related to BIM/CAD.
footer
logo
text-logo
Quality & Information Security
are at the core of our priorities.
iso9001
iso27001
awardsaokhue
Contact
Email:sales@tgl-sol.com
Hotline:(+84) 377 359 728
Ho Chi Minh Office:42/1 Ung Van Khiem Street, Ward 25, Binh Thanh District, Ho Chi Minh
Da Nang Office:01 Tran Van Ky Street, Hoa Khanh Nam Ward, Lien Chieu District, Da Nang
Headquarter:3F Tojikyo Building, 16-2 Kodenmacho, Nihonbashi, Chuo-ku, Tokyo, Japan
Follow Us
BIM/CAD © 2023 All Rights Reserved
Hey 👋 I'm right here to help you, so just click the chat button.