3

Is there any open-source Java or JavaScript library available to parse .dwg files and get the objects from it.

I would like to extract data from a table of text for my project.

It seems that the AutoCAD developer community prefers .NET and C/C++ over JAVA.

The only free alternative I found is by converting .dwg to .dxf first and using the Kabeja lib to read from it.

user3336544
  • 211
  • 1
  • 4
  • 11
  • try this http://sourceforge.net/projects/jdwglib/ – unique_ptr Aug 07 '15 at 09:45
  • i think this project is dead... i contacted the author but had no reply after a few days... Besides, .dwg format evolves very often and the last commit for the library is a few years ago.. – user3336544 Aug 07 '15 at 14:59
  • you could checkout the project and do slite modifications, or you do the other way around, as we did here, file handling is native ( C/C++ ) and use JNI to inetract with java – unique_ptr Aug 07 '15 at 15:03
  • Er, Java and JavaScript are something different. – Thomas S. Aug 08 '15 at 10:38

4 Answers4

9

The Teigha library from opendesignaliance has C++, C#, and Java interface. Teigha is the alternative of RealDWG and it is widely used by many CAD software vendors. It is stable and has the power to read/edit/write dwgs without problem. We have more than 3 years of experience with it and I can say it is excellent and a lot cheaper. When we were at the point to choose between RealDWG and Teigha we chose Teigha and I am glad we did it.

Leveraging SWIG to Create Teigha for Java

In 2013, ODA used the Java support provided by SWIG to create "Teigha for Java". Teigha for Java includes the following:

Java access to the full Teigha API for both .dwg and .dgn files. Support for Windows, Linux and Mac platforms. API very similar to Teigha.NET, simplifying the transition between languages.

Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
  • 1
    [Here](http://www.opendesign.com/join) you can find all the different Join options. [Here](http://www.opendesign.com/education) is for educational/research specific. They say that it is free for that purpose. You need to submit application though. – Ognyan Dimitrov Aug 10 '15 at 08:26
  • 1
    @OgnyanDimitrov : Good answer, I have a question : Importing a autocad file into java means converting the autocad lines to `Point`s in java where each `Point` has two coordinates `x` and `y` ? so each autocad line will be two `Point`s in java ? – Jad Chahine Apr 20 '16 at 19:11
  • 1
    The Teigha(BricsCAD) lib has its own classes just like RealDWG(AutoCAD) has it own classes. No class from the CAD library is "translated" to a Java class. Each Point3d, Point2D, Polyline, Line, Arc, Circle, MText in AutoCAD has corresponding class - Point3D, Point2D, Polyline, Line, etc. - in Teigha. The code from AutoCAD is almost source code compatible with Teigha ( on API level ) even though the internal implementation is not the same. We migrated one big app from AutoCAD to BricsCAD and maintain and develop two versions (AuCad and BrixCAD) with the same code with very little to no effort. – Ognyan Dimitrov Apr 21 '16 at 08:11
  • "When we were at the point to choose between RealDWG and Teigha we chose Teigha and I am glad we did it." ... I chose RealDwg and I'm not glad I did it, for those keeping score. – CAD bloke Aug 01 '18 at 23:49
  • @CADbloke can you provide a link to the Java interface of RealDWG, please? I searched around for Java interface in RealDWG but I could not find it! – Ognyan Dimitrov Aug 02 '18 at 11:43
  • @CADBloke is this really a link to the RealDWG java interface? When I opened it it points to Teigha `s Java interface. – Ognyan Dimitrov Aug 02 '18 at 12:04
  • @OgnyanDimitrov No, the Autodesk RealDwg library only uses .NET or C++. The link is to a competitor library. Autodesk doesn’t do Java. – CAD bloke Aug 02 '18 at 19:34
8

Credits to all who have answered, I've tested all your proposition and here's what I've found , as of 2015:

There is currently no free AND reliable solution to read and manipulate .dwg and .dxf files. This applies especially to latest versions of AutoCAD, ex : Autocad 2010, Autocad 2013 etc, RF 2013, RF 2010.

Reliable (and expensive) solutions would be Teigha by ODA (2000$ a year) and RealDWG in C# by Autocad (5000$ a year)...

Cheaper alternatives are as such :

  • AutoCAD I/O for 10$ per month (as suggested by Augusto Gonclaves), but limited functionalities for now.
  • writing LISPS routine and running them with a SCRIPT file in a paid instance of AutoCAD 2015/2016..
  • wait for a more complete implementation of AutoCad Core Console..

Open-source libraries such as Kabeja and YCad may be able to deal with older AutoCAD versions but do not expect much from them as these projects are inactive since a few years ago. It's worth to keep an eye out for Apache Tika though, since they started writing parsers for .dwg files but development has been slow.

On a personal note, I think that AutoDesk has a strong and selfish monopoly on the CAD market now and they are making it difficult for others to join in. The format's version of .dwg files changes so often and I guess open-source developers will have to give up at some point and use the official product instead.

Let's hope for more open-source solutions in the coming years

user3336544
  • 211
  • 1
  • 4
  • 11
  • Apache Tika's DWGParser is currently limited to reading file headers. Are they planning on creating a reader for DWG content as well? – a different ben Apr 18 '18 at 01:13
2

Autodesk developed AutoCAD mainly with a C++ and offers plug-in support for C++, .NET, JavaScript, VBA and LISP, that's why there is no native Java support. All of those will require AutoCAD installed on the machine.

Alternatively, you can use the AutoCAD I/O webservice, that is basically a running instance on the cloud, to run custom code and extract data or create new drawings. That will have support for all DWG features. Check http://developer.autodesk.com

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • Yeah AutoCAD seems to hate Java... Im trying to develop a plugin for Nuxeo document management system tp parse and read .dwg files but all the libraries available now in Java does not seem to work... the only solution now would be to pass through .dxf converison and use Kabeja to get the objects – user3336544 Aug 07 '15 at 15:06
  • If you have AutoCAD installed on the machine, you can use the developer version accoreconsole.exe, which is a command line version of AutoCAD that can be automated from any language (via command line). Check for this exe at the install folder. Note you cannot copy&paste on different folder machine, this requires a full install of AutoCAD. – Augusto Goncalves Aug 07 '15 at 16:39
  • feedback on accoreconsole.exe : zero guide, zero support, very limited use... i tried DATAEXTRACTION but the console just crashes... ATTOUT is not supported.. very few guides on the internet... it seems that AutoCAD aren't giving a crap about this new functionality for now... – user3336544 Aug 10 '15 at 12:22
2

As you pointed out, use DXF format instead, there is open source java library, YCAD also, that you can use and is very easy to use.

Yoku
  • 307
  • 5
  • 16
  • I've tried using Ycad and it's confusing to compile and import.... besides it does not read Attribut's value in the Blocks... the author may have already abandoned the project... there is no usage examples anywhere... NOTE : Kabeja and Ycad do not read Attribut's value, it is implied that they can but my tests returns null value everytime... I've tried with a few AutoCad versions (R10,R13, 2010, 2013) – user3336544 Aug 13 '15 at 08:43
  • If you refer to DXF specifications pdfs, you can check about the Attribut entities and understand them and write a quick file parser and you can get away with your requirements. – Yoku Aug 13 '15 at 08:55