Solved

How i can read AutoCad DWG file using ObjectARX SDK ?

Posted on 2003-11-05
8
2,256 Views
Last Modified: 2007-12-19
How i can read AutoCad DWG file using ObjectARX SDK ?

Anyone have any idea please inform me..?
0
Comment
Question by:Dhanushdas
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9687162
Get the ObjectARX samples on this issue from http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=773180
0
 
LVL 86

Expert Comment

by:jkr
ID: 9687198
'AcDbDatabase::readDwgFile()' is what you should look for in the above samples...
0
 

Author Comment

by:Dhanushdas
ID: 9691899
Yes...I am looking for 'AcDbDatabase::readDwgFile()'.How i can get souce code for reading all autocad objects in a DWG file.?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 9694940
>>How i can get souce code

Download the aforementioned samples...
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 9695501
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.dwg");

    // Open the model space block table record.
    //
    AcDbBlockTable *pBlkTbl;
    pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);

    AcDbBlockTableRecord *pBlkTblRcd;
    pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
        AcDb::kForRead);
    pBlkTbl->close();

    AcDbBlockTableRecordIterator *pBlkTblRcdItr;
    pBlkTblRcd->newIterator(pBlkTblRcdItr);

    AcDbEntity *pEnt;
    for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();
        pBlkTblRcdItr->step())
    {
        pBlkTblRcdItr->getEntity(pEnt,
            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(AcDbBlockReference::desc())) {
              // Block Reference  - get Attribute iterator
            pIter = AcDbBlockReference::cast(pEnt)->attributeIterator() ;
        } else if (pEnt->isKindOf(AcDb2dPolyline::desc())) {
              // 2D Polyline - get vertex iterator
            pIter = AcDb2dPolyline::cast(pEnt)->vertexIterator() ;
        } else if (pEnt->isKindOf(AcDb3dPolyline::desc())) {
              // 3D Polyline - get vertex iterator
            pIter = AcDb3dPolyline::cast(pEnt)->vertexIterator() ;
        } else if (pEnt->isKindOf(AcDbPolyFaceMesh::desc())) {
              // Polyface Mesh - get subobject iterator
            pIter = AcDbPolyFaceMesh::cast(pEnt)->vertexIterator() ;
        } else if (pEnt->isKindOf(AcDbPolygonMesh::desc())) {
              // Polygon Mesh - get vertex iterator
            pIter = AcDbPolygonMesh::cast(pEnt)->vertexIterator() ;
        }

- 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(mpSymbolTable, AcDb::kForRead);
// LineType
         mErrStat = mpDwg->getLinetypeTable(mpSymbolTable, 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->getMLStyleDictionary( mpDict, AcDb::kForRead);
// PlotStyleName :
AcDbDictionaryWithDefault   *pDictWD      = NULL;
mErrStat = mpDwg->getPlotStyleNameDictionary( pDictWD, AcDb::kForRead);
if( Acad::eOk == mErrStat )
  mpDict = AcDbDictionary::cast(pDictWD);
// NamedDict:
 if( !strcmp(pName/*dictionary name*/, ACDB_PLOTSETTINGS_DICTIONARY)) {
    mErrStat = mpDwg->getPlotSettingsDictionary( mpDict, AcDb::kForRead);
    break;
 }
 mErrStat = mpDwg->getNamedObjectsDictionary( 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);


0
 
LVL 9

Expert Comment

by:tinchos
ID: 10242550
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
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 10250762
I gave detailed description of drawing reading procedure. It's much more useful answer than other ones.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now