当前位置: 代码迷 >> 综合 >> ObjectARX 创建AcDbLeader引线附着块对象实例
  详细解决方案

ObjectARX 创建AcDbLeader引线附着块对象实例

热度:94   发布时间:2023-12-23 22:23:45.0

 三点引线附着块参照实例

        // 创建AcDbLeader引线ads_point p1,p2,p3;if (RTNORM != acedGetPoint(NULL,_T("\n请选择引线第一点: "),p1))return;if (RTNORM != acedGetPoint(p1,_T("\n请选择引线第二点: "),p2))return;if (RTNORM != acedGetPoint(p2,_T("\n请选择引线第三点: "),p3))return;// ucs点转换到wcs点acdbUcs2Wcs(p1,p1,false);acdbUcs2Wcs(p2,p2,false);acdbUcs2Wcs(p3,p3,false);// ads点转为AcGe点AcGePoint3d pt1=asPnt3d(p1);AcGePoint3d pt2=asPnt3d(p2);AcGePoint3d pt3=asPnt3d(p3);//  设置第三点为第二点的水平点pt3.y=pt2.y;AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase();// 使用智能指针打开块表AcDbBlockTablePointer pBlkTbl(pDb,AcDb::kForRead);Acad::ErrorStatus es =pBlkTbl.openStatus();if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}// 获取指定块名的块表记录IDAcDbObjectId blkDefId;es=pBlkTbl->getAt(_T("123"),blkDefId);if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}// 使用智能指针创建块参照对象AcDbObjectPointer<AcDbBlockReference> pBlkRef;es= pBlkRef.create();if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}        pBlkRef->setBlockTableRecord(blkDefId);pBlkRef->setPosition(pt3);pBlkRef->setDatabaseDefaults();// 使用智能指针打开pDb的当前空间AcDbBlockTableRecordPointer pBlkRcd(pDb->currentSpaceId(),AcDb::kForWrite);es =pBlkRcd.openStatus();if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}AcDbObjectId blkRefId;pBlkRcd->appendAcDbEntity(blkRefId,pBlkRef);// 引线的附着对象一定要及时关闭,否则attachAnnotation附着失败pBlkRef->close();// 创建引线对象AcDbObjectPointer<AcDbLeader> pLeader;es= pLeader.create();if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}pLeader->appendVertex(pt1);pLeader->appendVertex(pt2);pLeader->appendVertex(pt3);pLeader->setDatabaseDefaults();// 要先将引线对象添加到数据库后再执行attachAnnotation附着对象,否则附着失败pBlkRcd->appendAcDbEntity(pLeader);// 条件1,附着实体ID,AcDbLeader引线必须是添加到数据库的对象否则出现,eNotInDatabase// 条件2,附着实体ID对象也必须是数据库的关闭对象,因为需要对附着对象添加反应器之类操作es = pLeader->attachAnnotation(blkRefId);if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}es = pLeader->evaluateLeader();if (Acad::eOk != es){acutPrintf(_T("\n程序执行失败,错误码=%s"),acadErrorStatusText(es));return;}

附着多行文字,参考链接 Create a leader attached MText - AutoCAD DevBlog