|
thisline.set(leftPnt3d,rightPnt3d);
AcGePoint3dArray breakPts;
AcDbBlockTable *pBlockTable1;
//下面这段程序是遍历块表,找到与this AcDbmyEntity相交的others AcDbmyEntity实体
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable1, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord1;
pBlockTable1->getAt(ACDB_MODEL_SPACE, pBlockTableRecord1, AcDb::kForRead);
pBlockTable1->close();
AcDbBlockTableRecordIterator *pBlockIterator;
pBlockTableRecord1->newIterator(pBlockIterator);
AcGePoint3d rightPt,leftPt;
double qiangHeight,qiangwidth;
AcDbEntity *pEntity;
for (; !pBlockIterator->done();pBlockIterator->step())
{
pBlockIterator->getEntity(pEntity, AcDb::kForRead);
if(pEntity->isKindOf(AcDbmyEntity::desc()))
{
AcDbmyEntity::cast(pEntity)->getRpoint(rightPt);
AcDbmyEntity::cast(pEntity)->getLpoint(leftPt);
AcDbmyEntity::cast(pEntity)->getHeight(qiangHeight);
AcDbmyEntity::cast(pEntity)->getWidth(qiangwidth);
otherline.set(rightPt,leftPt);
Adesk::Boolean rc=thisline.intersectWith(otherline, ptmy);
if(rc==Adesk::kTrue)
{
breakPts.append(ptmy);
//下面为删除others AcDbmyEntity实体
AcDbmyEntity::cast(pEntity)->upgradeOpen();
AcDbmyEntity::cast(pEntity)->erase(true);
AcDbmyEntity::cast(pEntity)->close();
//问题在下面,如果不加下面1-15句,运行不会报错误,不知为什么出错,也不知道这样
//出实现下面的功能行不行,是否有其他的方法,请各位大虾指教
//下面为用ptmy点重新生成两个AcDbmyEntity实体替换已删除others AcDbmyEntity实体
//相当于把others AcDbmyEntity实体以ptmy点分为两段
1 AcDbmyEntity* pTriangle0 = new AcDbmyEntity();
pTriangle0->create(leftPt, ptmy,qiangwidth,qiangHeight);
AcDbEquiTriangle* pTriangle1 = new AcDbmyEntity();
Triangle1->create(ptmy,rightPt,qiangwidth,qiangHeight);
AcDbBlockTable *pBlockTable2;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable2, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord2;
pBlockTable2->getAt(ACDB_MODEL_SPACE, pBlockTableRecord2, AcDb::kForWrite);
pBlockTable2->close();
AcDbObjectId objectId1,objectId2;
pBlockTableRecord2->appendAcDbEntity(objectId1, (AcDbmyEntity *)pTriangle0);
pBlockTableRecord1->appendAcDbEntity(objectId2, (AcDbmyEntity *)pTriangle1);
pBlockTableRecord2->close();
pTriangle0->close();
15 pTriangle1->close();
}
else
{
AcDbmyEntity::cast(pEntity)->close();
}
}
}
delete pBlockIterator;
pBlockTableRecord1->close(); |
|