easyw / kicadStepUpMod

kicadStepUp: ECAD to MCAD FreeCAD WorkBench
483 stars 61 forks source link

KiCAD 6 variables not supported #159

Open fromsawa opened 1 year ago

fromsawa commented 1 year ago

When importing a KiCAD v6 PCB, models usually contain ${KICAD6_3DMODEL_DIR} (and in my case ${KICAD_USER_3DMODEL_DIR}).

I suggest the following change (so that ${ENV} is generally expanded by environment variables):

diff --git a/kicadStepUptools.py b/kicadStepUptools.py
index e1ec7cc..92fc86b 100644
--- a/kicadStepUptools.py
+++ b/kicadStepUptools.py
@@ -4424,7 +4424,12 @@ def Load_models(pcbThickness,modules):
             say('adjusting Local Path')
             say('step-module-replaced '+step_module)
         elif (step_module.find('${')!=-1) and encoded==0:  #extra local ${ENV} 3D path
-            step_module= re.sub('\${.*?}/', '', step_module)
+            match = re.search(u'\${([^}]+)}(.*)', step_module)
+            if match:
+                envvar=match.group(1)
+                step_module=os.getenv(envvar, envvar)+match.group(2)
+            else:
+                step_module= re.sub('\${.*?}/', '', step_module)
             #step_module=step_module.decode("utf-8").replace(u'${}/', u'')
             step_module=step_module.replace(u'${}/', u'')
             step_module=step_module.replace(u'"', u'')  # name with spaces
easyw commented 1 year ago

@fromsawa kicad environment variables are not available in FreeCAD through python... There is a FC preference page in which you can preset up to 4 different 3D model searching paths

image