- 积分
- 621
- 明经币
- 个
- 注册时间
- 2003-5-14
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
下面我是参照书本例子做的copied()函数全部,问题在文字对象生成部分,代码中只生成一个
文字对象,可是运行时生成许多文字对象,不知何故?另一问题当删除一个对象时,要让其永久反应器同时删除,该怎样实现,请大家提供一个思路
AcDbHandle myhandle;
char IntidText[132];
double wallWd,myAngle;
AcDbObjectId objectId,objId;
AcGePoint3d leftPnt3d,rightPnt3d;
bool cs;
if (dbObj->isKindOf(AcDbEquiTriangle::desc())) //找到原对象的反应器的ID
{
AcDbEquiTriangle *pTemp=AcDbEquiTriangle::cast(dbObj);
pTemp->getAcDbHandle(myhandle);
cs=myhandle.isNull();
if(!cs)
{
myhandle.getIntoAsciiBuffer(IntidText);
}
pTemp->close();
AcDbDictionary *pNamedObj;
AcDbDictionary *pNameList;
acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary(pNamedObj,AcDb::kForWrite);
if (pNamedObj->getAt("ASDK_DICT",(AcDbObject*&)pNameList, AcDb::kForRead)== Acad::eKeyNotFound)
{
return;
}
pNamedObj->close();
if ((pNameList->getAt(IntidText, objId))== Acad::eKeyNotFound)
{
return;
}
pNameList->close();
}
if(newObj->isKindOf(AcDbEquiTriangle::desc()))
{
AcDbEquiTriangle *pLine = AcDbEquiTriangle::cast(newObj);
pLine->removePersistentReactor(objId);//把新复制的对象的反应器除去
pLine->getLpoint(leftPnt3d);
pLine->getRpoint(rightPnt3d);
pLine->getAngle(myAngle);
pLine->getQiangKuan(wallWd);
pLine->getAcDbHandle(myhandle);
cs=myhandle.isNull();
if(!cs)
{
myhandle.getIntoAsciiBuffer(IntidText);
}
objectId=pLine->objectId();
AcGePoint3d textPnt;
char QiangText[132];
textPnt.set((leftPnt3d.x+rightPnt3d.x)/2-200*sin(myAngle),(leftPnt3d.y+rightPnt3d.y)/2+200*cos(myAngle),leftPnt3d.z);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();
acdbRToS(wallWd,2,2,QiangText);
AcDbObjectId textId;
AcDbText *mytext=new AcDbText( textPnt,QiangText,AcDbObjectId::kNull,200,myAngle);//生成新的文字对象
pBlockTableRecord->appendAcDbEntity(textId, (AcDbText *)mytext);
pBlockTableRecord->close();
mytext->close();
AcDbDictionary *pNamedObjNew;//建立文字对象与新复制对象的联系的反应器
AcDbDictionary *pNameListNew;
acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary(pNamedObjNew,AcDb::kForWrite);
if (pNamedObjNew->getAt("ASDK_DICT",(AcDbObject*&)pNameListNew, AcDb::kForWrite)== Acad::eKeyNotFound)
{
pNameListNew = new AcDbDictionary;
AcDbObjectId DictId;
pNamedObjNew->setAt("ASDK_DICT", pNameListNew, DictId);
}
pNamedObjNew->close();
// Create the AsdkObjectToNotify for line A.
AsdkObjectToNotify *pObj = new AsdkObjectToNotify();
pObj->eLinkage(textId);
AcDbObjectId objIdNew;
if ((pNameListNew->getAt(IntidText, objIdNew))== Acad::eKeyNotFound)
{
pNameListNew->setAt(IntidText, pObj, objIdNew);
pObj->close();
} else {
delete pObj;
}
pNameListNew->close();
pLine->addPersistentReactor(objIdNew);
pLine->close();
}
} |
|