DWG suport in Draft - Request for help

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

DWG suport in Draft - Request for help

Postby yorik » Sun Apr 21, 2013 5:57 pm

With the latest commit I added preliminary support for DWG support in the Draft module.

It's very simple, really. The openDesign alliance has released a standalone multiplatform freeware tool called "Teigha File Converter" ( http://www.opendesign.com/guestfiles/Te ... eConverter ). Teh DWG import/export script in the Draft module simply uses it to convert dwg files to dxf, then imports them with the dxf import script, and the other way round for export. All entities supported by the dxf script are supported here too.

The problem, and where I need your help:

I only have a Linux machine. I can find the TeighaFileConvertor executable on linux. I have no idea where it resides on windows and mac. If you want to help, you can do this:

1) Install the teigha file converter for Windows or Mac
2) Check that it runs fine
3) Find where it installed its main executable (TeighaFileConvertor, TeighaFileConvertor.exe, something like that)
4) Check that it works from a command line window by issuing something like this: Path-To-TeighaFileConverter "Path-To-Input-Directory" "Path-To-Output-Directory" "ACAD2010" "DXF" "0" "1" "Name-Of-A-Test-File.dwg" changing all the path-to... and name-of... by the actual names (the dwg test file must exist in the input dir)

If all this works, just give me the path to the executable (or better, post it here: https://sourceforge.net/apps/mantisbt/f ... hp?id=1103 )

Thanks!
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: DWG suport in Draft - Request for help

Postby NormandC » Sun Apr 21, 2013 9:38 pm

That's a good idea for people who badly need DWG support. The ODA's reverse engineered DWG library is state-of-the-art, many commercial software use it.

From the Mantis ticket description:
The newly freely available multi-platform Teigha converter allows to make a script that imports and exports DWG files in freecad (converting them to/from a temp DXF file).

The script will not include anything (for license compatibility reasons), but will simply check for the presence of the teigha executable on start, and activate DWG support if it is found. If not, a notice is displayed, like the collada import script.
For the heck of it I just tried opening a DWG file from FreeCAD GUI, without Teigha installed. Nothing happens.

How are we supposed to use this? Do we need to use the python console to open/import a DWG file?
renatorivo
Posts: 2245
Joined: Tue Feb 21, 2012 8:07 pm
Location: Torino - Italy

Re: DWG suport in Draft - Request for help

Postby renatorivo » Sun Apr 21, 2013 9:43 pm

Hi,
for now:

in my installation with os Windows7

- default installation patch,
- file in C:\Program Files\ODA\Teigha File Converter 3.08.2 and
- default start window

rename zip -> png

I hope it is useful
Attachments
teigha3.zip
rename .png
(26.71 KiB) Downloaded 280 times
teigha2.zip
rename .png
(43.68 KiB) Downloaded 195 times
teigha1.zip
rename .png
(13.72 KiB) Downloaded 203 times
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DWG suport in Draft - Request for help

Postby yorik » Sun Apr 21, 2013 9:53 pm

normandc wrote:How are we supposed to use this? Do we need to use the python console to open/import a DWG file?
Normally if teigha is found, you have dwg support. If not, you have no dwg support. I'm not sure how you tried to open a dwg file without it activated? Normally you shouldn't have dwg format available in import file types...
renatorivo wrote:file in C:\Program Files\ODA\Teigha File Converter 3.08.2
Perfect, thanks! I forgot that on Win you can choose where to install... Maybe I should add a preference setting in Draft to adjust the path manually... Besides, newer versions will likely install in paths with different number.
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: DWG suport in Draft - Request for help

Postby NormandC » Sun Apr 21, 2013 10:09 pm

yorikvanhavre wrote:Normally if teigha is found, you have dwg support. If not, you have no dwg support. I'm not sure how you tried to open a dwg file without it activated? Normally you shouldn't have dwg format available in import file types...
I know it wasn't listed, I chose "All files" to make DWGs show.

I was trying to make this point:
Mantis wrote:but will simply check for the presence of the teigha executable on start, and activate DWG support if it is found. If not, a notice is displayed, like the collada import script.
At first I didn't see a notice displayed that this was an unsupported file, as I said nothing happened.

But I quit FreeCAD and opened it again and I noticed that this appears in the report view before the pycollada error (which is why I didn't notice it):
During initialization the error No module named importDWG occurred in /home/normand/compilation/freecad-build/Mod/Draft/InitGui.py
I'm not sure why but importDWG.py was not installed in my build folder (I compiled right after pulling your last commit)

So I simply copied it from the freecad source folder to the freecad-build folder, and the error is gone... But there is no notice that DWG support is disabled.

I'm trying to test all scenarios, including newcomers who will ask why they can't open DWG files when you say you included support.

BTW IIRC the report view is not activated by default.
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DWG suport in Draft - Request for help

Postby yorik » Sun Apr 21, 2013 10:15 pm

ah thanks, forgot to update the cmake file...
raulshc
Posts: 40
Joined: Wed Nov 28, 2012 11:34 pm

Re: DWG suport in Draft - Request for help

Postby raulshc » Wed Jan 01, 2014 4:41 pm

Hi Yorik,

I took a look to DWG support tool a few days ago on a Windows based PC. There are some issues in the code of importDWG.py, and therefore, it doesn't work.

First of all corresponds to the path of Teigha converter, in getTeighaConverter() function

Code: Select all

elif platform.system() == "Windows":
     odadir = "C:\Program Files\ODA"
This assign is not advisable because Program files folder may be in many places and take different names depending of the language configurations and architecture platforms over Windows.

See https://en.wikipedia.org/wiki/Program_Files.

Then, the best option is to use the volatile environment variable %ProgramFiles% for the path. For expand it, we can use os.path.expandvars(path) method in python and we shall obtain the correct path in every windows system.

Second, the variable teigha in convertToDxf() and convertToDwg() functions

Code: Select all

cmdline = teigha + ' "' + indir + '" "' + outdir + '" "ACAD2010" "DXF" "0" "1" "' + basename + '"'
is expanded with spaces in the windows consola so the command line cannot running. We can use this simplified code, that works correctly:

Code: Select all

cmdline = '""%s" "%s" "%s" "ACAD2010" "DXF" "0" "1" "%s""' % (teigha, indir, outdir, basename)
Last, the target version for the intermediary DXF files and the output DWG files must be ACAD2000, because it has a good backward for most CAD programs. However, it would be better to change this feature in Edit->Preferences->Draft->Import/Export (choice ACAD version).

I made a patch to correct these errors and Works 100% on my windows systems. I will attach it in #0001103 issue, on our bug tracker, check it on linux systems and integrate it into the master.


Thanks

PDT: Happy new year!!
raulshc
Posts: 40
Joined: Wed Nov 28, 2012 11:34 pm

Re: DWG suport in Draft - Request for help

Postby raulshc » Wed Jan 01, 2014 4:54 pm

raulshc wrote:I made a patch to correct these errors and Works 100% on my windows systems. I will attach it in #0001103 issue, on our bug tracker, check it on linux systems and integrate it into the master.
Aggh, I can't reopen #0001103 issue. I attach the patch here.

Greetings ;)
Attachments
import.patch.zip
ImportDWG.py fixes
(1.61 KiB) Downloaded 371 times
User avatar
yorik
Site Admin
Posts: 11567
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DWG suport in Draft - Request for help

Postby yorik » Wed Jan 01, 2014 9:51 pm

Added the patch. Thanks!