//遍历当前DWG中块(不打开文件)
BOOL CPushDbDlg::TraverBlock(CString dwgpath,int type)
{
Acad::ErrorStatus es;
AcApDocument *pDoc=acDocManager->curDocument();//锁定文档
es=acDocManager->lockDocument(pDoc);
if(es!=Acad::eOk)
{
acutPrintf("锁定文档失败");
return es;
}
AcDbBlockTable *ptlb;
pdb->getSymbolTable(ptlb,AcDb::kForRead);
AcDbBlockTableRecord *prec;
AcDbBlockTableRecord *precT;
ptlb->getAt(ACDB_MODEL_SPACE,prec,AcDb::kForRead);
ptlb->close();
AcDbBlockTableRecordIterator *piter;
prec->newIterator(piter);
AcDbObjectIdArray idArray;
for(piter->start();!piter->done();piter->step())
{
AcDbEntity *pentity;
piter->getEntity(pentity,AcDb::kForRead);
if(pentity->isKindOf(AcDbBlockReference::desc()))
{
idArray.append(pentity->objectId());
}
pentity->close();
}
delete piter;
prec->close();
AcDbObjectId Aobjectid=pIterator->objectId();
es=acdbOpenAcDbObject((AcDbObject*&)pAEntity,Aobjectid,AcDb::kForRead);
if(es!=Acad::eOk)
{
acutPrintf("对象打开失败");
break;
}
pAtt=AcDbAttribute::cast(pAEntity);
char *szTag="";
if(pAtt!=NULL)
{
szTag=pAtt->tag();
}
if(pAtt!=NULL /*&& strBlockName=="标题栏"*/ && type==1) //单独取块信息写入一个文件
{
if(strcmp(szTag,"草图绘制")==0)
{
char *szText=pAtt->textString();
strDrawer=szText;
}
else if(strcmp(szTag,"图属类别")==0)
{
char *szText=pAtt->textString();
strCate=szText;
}
else if(strcmp(szTag,"图纸编号")==0)
{
char *szText=pAtt->textString();
strCode=szText;
}
else if(strcmp(szTag,"车间主任")==0)
{
char *szText=pAtt->textString();
strDirector=szText;
}
else if(strcmp(szTag,"机动处")==0) {
char *szText=pAtt->textString();
strPlant=szText;
}
if(strDirector=="") //如果没有车间主任
{
if(strcmp(szTag,"设备主任")==0)
{
char *szText=pAtt->textString();
strDirector=szText;
}
}
}
else if(pAtt!=NULL && type==2) //写入每个块
{
if(strcmp(szTag,"设备编号")==0)
{
char *szText=pAtt->textString();
strECode=szText;
m_list.GetItem(iCur,strDrawCode);
//然后写入数据库
this->WriteBlockDb(strDrawCode,strBlockCode,strECode);
}
}
}
pAEntity->close();
pAtt->close();
delete pIterator;
pref->close();
}
delete pworkiter;
}
pobj->close();
}
delete pdb;
pdb=NULL;
es=acDocManager->unlockDocument(pDoc);
return TRUE;
}