- UID
- 121629
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-4-5
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我想用一个dwg文件保存所有的预定义图块(图块较小),并且随时接受用户的定义,并插入到该文件中。我的思路如下:用户在当前文档中定义完形成图块的所有图形元素后,程序提示用户输入图块名,然后将其用AcDbDatabase::Insert(&AcDbObjectId,char*,AcDbDatabase*)函数以图块的形式插入到预定义图形文件中,然而该函数的返回代码是16,即beNullObjectId,结果预定义图形文件中没有该图块,不知道这是什么原因。
我将代码贴在下面(实际的实现情况稍有出入,请大家指正):
CString prompt;
prompt.Format("\n%s","请选择组成块的图形:");
acutPrintf("%s",prompt);
ads_name ssname;
acedSSGet(NULL,NULL,NULL,NULL,ssname);
prompt.Format(_T("\n%s"),"请输入所要创建块的名称:");
char input[20];
int rc;
rc=acedGetString(0,prompt,input);
if (rc!=RTNORM) {
return;
}
AcDbDatabase* pCurDbDatabase;
pCurDbDatabase=acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pDbBlockTable;
pCurDbDatabase->getSymbolTable(pDbBlockTable,AcDb::kForWrite);
AcDbBlockTableRecord *pDbBlockTableRecord;
pDbBlockTableRecord=new AcDbBlockTableRecord;
pDbBlockTableRecord->setName(input);
AcDbObjectId BlockTableId;
pDbBlockTable->add(BlockTableId,pDbBlockTableRecord);
pDbBlockTable->close();
long length_Sel;
acedSSLength(ssname,&length_Sel);
ads_name entres;
AcDbObjectId OId;
AcArray<AcDbObjectId> entitiesToMove;
entitiesToMove.append(OId);
for(long i=0;i<length_Sel;i++)
{
acedSSName(ssname,i,entres);
acdbGetObjectId(OId,entres);
entitiesToMove[0]=OId;
pDbBlockTableRecord->assumeOwnershipOf(entitiesToMove);
}
pDbBlockTableRecord->close();
acedSSFree(ssname);
AcDbBlockReference * pBlockReference;
pBlockReference=new AcDbBlockReference;
pBlockReference->setBlockTableRecord(BlockTableId);
pCurDbDatabase->getSymbolTable(pDbBlockTable,AcDb::kForRead);
pDbBlockTable->getAt(ACDB_MODEL_SPACE,pDbBlockTableRecord,AcDb::kForWrite);
pDbBlockTable->close();
AcDbObjectId BlockTableRecordId;
pDbBlockTableRecord->appendAcDbEntity(BlockTableRecordId,pBlockReference);
pDbBlockTableRecord->close();
pBlockReference->close();//这里是为调试编写的,实际运行时,发现该图块的引用不能进行拖动操作
AcDbDatabase * newDb;
newDb=new AcDbDatabase(Adesk::kFalse);
CString strPath = appFullPath;//appFullPath 为预定义的应用程序路径
strPath = strPath.Left(strPath.ReverseFind('\\')) + "\\support\\temp.dwg";
pCurDbDatabase->wblock(newDb,BlockTableId);
newDb->saveAs(strPath);
strPath = strPath.Left(strPath.ReverseFind('\\')) + "\\support\\test.dwg";
AcDbDatabase* pDbDatabase_BLOCK;
pDbDatabase_BLOCK=new AcDbDatabase(Adesk::kFalse);
pDbDatabase_BLOCK->readDwgFile(strPath,_SH_DENYRW);
AcDbObjectId blockId;
Acad::ErrorStatus es;
es=pDbDatabase_BLOCK->insert(blockId,input,newDb);
if (es!=Acad::eOk) {
acutPrintf("\n%s,%d","有错误!",es);
}
delete newDb;
pDbDatabase_BLOCK->save();
delete pDbDatabase_BLOCK;
真诚希望大家能指出问题所在 |
|