Reading a Dxf file with Java

Spyros picture Spyros · Jul 19, 2011 · Viewed 23.7k times · Source

I am trying to write/find some code in Java which reads dxf files and stores geometry from the "Entities" section into arrays so that I can later import that information into Oracle 11g in terms of tables.

Thank you in advance!

Answer

aacotroneo picture aacotroneo · Jun 2, 2012

I've used kabeja recently and haven´t had any problems, though I did quite simple tasks. If you just want to bring those geometries into an array it will do the job (in other cases I can't tell). If you already know the DXF format you will have no problems to get started. It can get as easy as follows (e.g. to extract some circle entities):

Parser parser = ParserBuilder.createDefaultParser();
parser.parse("path/file.dxf", DXFParser.DEFAULT_ENCODING);
DXFDocument doc = parser.getDocument();
DXFlayer layer = doc.getDXFLayer("layer_name");
List<DXFCircle> arcs = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_CIRCLE);

The documentation is a bit incomplete, but it has decent javadocs and clean api.