高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】不打开cad 读取.dwg文件内部的实体元素的信息
不打开cad 读取.dwg文件内部的实体元素的信息
不打开cad 读取.dwg文件内部的实体元素的信息
在不打开cad软件的情况下,通过程序读取.dwg文件内部的实体元素的信息,这个想法能否实现,若能实现用什么技术可以实现,希望版主和对这方面了解的同仁给与解答。
有的,odt技术就是做这个的
朋友,我和你的问题一样,搞出来了没?
如下代码可以实现
void
clone3()
{
acdbobjectid id;
acdbobjectidarray list;
acdbdatabase extdatabase( adesk::kfalse );
char dwgname[_max_path];
if (rtnorm != getfile( "enter dwg name", "select drawing", "dwg",
dwgname ))
{
return;
}
if (acad::eok != extdatabase.readdwgfile( dwgname ))
{
acedalert( "error reading dwg!" );
return;
}
extdatabase.
acdbblocktable* pbt;
if (acad::eok != extdatabase.getsymboltable( pbt, acdb::kforread ))
{
acedalert( "error getting blocktable of dwg" );
return;
}
acdbblocktablerecord* pbtr;
acad::errorstatus es = pbt->getat( acdb_model_space, pbtr, acdb::kforread );
pbt->close();
if (acad::eok != es) {
acedalert( "error getting model space of dwg" );
return;
}
acdbblocktablerecorditerator* pit;
if (acad::eok != pbtr->newiterator( pit )) {
acedalert( "error iterating model space of dwg" );
pbtr->close();
return;
}
for ( ; !pit->done(); pit->step()) {
if (acad::eok == pit->getentityid( id )) {
list.append( id );
// there is a bug in arx that causes extension dictionaries
// to appear to be soft owners of their contents. this causes
// the contents to be skipped during wblock. to fix this we
// must explicitly tell the extension dictionary to be a hard
// owner of it's entries.
//
acdbentity *pent;
if ( acad::eok == pit->getentity(pent, acdb::kforread)) {
acdbobjectid obj;
if ((obj = pent->extensiondictionary())
!= acdbobjectid::knull)
{
acdbdictionary *pdict = null;
acdbopenobject(pdict, obj, acdb::kforwrite);
if (pdict) {
pdict->settreatelementsashard(adesk::ktrue);
pdict->close();
}
}
pent->close();
}
}
}
delete pit;
pbtr->close();
if (list.isempty()) {
acedalert( "no entities found in model space of dwg" );
return;
}
acdbdatabase *ptempdb;
if (acad::eok != extdatabase.wblock( ptempdb, list, acgepoint3d::korigin ))
{
acedalert( "wblock failed!" );
return;
}
if (acad::eok != acdbhostapplicationservices()->workingdatabase()
->insert( acgematrix3d::kidentity, ptempdb ))
acedalert( "insert failed!" );
delete ptempdb;
}
|