1

I've created a GUI using PyQt5 wich takes shapefiles and one .dwg file as inputs. In the .dwg file, I have a certain amount of standard layers that should be inside. If one or more of those layers is missing, I would like to be able to inform the user which layers are missing.

For example, if the .dwg files must have these layers ('Trees', Roads', 'Houses', 'Lakes' etc.), if 'Roads' is missing, I would like the user to be inform when he launches the GUI.

Using Python I have to use a Python extension/library I guess. But I've looked and PyAcad or PythonCAD don't seem to be very implemented yet. If anyone has used Python for AutoCAD, I am looking for some advice/tips. And if you have an alternative idea for my problem that would be greatly appreciated !

guy16
  • 233
  • 2
  • 3
  • 16
  • I think you should parse the file. I dont know wheter .dwg is ASCII file. If it is then you can parse it. – DigviJay Patil Jun 25 '15 at 08:44
  • @DigviJayPatil .dwg is binary, but .dxf is ASCII i think. – guy16 Jun 25 '15 at 09:29
  • Then you can parse .dxf file – DigviJay Patil Jun 25 '15 at 10:09
  • @DigviJayPatil i've opened the file in notepad++ but it's not an easy file to parse, there are so many information – guy16 Jun 25 '15 at 10:20
  • Find out some keyword from file which will give you required information and then parse file with those keywords – DigviJay Patil Jun 25 '15 at 11:16
  • I don't use Python, but I could do everything in C# referencing the `Autodesk.AutoCAD.Interop` and `Autodesk.AutoCAD.Interop.Common` dlls. Can Python access regular DLL libraries? Do you mind it if Autocad opens in order to check the file? You can try using the that DLL: The `AcadApplication` object is used to open and close Autocad and its documents. The `AcadDocument` object contains the `Layers` collection. – Daniel Möller Jun 25 '15 at 20:18

1 Answers1

3

There is a complication here: if you have a .dwg you cannot convert it to .dxf without AutoCAD installed on the machine.

If you have AutoCAD installed, then use it's APIs to open and manipulate the drawing. This can be done with .NET, C++, JavaScript or any language compatible with COM (including Python).

If you DON'T have AutoCAD installed, there is a cloud API for it: AutoCAD I/O. This is basically a running instance on the cloud that you can use for processing .dwg drawings. That way you can upload a .dwg with a script to list layers. Below is the sequence of commands to list layers:

-layer
?
*

Which should return a list of layers. You can have more with .NET code running on this cloud instance. See more at http://developer.autodesk.com

Let me know what you have (scenario and goal), then I can advise better.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • Thanks a lot! I have AutoCAD but since the tool that I'm creating aims to be distributed to others, they may not have AutoCAD installed (though it is unlikely). Basically, what i am doing is : i have a dwg file as input and i want to know what layers are in this file (just the name of the layers). And I would like to have these names in my Python Script. – guy16 Jun 26 '15 at 10:15