开发者

How do I open a DWG file extension with Python?

I have a file with extension .dwg (AutoCAD), and I want to call that file fr开发者_如何学JAVAom a Python console and present it on the web. Is there a module for the .dwg extension or some other solution?


The best format for displaying these online would (imo) definitely be SVG. Recent browsers support SVG rendering natively; older ones (think IE6) may require an SVG plugin

So your best bet is probably using a command line convert tool like cad2svg (this is a free linux command line tool) which converts the DWG files to SVG. You can easily do this that from your Python program (using subprocess).


It's not easy to get data just from .dwg file, but much more easier from a .dxf file. So I choose to convert a .dwg file to a .dxf file, and just handle the .dxf file. This is not fast, but it is also an alternative, since there is no other easy way to handle .dwg files.

The converter is at https://www.opendesign.com/guestfiles/TeighaFileConverter.

My OS is CentOS 6.5 (GCC 4.4.7), so I choose Teigha File Converter for Linux 64-bit (RPM).

#Install some qt5 lib
yum install -y qt5*

# If your libstdc++.so.6 has GLIBCXX>=15, you can pass the following three steps (using strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX to find)
mv libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6.0.20
mv /usr/lib64/libstdc.so.6 /usr/lib64/libstdc.so.6.bk
ln /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc.so.6

# Install TeighaFileConverter
rpm -i --nodeps TeighaFileConverter_QT5_lnxX64_4.7dll.rpm

If you want to use the graphical interface, you need to install Qt 5, or you can just use it in terminal or use it as shell commands in your program.

TeighaFileConverter 'input_folder' 'output_folder' "output_version" "output_type" "recurse_folder" "audit" -platform offscreen
# 'input_folder' can't be same with output_folder
# For example, convert dwg to dxf
TeighaFileConverter ./ ./dxf "ACAD10" "DXF" "0" "0" -platform offscreen


GNU LibreDWG (GitHub mirror) is the canonical answer in late 2021. Hilariously forked from the now defunct LibDWG project documented in ...wait for it Esperanto, LibreDWG:

  • Optionally installs Python 3 bindings (enabled by default).
  • Optionally installs DWG→DXF converters (enabled by default).
  • Is unsurprisingly licensed under the GPL 3.0 (fine for web backends; less fine everywhere else).
  • Supports almost the entirety of R2010+.

Seriously, it's hot. LibreDWG is the only sane choice that still matters. Let's embrace sanity, everybody.


Maybe there will be something you can use from this Summer Of Code project

http://groups.fsf.org/wiki/LibreDWG/SummerOfCode

http://groups.fsf.org/wiki/LibreDWG

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜