No Idea For Name
No Idea For Name

Reputation: 11577

AutoCAD - Is it possible to analyze .dwg file?

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?

Upvotes: 5

Views: 9573

Answers (4)

danywigglebutt
danywigglebutt

Reputation: 269

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

Upvotes: 0

mohnston
mohnston

Reputation: 749

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.

Upvotes: 1

Andrey Bushman
Andrey Bushman

Reputation: 12486

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

Upvotes: 1

Augusto Goncalves
Augusto Goncalves

Reputation: 8574

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.

Upvotes: 6

Related Questions