5

I want to analyze dwg file. Is it possible?

I'm trying to write a some program that could analyze the content of the .dwg file. for example the program could say if a door in a building model could be opened.

I've found this article that explains how to read autoCAD file. also i've seen some program that can open and view .dwg files, but nothing to analyze the content.

I want to know if there is something similar to that, that analyze the content of the .dwg file, and to know if there are SDK that can help me analyze?

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
  • You can write software to run within AutoCAD (requires AutoCAD - AutoLisp, et. al.) or software that runs without AutoCAD (Autodesk RealDWG license, C++ / C#). The only other options are third-party software libraries. As it is though, this is too broad and/or asking for off-site resource. – crashmstr May 16 '16 at 13:03
  • do you have a 2D or 3D model os this building? – Augusto Goncalves May 16 '16 at 21:29
  • @AugustoGoncalves 2D model – No Idea For Name May 17 '16 at 05:23
  • 2
    Basically, no. The "doorness" of an object is not explicit in a DWG entity. You'd need some algorithm to recognize shapes from their features, i.e. "teach" the software what a door *is*. And if the fact that it can be opened is part of the definition (e.g. the presence of a lumen identifies a door), you can no longer ask whether a door can be opened: doors that can't won't be recognized as doors in the first place. You **can** do this if you have a standard, e.g. you say that a door **must** be a `GROUP` tagged DOOR (not a bunch of base LINE entities arranged in the shape of a door). – LSerni May 19 '16 at 12:00
  • @NoIdeaForName indeed for 2D my answer below would be the same... just in case you have 3D models (with Solids) it may be less hard with Intersects – Augusto Goncalves May 23 '16 at 17:22

4 Answers4

6

You could, but it's not easy.

An AutoCAD .DWG file is basically just geometry (lines and arcs). You may have some well organized files with block, let's say a "Door" block, but it's not 100% confident: for instance, you may have "Door1" and "Out Patio Door" as a block name.

For both cases, the way the main problem is to understand the geometry and interpret somehow. Assuming you can, then you have some options of paths:

  • Run an in-process plugin on AutoCAD: this can be accomplished in C++, .NET (C#, VB.NET), LISP or VBA. There are tons of resources, like DevCenter, blog and blog.
  • Use as a library to access the objects, like RealDWG or other open source. This might be tricky and requires programming (like above).
  • Use a webservice, like AutoCAD I/O, to upload a .DWG and a .DLL (.NET) code that will analyse your drawing.

To interpret the geometry (with any of the above), the BRep API is the best way to analyze the geometry, like intersection points and other relations. The the blog you'll find some samples around it, but I don't believe there is something on this area. Check this and this.

Finally, as a summary, with .NET you'll need the Autodesk.AutoCAD.DatabaseServices namespace with Line, Arc, BlockReference and the respective IntersectWith methods to do some basic analysis.

Now if you have an AutoCAD Architecture .DWG drawing, it might be easier as some basic objects are available as part of the APIs, like Walls and Doors. I don't believe that's the case, but if so, check at this link.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
1

RealDWG costs unreal money. But you can use Teigha. Its cost is less, but its capabilities are great. Also you can read DWG Specification.

Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
1

The existing SDKs mentioned will allow you to examine the AutoCAD entities and data in a dwg file. Recognizing AutoCAD entities (lines, arcs, blocks etc.) as something of interest to you (door, window, cabinet etc.) would require that you identify these entities as such. You could do that with attributes or hidden data embedded in the AutoCAD entities. Attributes are built-in functionality in AutoCAD. Hidden embedded data would require custom programming.

mohnston
  • 737
  • 1
  • 6
  • 18
0

You can use the open source LibreDWG library to run a number of AutoCAD native commands such as DATAEXTRACTION that are able to parse the file and extract the contents.

Mixpeek is one free option that does just this:

pip install mixpeek

from mixpeek import Mixpeek  
  
mix = Mixpeek(  
    api_key="my-api-key"  
)  
  
mix.index("design_spec.dwg")

This /index endpoint will extract the contents of your DWG file, then you can search for terms for analysis.

mix.search("retainer", include_context=True)

[  
    {  
        "file_id": "6377c98b3c4f239f17663d79",  
        "filename": "design_spec.dwg",  
        "context": [  
            {  
                "texts": [  
                    {  
                        "type": "text",  
                        "value": "DV-34-"  
                    },  
                    {  
                        "type": "hit",  
                        "value": "RETAINER"  
                    },  
                    {  
                        "type": "text",  
                        "value": "."  
                    }  
                ]  
            }  
        ],  
        "importance": "100%",  
        "static_file_url": "s3://design_spec_1.dwg"  
    }  
]

More documentation here: https://docs.mixpeek.com/ and a writeup: https://medium.com/@mixpeek/search-the-contents-of-dwg-files-with-python-1fd2fc0772af

danywigglebutt
  • 238
  • 1
  • 17