Skip to content

Commit 05bee3a

Browse files
berndhahnebachyorikvanhavre
authored andcommitted
Materials: use material directory pref from FEM
1 parent 1a4b2cb commit 05bee3a

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/Mod/Material/MaterialEditor.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,39 @@ def __init__(self, obj = None, prop = None, material = None):
7474
self.updateContents(d)
7575

7676

77+
def getMaterialResources(self):
78+
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material/Resources")
79+
use_built_in_materials = self.fem_prefs.GetBool("UseBuiltInMaterials", True)
80+
use_mat_from_config_dir = self.fem_prefs.GetBool("UseMaterialsFromConfigDir", True)
81+
use_mat_from_custom_dir = self.fem_prefs.GetBool("UseMaterialsFromCustomDir", True)
82+
if use_mat_from_custom_dir:
83+
custom_mat_dir = self.fem_prefs.GetString("CustomMaterialsDir", "")
84+
# later found cards with same name will override cards
85+
# FreeCAD returns paths with / at the end, thus not os.sep is needed on first +
86+
self.resources = []
87+
if use_built_in_materials:
88+
self.resources.append(FreeCAD.getResourceDir() + "Mod" + os.sep + "Material" + os.sep + "StandardMaterial")
89+
if use_mat_from_config_dir:
90+
self.resources.append(FreeCAD.ConfigGet("UserAppData") + "Material")
91+
if use_mat_from_custom_dir:
92+
custom_mat_dir = self.fem_prefs.GetString("CustomMaterialsDir", "")
93+
if os.path.exists(custom_mat_dir):
94+
self.resources.append(custom_mat_dir)
95+
self.outputResources()
96+
97+
98+
def outputResources(self):
99+
print('locations we gone look for material cards:')
100+
for path in self.resources:
101+
print(' ' + path)
102+
print('\n')
103+
104+
77105
def updateCards(self):
78106
"updates the contents of the materials combo with existing material cards"
79-
# look for cards in both resources dir and a Materials sub-folder in the user folder.
80-
# User cards with same name will override system cards
81-
# FreeCAD returns paths with / at the end, thus not os.sep is needed on first +
82-
paths = [FreeCAD.getResourceDir() + "Mod" + os.sep + "Material" + os.sep + "StandardMaterial"]
83-
ap = FreeCAD.ConfigGet("UserAppData") + "Material"
84-
if os.path.exists(ap):
85-
paths.append(ap)
86-
# print('locations we gone look for material cards:')
87-
# for path in paths:
88-
# print(' ' + path)
89-
# print('\n')
107+
self.getMaterialResources()
90108
self.cards = {}
91-
for p in paths:
109+
for p in self.resources:
92110
for f in os.listdir(p):
93111
b,e = os.path.splitext(f)
94112
if e.upper() == ".FCMAT":

0 commit comments

Comments
 (0)