It is not easy to get data only from a .dwg file, but much easier from a .dxf file. So I decided to convert the .dwg file to a .dxf file and just process the .dxf file. This is not fast, but it is also an alternative, as there is no other easy way to process .dwg files.
The converter is located 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 you want to use the graphical interface, you need to install Qt 5, or you can just use it in the 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
source share