Reading DXF files using ObjectARX and C++

Reading DXF files using ObjectARX and C++

Anonymous
Not applicable
2,984 Views
6 Replies
Message 1 of 7

Reading DXF files using ObjectARX and C++

Anonymous
Not applicable

Dear all,

 

I am gathering information to create a dxf reader in ObjectARX using C++.

 

More specifically, I would like to read a dxf file and find all the objects.

Then based on the object Id to extract in a txt file the geometric information.

For example, if we have a circle to extract its center point and radius.

 

Until now the only useful information was in Autocad 2018 documentation.

I would like to ask you if you can help me to find more code examples for my purpose or any other extra information.

 

Thank you very much in advance!

0 Likes
Accepted solutions (1)
2,985 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I am gathering information to create a dxf reader in ObjectARX using C++.

First of all, with a help of ObjectARX you can use your "reader" ONLY if Autocad is installed, and ONLY if Autocad is running and your "reader" is loaded to Autocad.

 

Actually, your link is enough to do what you want and it is possible to create an DXF parser without ObjectARX. Here is a link to DXF file format

Message 3 of 7

Anonymous
Not applicable

Thank you Nick for your reply.

 

I thought to create my own dxf parser but it is a lot of work and I need it more for 3D shapes. That's why I am interesting on testing the RealDWG library and I am investigating if I should buy a license. In order to test it I should do it through ObjectARX if I am right.

 

Using RealDWG, I want to create a routine from which I can find all the objects. From the documentation I created this code sample which may not be correct but it is a first idea of what I would like to do,

 

AcDbDatabase *pDg = new AcDatabase( Adesk::False );

if ( Acad::eOk != pDg -> dxfIn( pathToFile ); // Where path to file is the full path to the dxf file

{

  return;

}

 

AcBlockTable *pBlkTbl;

pBlkTbl -> getSymbolTable( pBlkTbl, AcDb::kForRead );

 

AcDbBlockTableRecord *pBlkTblRcd;

pBlkTbl -> getAt( ACDB_MODEL_SPACE, pBlkTbRcd, AcDb::kForRead );

 

AcDbBlockTableRecordIterator -> *pBlkTblRcdItr;

pBlkTblRcd -> newIterator( pBlkTblRcdItr );

 

AcDbObjectId *pEntId;

for ( pBlkTblRcdItr -> start(); pBlkTblRcdItr -> done(); pBlkTblRcdItr -> step() )

{

  pBlockTbRcdItr -> getEntityId( pEntId );

  exportGeoProps( pEntId ); // Function where I will extract the geometric properties of the entity

  pEntId -> close() // I am not sure if I have to close the object id

}

 

pBlkTblRcd -> close();

delete pBlkTblRcdItr;

delete pDb;

}

 

0 Likes
Message 4 of 7

tbrammer
Advisor
Advisor
Accepted solution

It makes sense what you are doing.

You can develop an ARX (or better CRX - see below) application that runs under AutoCAD and reuse the code for an RealDWG project.

Keep in mind that RealDWG has certain limitations (no UI, no command calls, no graphic system). But extracting geometry is possible.

 

If you use a EXE based on RealDWG it won't be able to load ARX modules - but it can load CRX modules. AutoCAD can load them as well.

You can create a CRX app with the ObjectARX Wizard if you use Project type=Console (Console Application).

You can also test your CRX app with the AutoCAD core console (accoreconsole.exe) which is located in the AutoCAD directory.

 

If you install ObjectARX there is a <ARXDIR>\samples  subdirectory with a lot of samples.

For geometry extraction from 3DSOLIDs you will need <ARXDIR>\utils\brep (Boundary REPresentation library) which has samples as well.

I highly recomment to build the <ARXDIR>\samples\database\ARXDBG project. This builds the ArxDbg.arx app that implements commands like

SNOOPDB, SNOOPENTS, REACTORS which are helpful to understand the DWG database.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 5 of 7

artc2
Autodesk
Autodesk
RealDWG apps will not load CRX modules. They will load dbx modules.
Message 6 of 7

tbrammer
Advisor
Advisor

artc2 is right. RealDWG won't load CRX. Smiley Embarassed

Anyway: You can implement the geometry extraction functions in a DBX as well.

But you will need a CRX or ARX to implement a command that allows to test the function with AutoCAD or the core console.

 

Instead of using RealDWG you could also use Autdesk's cloud based solution Forge to create a web service.

CRX modules that run on the core console can be uploaded to the Forge server. Your users won't even need a RealDWG installation.

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thank you for your replies!

 

I will investigate what suits me better and I will let you know!

This is new information for me so it will take some time.

0 Likes