set import preference by Python not possible
set import preference by Python not possible
I would like to set some import preferences but would not like to change the FreeCAD preference by Python. Means for example I would like to set SEPARATE_OPENINGS = True for one import or as long as getPreferences is called from importIFC. The problem is getPreferences is called inside the insert method.
How about to make some changes to be able to do such imports and export. I played a bit but could not find a smart solution so far. Thus I have nothing to show to make a suggestion.
https://github.com/FreeCAD/FreeCAD/blob ... FC.py#L281
May be some dictionary. Get the preferences as a dictionary, reset one preference, call insert method with this dictionary. If it is not given the insert method uses getPreference. This might be simpler by the use of the globals, but I am not sure.
bernd
How about to make some changes to be able to do such imports and export. I played a bit but could not find a smart solution so far. Thus I have nothing to show to make a suggestion.
https://github.com/FreeCAD/FreeCAD/blob ... FC.py#L281
May be some dictionary. Get the preferences as a dictionary, reset one preference, call insert method with this dictionary. If it is not given the insert method uses getPreference. This might be simpler by the use of the globals, but I am not sure.
bernd
Re: set import preference by Python not possible
This is a classic case similar to using dependency injection to separate dependencies. In this case, the preferences is a dependency.
It should be refactored so that there are no globals, that the preferences is its own object, which is passed into the insert() function as an argument. This allows you to overload the preferences.
Would you like to give a shot to this refactoring? If not, I don't mind doing this refactor.
It should be refactored so that there are no globals, that the preferences is its own object, which is passed into the insert() function as an argument. This allows you to overload the preferences.
Would you like to give a shot to this refactoring? If not, I don't mind doing this refactor.
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
Re: set import preference by Python not possible
yeah that importer was never really thought to be used from python yet... There are a lot of very easy improvements to bring...
Re: set import preference by Python not possible
once this is implemented we would be able to set up some unit tests. I may help here. Since I make heavy usage of ifc exporter this would really be very useful. Over the years it has happened a few times we gone introduce a regresion wheras make some improvements on some other place.
Re: set import preference by Python not possible
Sorry, I was working on another PR related to IFC import and hoped for it to be merged first to prevent merge conflicts ( https://github.com/FreeCAD/FreeCAD/pull/2259/ ) - I'll submit the PR for the refactor tonight (or tomorrow)!
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
Re: set import preference by Python not possible
Great, keep in mind: FreeCAD moto is: It's done when it's done!
Re: set import preference by Python not possible
small reminder ...
Re: set import preference by Python not possible
from another topic ...
AFAIR I tried something similar myself, but failed due to the global variables. But I can not remember. I am happy with anything which would work.
BTW: it is not just me. If we can set the preference we can start to make unit tests! Since they should be passed no matter which setting the user have on his machine, we need to set them for unit tests.
yorik wrote: ↑Tue Aug 20, 2019 10:50 pm I did some more cleaning and move more stuff from importIFC.py to importIFCHelper.py
This is becoming a lot cleaner now...
I had an idea to solve the problem of allowing users (I mean bernd ) to override settings while still read the preferences again at each import (in case they were modified inbetween):
we move all the import code to another function, and we make insert() a very minimal one:
so you can do that yourself, and override any of the settings after readpreferences()Code: Select all
def insert(file): readpreferences() do_the_real_import()
AFAIR I tried something similar myself, but failed due to the global variables. But I can not remember. I am happy with anything which would work.
BTW: it is not just me. If we can set the preference we can start to make unit tests! Since they should be passed no matter which setting the user have on his machine, we need to set them for unit tests.