How To Create A Custom Entity Level?

How To Create A Custom Entity Level?

BIMCAD Journalist 10/09/2024

Guide to Creating a Project

| Creating C++ project

1. Open Visual Studio 2022, then select New → Project. Choose CRL Empty Project (.Net Framework)

2. Modify the project configuration as needed to suit your requirements:

3. Right-click on the Project → Properties: Modify the information as shown below:

4. Add the Ares SDK to the project

Installation link for the Ares SDK

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 linkage

$(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)

| Creating C# project

1. In the Solution Explorer, select Add → New Project. Choose the Class Library (.Net Framework) project.

2. Right-click on the Project → Properties: modify the information as follows

3. Add Post-build event command line:

 

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

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

5. Add the following DLLs to References: Include the 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 created C++ project to References → Projects.

Guide to Creating a Custom Entity Level


CustomEntity.h: Header file of the custom entity.

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

    /**
    Function used to draw the Custom Entity.

    @param [in] Pointer to the OdGiWorldDraw object.

    @return \\c true if the custom entity does not have a view-dependent association with any other entity.
    Otherwise, return \\c false and the subViewportDraw function must be implemented.
    */
    bool subWorldDraw(OdGiWorldDraw* pWd) const override;
    
    /**
    Optional function used to draw the Custom Entity containing associations with other entities. (May contain other entities within)

    @param [in] Pointer to the OdGiViewportDraw object.
    */
    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 used to apply a specific 3D transformation to the entity.

    @param [in] A transformation matrix.

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

    /**
    Function called to retrieve grip points for the entity.

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

    @return \\c eOk if gripPoints contain grip points.
    */
    OdResult subGetGripPoints(OdGePoint3dArray& gripPoints) const override;

    /**
    Function called when a selected grip point is moved.

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

    @return \\c eOk if successful.
    */
    OdResult subMoveGripPointsAt(const OdIntArray& indices, const OdGeVector3d& offset) override;

    /**
    Function called to retrieve 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.
    */
    OdResult subGetOsnapPoints(OdDb::OsnapMode osnapMode, OdGsMarker gsSelectionMark,
        const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint,
        const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const override;

    /**
    Function 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.
    */
    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;

Entity.h: Public wrapper class used to expose CustomEntity for C# consumption.

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

public ref class CustomLevel : Entity
{
public:
    CustomLevel(CustomEntity*, bool bol);
    CustomLevel();
    ~CustomLevel();
    /**
    This function is used to create a wrapper function to interact with CustomEntity
    **/
    void functionEdit();
private:
    CustomEntity* GetImpObj()
    {
        return static_cast<CustomEntity*>(UnmanagedObject.ToPointer());

InitCLI.h: Header file declaration used to initialize CustomEntity instances.

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

void InitCLI::InitializeCustomEntity()
{
    CustomEntity::rxInit();
    // If there are multiple entities, we will initialize all of them here
    #if defined _AutoCad
        acrxBuildClassHierarchy();
    #endif
}

void InitCLI::UnInitializeCustomEntity()
{
    // If there are multiple entities, we will destroy all of them here
    CustomEntity::rxUninit();
}


Wrapper.cs: This file adds commands and executes them along 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();
        }
    }
}


Guide to Creating a Level Wrapper

Reference:

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

Tags:
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.