明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1460|回复: 0

[求助]如何正确调用数据库类的Insert()函数?

[复制链接]
发表于 2005-8-17 13:59:00 | 显示全部楼层 |阅读模式
我想用一个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 entitiesToMove;
entitiesToMove.append(OId);
for(long i=0;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;

真诚希望大家能指出问题所在
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 06:54 , Processed in 0.144093 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表