[Solved] Cannot set STEP/IGES export units

Need help, or want to share a macro? Post here!
User avatar
ardenpm
Posts: 9
Joined: Tue Jun 04, 2019 1:46 am

[Solved] Cannot set STEP/IGES export units

Postby ardenpm » Tue Jun 04, 2019 2:13 am

I am trying to set the export units in STEP files that are created by FreeCAD. If I create the following Python script:

Code: Select all

import FreeCAD
import Part
Part.exportUnits("IN")
And run it with python on the command line I get the following output:

Code: Select all

FreeCAD 0.18, Libs: 0.18R16110 (Git)
Traceback (most recent call last):
  File "repo.py", line 3, in <module>
    Part.exportUnits("IN")
RuntimeError: Failed to set 'write.iges.unit'
This is definitely triggering the right code which should be doing what is needed here:

https://github.com/FreeCAD/FreeCAD/blob ... PartPy.cpp

At line 1743, however the

Code: Select all

Interface_Static::SetCVal("write.iges.unit",unit)
call is failing it seems, though it is unclear why. This code seems to have been added sometime ago as a result of this issue:

https://www.freecadweb.org/tracker/view.php?id=931

The commit referenced by the issue doesn't seem to be the correct one, it seems to have been this one:

https://github.com/FreeCAD/FreeCAD/comm ... 476ae3afa2

In any case, currently I don't seem to be able to set the Units correctly in my script, has anyone gotten this to work? I am wondering if perhaps another module needs to be loaded for the OpenCASCADE properties it is trying to set to be available. Just to note, I get the same result with the Python console in the FreeCAD GUI as with using the script on the command line.

This is using the 0.18 stable release. I haven't seen any commits that would really seem to make a difference to this in the master.
Last edited by Kunda1 on Thu Jun 13, 2019 3:15 pm, edited 1 time in total.
Reason: Marked thread as [Solved]
User avatar
ardenpm
Posts: 9
Joined: Tue Jun 04, 2019 1:46 am

Re: Cannot set STEP/IGES export units

Postby ardenpm » Tue Jun 04, 2019 8:36 am

Interestingly, it does seem to work on Linux with FreeCAD 0.16. My testing was on Windows with FreeCAD 0.18.
User avatar
ardenpm
Posts: 9
Joined: Tue Jun 04, 2019 1:46 am

Re: Cannot set STEP/IGES export units

Postby ardenpm » Wed Jun 05, 2019 5:35 am

Just testing further on Linux and I can now confirm the problem exists in 0.18 but not 0.16, so somewhere in between something seems to have gone astray.
User avatar
ardenpm
Posts: 9
Joined: Tue Jun 04, 2019 1:46 am

Re: Cannot set STEP/IGES export units

Postby ardenpm » Wed Jun 12, 2019 10:54 pm

Before reporting as a bug just wondering if anyone has also seen this issue? I've looked through the relevant code but can't find an obvious reason for the issue so it might be downstream in the Open CASCADE side of thing.
wmayer
Site Admin
Posts: 16459
Joined: Thu Feb 19, 2009 10:32 am

Re: Cannot set STEP/IGES export units

Postby wmayer » Thu Jun 13, 2019 9:30 am

Apparently something has changed inside OCC.
With this version it works without problems
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16979 (Git)
Build type: Release
Branch: master
Hash: b60a736c0de2a254069f9813bca88c3763cacfbd
Python version: 2.7.14
Qt version: 5.6.0
Coin version: 4.0.0a
OCC version: 7.0.0
Locale: German/Germany (de_DE)


but it fails with:
OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16979 (Git)
Build type: Release
Branch: master
Hash: b60a736c0de2a254069f9813bca88c3763cacfbd
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

So, between version 7.0 and 7.3 the behaviour has changed.
wmayer
Site Admin
Posts: 16459
Joined: Thu Feb 19, 2009 10:32 am

Re: Cannot set STEP/IGES export units

Postby wmayer » Thu Jun 13, 2019 10:42 am

Apparently IN was silently accepted by older OCC versions but the correct value always was and is INCH.
So, this fixes it: git commit 1b2617358

In your Python code you have to write: Part.exportUnits("INCH")
User avatar
Kunda1
Posts: 8410
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Solved] Cannot set STEP/IGES export units

Postby Kunda1 » Thu Jun 13, 2019 3:16 pm

Marked thread as [Solved] and posted to 0.19 release notes tracking forum thread
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
ardenpm
Posts: 9
Joined: Tue Jun 04, 2019 1:46 am

Re: [Solved] Cannot set STEP/IGES export units

Postby ardenpm » Thu Jun 13, 2019 11:41 pm

Fantastic. I had tried using INCH but then realised the code was setup with an explicit if test for IN anyway so it wasn't getting passed through. I see the commit also fixes that.