View Issue Details

IDProjectCategoryView StatusLast Update
0000931FreeCADFeaturepublic2013-07-09 15:03
Reporterthatcadguy Assigned Towmayer  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version0.12 
Target Version0.14Fixed in Version0.14 
Summary0000931: Can't change STEP/IGES export units through Python interface
DescriptionBy default, STEP/IGES export is in mm. You can change the units by going to Preferences->Part design->Export->Units for export of STEP/IGES. When this happens, DlgSettingsGeneral::saveSettings() is called (/Mod/Part/Gui/DlgSettingsGeneral.cpp) and it does 2 things:
- Change the units in BaseApp/Preferences/Mod/Part
- Change the units in OpenCASCADE's settings: write.step.unit and write.iges.unit

Currently, you can only do the 1st part from Python:
params = FreeCAD.ParamGet('User parameter:BaseApp/Preferences/Mod/Part')
params.SetInt('Unit',unit)

However, without doing the 2nd part (e.g. not changing the setting via dialog and only doing the above 2 lines in a script), the STEP/IGES files are still exported as mm.

In order to remedy this, I have constructed the following from DlgSettingsGeneral::saveSettings():

static PyObject * setExportUnits(PyObject *self, PyObject *args)
{
    int unit;
    if (!PyArg_ParseTuple(args, "i", &unit))
        return NULL;
    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part");
    hGrp->SetInt("Unit", unit);
    switch (unit) {
        case 1:
            Interface_Static::SetCVal("write.iges.unit","M");
            Interface_Static::SetCVal("write.step.unit","M");
            break;
        case 2:
            Interface_Static::SetCVal("write.iges.unit","IN");
            Interface_Static::SetCVal("write.step.unit","IN");
            break;
        default:
            Interface_Static::SetCVal("write.iges.unit","MM");
            Interface_Static::SetCVal("write.step.unit","MM");
            break;
    }
}

The following should be added to the Python methods registration table:
{"setExportUnits", setExportUnits, METH_VARARGS, "setExportUnits(unit) -- Set units for exporting STEP/IGES files"}

Not sure where this function should be added, I was thinking /src/Mod/Part/App/AppPartPy.cpp.

Anyway, the function should work and is straightforward, I'd appreciate it if someone more familiar with FreeCAD's code as a whole could look it over and add it to the appropriate place. Thanks!
TagsNo tags attached.
FreeCAD Information

Activities

thatcadguy

2012-12-23 20:55

reporter   ~0002761

The following includes should be present as well:
#include <Interface_Static.hxx>
#include <Base/Parameter.h>
#include <App/Application.h>

wmayer

2013-07-09 15:03

administrator   ~0003368

git show a66d944

Issue History

Date Modified Username Field Change
2012-12-23 20:43 thatcadguy New Issue
2012-12-23 20:55 thatcadguy Note Added: 0002761
2012-12-23 22:01 Jriegel Status new => acknowledged
2012-12-27 13:08 wmayer Target Version => 0.14
2013-07-02 03:51 wmayer Status acknowledged => assigned
2013-07-02 03:51 wmayer Assigned To => wmayer
2013-07-09 15:03 wmayer Note Added: 0003368
2013-07-09 15:03 wmayer Status assigned => closed
2013-07-09 15:03 wmayer Resolution open => fixed
2013-07-09 15:03 wmayer Fixed in Version => 0.14