Làm thế nào để tạo một custom entity level?

Làm thế nào để tạo một custom entity level?

BIMCAD Journalist 26/08/2024
custom entity level.png

Hướng dẫn tạo Project


| Tạo project C++

1. Mở Visual Studio 2022 chọn New → Project . Chọn project CRL Empty Project (.Net Framework)

2. Thay đổi config project cho phù hợp:

3. Click phải chuột vào Project → Properties : thay đổi thông tin như bên dưới:

4. Thêm Ares SDK vào project

Link cài 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. Thêm file thư viện tĩnh vào liên kết:

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

| Tạo project C# 

1. Trong Solution chọn Add → New Project . Chọn project Class Library (.Net Framework)

2. Click phải chuột vào Project → Properties : thay đổi thông tin như bên dưới:

3. Thêm Post-build even command line:

 

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

4. DebugStart external program chọn đường dẫn tới C:\Program Files\Graebert GmbH\ARES Commander 2024\BIN\ARESC.exe và thêm “/b < đường dẫn tới file .scr>” vào Start opstions → Command line arguments.

5. Thêm dll vào References : Thêm các TD_Mgd_x.xx_xx.dll* và FxCoreMgd_x.xx_xx.dll từ ARES Commander (C:\Program Files\Graebert GmbH\ARES Commander 2024\BIN)

6. Thêm project C++ đã tạo vào References → Projects

Hướng dẫn tạo một 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;

Entity.h file clas public dùng để wrapper CustomEntity cho C# gọi vào sử dụng.

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());
	}
};

InitCLI.h file header khai báo dùng để khởi tạo các CustomEntity

#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();
}


Wrapper.cs file này thêm command và thực hiện cùng với 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();
        }
    }
}

Hướng dẫn tạo wrapper Level

Bạn đang gặp khó khăn trong việc triển khai BIM, REVIT, CDE, hay bất kỳ khía cạnh công nghệ và kỹ thuật liên quan đến BIM cho dự án của mình? 

Đừng lo lắng, BIMCAD Vietnam luôn sẵn sàng đồng hành cùng bạn!

LIÊN HỆ NGAY

Tham khảo:

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

Tin tức được đọc nhiều nhất

Từ khóa:
Chia sẻ:
dịch vụ tư vấn miễn phí
LIÊN HỆ VỚI CHÚNG TÔI
Đội ngũ chuyên gia BIMCAD của chúng tôi sẽ tư vấn miễn phí và đề xuất giải pháp IT cho mọi vấn đề bạn gặp phải trong xây dựng.
footer
logo
text-logo
Chất lượng & Bảo mật thông tin
là ưu tiên hàng đầu của chúng tôi
iso9001
iso27001
awardsaokhue
Liên hệ
Email:sales@tgl-sol.com
Hotline:0377 359 728
VP Hồ Chí Minh:42/1 đường Ung Văn Khiêm, phường 25, quận Bình Thạnh, Hồ Chí Minh
VP Đà Nẵng:Số 1 đường Trần Văn Kỷ, phường Hòa Khánh Nam, quận Liên Chiểu, Đà Nẵng
Trụ sở:Tòa nhà 3F Tojikyo, 16-2 Kodenmacho, Nihonbashi, Chuo-ku, Tokyo, Nhật Bản
Liên kết
BIM/CAD © 2023 All Rights Reserved
Chào 👋 Bạn cần sự giúp đỡ? Tôi ở đây vì bạn, nhấn vào app bạn muốn nhé.