diff --git a/src/App/Application.h b/src/App/Application.h index 264254df3..dd109789e 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -279,6 +279,7 @@ private: static PyObject* sAddExportType (PyObject *self,PyObject *args,PyObject *kwd); static PyObject* sGetExportType (PyObject *self,PyObject *args,PyObject *kwd); static PyObject* sGetResourceDir (PyObject *self,PyObject *args,PyObject *kwd); + static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args,PyObject *kwd); static PyObject* sGetHomePath (PyObject *self,PyObject *args,PyObject *kwd); static PyObject* sLoadFile (PyObject *self,PyObject *args,PyObject *kwd); diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index cda2a80fd..8d13296c5 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -80,6 +80,8 @@ PyMethodDef Application::Methods[] = { "Get the name of the module that can export the filetype"}, {"getResourceDir", (PyCFunction) Application::sGetResourceDir ,1, "Get the root directory of all resources"}, + {"getUserAppDataDir", (PyCFunction) Application::sGetUserAppDataDir ,1, + "Get the root directory of user settings"}, {"getHomePath", (PyCFunction) Application::sGetHomePath ,1, "Get the home path, i.e. the parent directory of the executable"}, @@ -525,6 +527,15 @@ PyObject* Application::sGetResourceDir(PyObject * /*self*/, PyObject *args,PyObj return Py::new_reference_to(datadir); } +PyObject* Application::sGetUserAppDataDir(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) +{ + if (!PyArg_ParseTuple(args, "")) // convert args: Python->C + return NULL; // NULL triggers exception + + Py::String user_data_dir(Application::getUserAppDataDir(),"utf-8"); + return Py::new_reference_to(user_data_dir); +} + PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/) { if (!PyArg_ParseTuple(args, "")) // convert args: Python->C diff --git a/src/Mod/Fem/MechanicalMaterial.py b/src/Mod/Fem/MechanicalMaterial.py index a90d43845..5d9086f76 100644 --- a/src/Mod/Fem/MechanicalMaterial.py +++ b/src/Mod/Fem/MechanicalMaterial.py @@ -139,6 +139,10 @@ class _MechanicalMaterialTaskPanel: if new_index != -1: self.form.comboBox_MaterialsInDir.setCurrentIndex(new_index) self.set_mat_params_in_combo_box(matmap) + else: + print "Cannot find previously used material \'{}\' - setting to \'None\'".format(material_name) + i = self.form.comboBox_MaterialsInDir.findText('None') + self.chooseMat(i) def print_mat_data(self, matmap): print 'material data:' @@ -197,5 +201,11 @@ class _MechanicalMaterialTaskPanel: material_name = os.path.basename(i[:-l]) self.form.comboBox_MaterialsInDir.addItem(material_name) + user_mat_dir = FreeCAD.getUserAppDataDir() + "/Materials" + user_mat_path_list = glob.glob(user_mat_dir + '/*' + mat_file_extension) + for i in user_mat_path_list: + material_name = os.path.basename(i[:-l]) + self.form.comboBox_MaterialsInDir.addItem(material_name) + self.pathList = self.pathList + user_mat_path_list FreeCADGui.addCommand('Fem_MechanicalMaterial',_CommandMechanicalMaterial())