Dhanushdas
asked on
How i can read AutoCad DWG file using ObjectARX SDK ?
How i can read AutoCad DWG file using ObjectARX SDK ?
Anyone have any idea please inform me..?
Anyone have any idea please inform me..?
Get the ObjectARX samples on this issue from http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=773180
'AcDbDatabase::readDwgFile ()' is what you should look for in the above samples...
ASKER
Yes...I am looking for 'AcDbDatabase::readDwgFile ()'.How i can get souce code for reading all autocad objects in a DWG file.?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to list ALL object you should learn ObjectARX anyway.
Some helpful hints
How to get entities:
ARX\DOCSAMPS\TESTDB\TESTDB .CPP
void
readDwg()
{
// Set constructor parameter to kFalse so that the
// database will be constructed empty. This way only
// what is read in will be in the database.
//
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse );
// The AcDbDatabase::readDwgFile( ) function
// automatically appends a DWG extension if it is not
// specified in the filename parameter.
//
pDb->readDwgFile("test1.dw g");
// Open the model space block table record.
//
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTb l, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_ SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterat or *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pB lkTblRcdIt r);
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();
pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(p Ent,
AcDb::kForRead);
acutPrintf("classname: %s\n",
(pEnt->isA())->name());
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
delete pDb;
}
Notice that there are various levels of AutoCAD objects visibility and various location of them.
Sample above lists top level objects available in model space.
The following types of objects can not be found this way:
- subentities In order to get them use
AcDbObjectIterator *pIter = NULL;
if (pEnt->isKindOf(AcDbBlockR eference:: desc())) {
// Block Reference - get Attribute iterator
pIter = AcDbBlockReference::cast(p Ent)->attr ibuteItera tor() ;
} else if (pEnt->isKindOf(AcDb2dPoly line::desc ())) {
// 2D Polyline - get vertex iterator
pIter = AcDb2dPolyline::cast(pEnt) ->vertexIt erator() ;
} else if (pEnt->isKindOf(AcDb3dPoly line::desc ())) {
// 3D Polyline - get vertex iterator
pIter = AcDb3dPolyline::cast(pEnt) ->vertexIt erator() ;
} else if (pEnt->isKindOf(AcDbPolyFa ceMesh::de sc())) {
// Polyface Mesh - get subobject iterator
pIter = AcDbPolyFaceMesh::cast(pEn t)->vertex Iterator() ;
} else if (pEnt->isKindOf(AcDbPolygo nMesh::des c())) {
// Polygon Mesh - get vertex iterator
pIter = AcDbPolygonMesh::cast(pEnt )->vertexI terator() ;
}
- Symbol Table records in order to get them use
AcDbSymbolTable mpSymbolTable;
// Block
mErrStat = mpDwg->getBlockTable( mpSymbolTable, AcDb::kForRead );
// Layer
mErrStat = mpDwg->getLayerTable( mpSymbolTable, AcDb::kForRead);
// TextStyle:
mErrStat = mpDwg->getTextStyleTable(m pSymbolTab le, AcDb::kForRead);
// LineType
mErrStat = mpDwg->getLinetypeTable(mp SymbolTabl e, AcDb::kForRead);
// View
mErrStat = mpDwg->getViewTable( mpSymbolTable, AcDb::kForRead);
// ViewPort
mErrStat = mpDwg->getViewportTable( mpSymbolTable, AcDb::kForRead);
// UCS
mErrStat = mpDwg->getUCSTable( mpSymbolTable, AcDb::kForRead);
// RegApp
mErrStat = mpDwg->getRegAppTable( mpSymbolTable, AcDb::kForRead);
// DimStyle
mErrStat = mpDwg->getDimStyleTable( mpSymbolTable, AcDb::kForRead);
mErrStat = mpSymbolTable->newIterator ( pIter,
true,
true/*Skip Deleted*/ )
// dictionaries
// Group
mErrStat = mpDwg->getGroupDictionary( mpDict, AcDb::kForRead);
// Layout
mErrStat = mpDwg->getLayoutDictionary ( mpDict, AcDb::kForRead);
// MLStyle
mErrStat = mpDwg->getMLStyleDictionar y( mpDict, AcDb::kForRead);
// PlotStyleName :
AcDbDictionaryWithDefault *pDictWD = NULL;
mErrStat = mpDwg->getPlotStyleNameDic tionary( pDictWD, AcDb::kForRead);
if( Acad::eOk == mErrStat )
mpDict = AcDbDictionary::cast(pDict WD);
// NamedDict:
if( !strcmp(pName/*dictionary name*/, ACDB_PLOTSETTINGS_DICTIONA RY)) {
mErrStat = mpDwg->getPlotSettingsDict ionary( mpDict, AcDb::kForRead);
break;
}
mErrStat = mpDwg->getNamedObjectsDict ionary( pDict, AcDb::kForRead);
if( !pName && Acad::eOk == mErrStat ) {
mpDict = pDict;
break;
}
if( Acad::eOk == (mErrStat = pDict->getAt(pName, pObj, AcDb::kForRead))) {
if( NULL == (mpDict = AcDbDictionary::cast(pObj) )) {
pObj->close();
mErrStat = Acad::eWrongObjectType;
}
}
// extension disctionary that can be attached to any object
dictObjId = pObj->extensionDictionary( );
pObj->close();
// Open the extension dictionary
acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
Some helpful hints
How to get entities:
ARX\DOCSAMPS\TESTDB\TESTDB
void
readDwg()
{
// Set constructor parameter to kFalse so that the
// database will be constructed empty. This way only
// what is read in will be in the database.
//
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse
// The AcDbDatabase::readDwgFile(
// automatically appends a DWG extension if it is not
// specified in the filename parameter.
//
pDb->readDwgFile("test1.dw
// Open the model space block table record.
//
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTb
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_
AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterat
pBlkTblRcd->newIterator(pB
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();
pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(p
AcDb::kForRead);
acutPrintf("classname: %s\n",
(pEnt->isA())->name());
pEnt->close();
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
delete pDb;
}
Notice that there are various levels of AutoCAD objects visibility and various location of them.
Sample above lists top level objects available in model space.
The following types of objects can not be found this way:
- subentities In order to get them use
AcDbObjectIterator *pIter = NULL;
if (pEnt->isKindOf(AcDbBlockR
// Block Reference - get Attribute iterator
pIter = AcDbBlockReference::cast(p
} else if (pEnt->isKindOf(AcDb2dPoly
// 2D Polyline - get vertex iterator
pIter = AcDb2dPolyline::cast(pEnt)
} else if (pEnt->isKindOf(AcDb3dPoly
// 3D Polyline - get vertex iterator
pIter = AcDb3dPolyline::cast(pEnt)
} else if (pEnt->isKindOf(AcDbPolyFa
// Polyface Mesh - get subobject iterator
pIter = AcDbPolyFaceMesh::cast(pEn
} else if (pEnt->isKindOf(AcDbPolygo
// Polygon Mesh - get vertex iterator
pIter = AcDbPolygonMesh::cast(pEnt
}
- Symbol Table records in order to get them use
AcDbSymbolTable mpSymbolTable;
// Block
mErrStat = mpDwg->getBlockTable( mpSymbolTable, AcDb::kForRead );
// Layer
mErrStat = mpDwg->getLayerTable( mpSymbolTable, AcDb::kForRead);
// TextStyle:
mErrStat = mpDwg->getTextStyleTable(m
// LineType
mErrStat = mpDwg->getLinetypeTable(mp
// View
mErrStat = mpDwg->getViewTable( mpSymbolTable, AcDb::kForRead);
// ViewPort
mErrStat = mpDwg->getViewportTable( mpSymbolTable, AcDb::kForRead);
// UCS
mErrStat = mpDwg->getUCSTable( mpSymbolTable, AcDb::kForRead);
// RegApp
mErrStat = mpDwg->getRegAppTable( mpSymbolTable, AcDb::kForRead);
// DimStyle
mErrStat = mpDwg->getDimStyleTable( mpSymbolTable, AcDb::kForRead);
mErrStat = mpSymbolTable->newIterator
true,
true/*Skip Deleted*/ )
// dictionaries
// Group
mErrStat = mpDwg->getGroupDictionary(
// Layout
mErrStat = mpDwg->getLayoutDictionary
// MLStyle
mErrStat = mpDwg->getMLStyleDictionar
// PlotStyleName :
AcDbDictionaryWithDefault *pDictWD = NULL;
mErrStat = mpDwg->getPlotStyleNameDic
if( Acad::eOk == mErrStat )
mpDict = AcDbDictionary::cast(pDict
// NamedDict:
if( !strcmp(pName/*dictionary name*/, ACDB_PLOTSETTINGS_DICTIONA
mErrStat = mpDwg->getPlotSettingsDict
break;
}
mErrStat = mpDwg->getNamedObjectsDict
if( !pName && Acad::eOk == mErrStat ) {
mpDict = pDict;
break;
}
if( Acad::eOk == (mErrStat = pDict->getAt(pName, pObj, AcDb::kForRead))) {
if( NULL == (mpDict = AcDbDictionary::cast(pObj)
pObj->close();
mErrStat = Acad::eWrongObjectType;
}
}
// extension disctionary that can be attached to any object
dictObjId = pObj->extensionDictionary(
pObj->close();
// Open the extension dictionary
acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: jkr {http:#9694940}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: jkr {http:#9694940}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I gave detailed description of drawing reading procedure. It's much more useful answer than other ones.