4. Debug → Start 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();
}
}
}