除了自定义夹点外,动态块应用程序还可以为块定义多个插入点。这些插入点在运行时通过协议扩展发现。为了提供自定义插入点,应用程序从类派生协议反应器并实现函数。当块插入到当前图形中时,AcRx 框架在注册反应器上调用此函数。AcDbBlockInsertionPointsAcDbBlockInsertionPoints::getInsertionPoints()AcDbBlockInsertionPoints 如果反应器返回一个插入点数组和一个匹配的对齐向量数组,框架将使用它们来补充块的默认插入点。对于插入点数组中的每个条目,必须在插入点数组中的相应索引处指定对齐向量。AutoCAD 使用对齐矢量在块插入到支持对齐方向的另一个对象附近时自动旋转块。有关为自定义实体实现对齐向量的相关信息,请参阅自定义实体的对齐定义。 下面的示例为一个块定义额外的插入点,该块由一个正方形组成,左下角位于 0,0,右上角位于 2,2。在函数中,应用程序检查要插入的块的名称。如果块的名称与应用程序定义的名称匹配,则返回备用插入点的列表以及对齐向量的列表。AutoCAD 使插入点可供用户在插入过程中循环使用。getInsertionPoints()getInsertionPoints()
#include "StdAfx.h" #include "AsdkInsertionPoints.h" #include "AcString.h" #define DYNBLKSAMP_BLOCKNAME "ASDK_CUSTOM_BLOCK" Acad::ErrorStatus AsdkInsertionPoints::getInsertionPoints ( const AcDbBlockTableRecord* pBlock, AcGePoint3dArray& insPts) { AcString sName; Acad::ErrorStatus es = pBlock->getName(sName); if (stricmp(sName, DYNBLKSAMP_BLOCKNAME) != 0) { return Acad::eNotApplicable; } insPts.append(AcGePoint3d(1.0, 0.0, 0.0)); //midpoint of side insPts.append(AcGePoint3d(1.0, -1.0, 0.0)); //buffered midpoint insPts.append(AcGePoint3d(2.0, 0.0, 0.0)); //endpoint insPts.append(AcGePoint3d(2.0, 1.0, 0.0)); //midpoint of side insPts.append(AcGePoint3d(3.0, 1.0, 0.0)); //buffered midpoint insPts.append(AcGePoint3d(2.0, 2.0, 0.0)); //endpoint insPts.append(AcGePoint3d(1.0, 2.0, 0.0)); //midpoint of side insPts.append(AcGePoint3d(1.0, 3.0, 0.0)); //buffered midpoint insPts.append(AcGePoint3d(0.0, 2.0, 0.0)); //endpoint insPts.append(AcGePoint3d(0.0, 1.0, 0.0)); //midpoint of side insPts.append(AcGePoint3d(-1.0, 1.0, 0.0)); //buffered midpoint alignmentDirections.append(AcGeVector3d(0.0, 1.0, 0.0)); alignmentDirections.append(AcGeVector3d(0.0, 1.0, 0.0)); alignmentDirections.append(AcGeVector3d(-1.0, 0.0, 0.0)); alignmentDirections.append(AcGeVector3d(-1.0, 0.0, 0.0)); alignmentDirections.append(AcGeVector3d(-1.0, 0.0, 0.0)); alignmentDirections.append(AcGeVector3d(0.0, -1.0, 0.0)); alignmentDirections.append(AcGeVector3d(0.0, -1.0, 0.0)); alignmentDirections.append(AcGeVector3d(0.0, -1.0, 0.0)); alignmentDirections.append(AcGeVector3d(1.0, 0.0, 0.0)); alignmentDirections.append(AcGeVector3d(1.0, 0.0, 0.0)); alignmentDirections.append(AcGeVector3d(1.0, 0.0, 0.0)); return Acad::eOk; } 若要注册类,将使用ACRX_PROTOCOL_REACTOR_LIST_AT协议反应器宏进行调用,如以下代码示例所示:AsdkInsertionPointsAcRxObject::addReactor() AsdkInsertionPoints* pPts = NULL; //... pPts = new AsdkInsertionPoints(); ACRX_PROTOCOL_REACTOR_LIST_AT(AcDbBlockTableRecord::desc(), CAsdkInsertionPoints::desc())->addReactor(pPts); 当应用程序卸载时,它会在函数期间移除反应器。这显示在以下代码示例中:CAsdkInsertionPointsAcRx::kUnloadAppMsgacrxEntryPoint() case AcRx::kUnloadAppMsg: acedRegCmds->removeGroup("DYNBLKAPP"); if (pPts) { ACRX_PROTOCOL_REACTOR_LIST_AT(AcDbBlockTableRecord::desc(), AsdkInsertionPoints::desc())->removeReactor(pPts); delete pPts; } break; |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:36
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.