// Traverse the current DWG block (do not open the file)
BOOL CPushDbDlg: TraverBlock (CString dwgpath, int type)
{
Acad: ErrorStatus es;
AcApDocument * pDoc = acDocManager-> curDocument (); // lock the document
Es = acDocManager-> lockDocument (pDoc );
If (es! = Acad: eOk)
{
AcutPrintf ("failed to lock the document ");
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 ("failed to open the object ");
Break;
}
PAtt = AcDbAttribute: cast (pAEntity );
Char * szTag = "";
If (pAtt! = NULL)
{
SzTag = pAtt-> tag ();
}
If (pAtt! = NULL/* & strBlockName = "title bar" */& type = 1) // write block information to a file
{
If (strcmp (szTag, "sketch drawing") = 0)
{
Char * sztext = patt-> textstring ();
Strdrawer = sztext;
}
Else if (strcmp (sztag, "Graph category") = 0)
{
Char * sztext = patt-> textstring ();
Strcate = sztext;
}
Else if (strcmp (sztag, "Drawing Number") = 0)
{
Char * sztext = patt-> textstring ();
Strcode = sztext;
}
Else if (strcmp (szTag, "workshop director") = 0)
{
Char * szText = pAtt-> textString ();
StrDirector = szText;
}
Else if (strcmp (szTag, "mobile location") = 0 ){
Char * szText = pAtt-> textString ();
StrPlant = szText;
}
If (strDirector = "") // if there is no workshop director
{
If (strcmp (szTag, "device Director") = 0)
{
Char * szText = pAtt-> textString ();
StrDirector = szText;
}
}
}
Else if (pAtt! = NULL & type = 2) // write each block
{
If (strcmp (szTag, "device number") = 0)
{
Char * szText = pAtt-> textString ();
StrECode = szText;
M_list.GetItem (iCur, strDrawCode );
// Write the data to the database
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;
}