From 47a38eceb395887d5cce220ff882f525ca06c4b7 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 18 Dec 2018 21:49:27 -0200 Subject: [PATCH] Arch: more thorough file search in arch references --- src/Mod/Arch/ArchReference.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Mod/Arch/ArchReference.py b/src/Mod/Arch/ArchReference.py index a7e90e1f34..744af1840c 100644 --- a/src/Mod/Arch/ArchReference.py +++ b/src/Mod/Arch/ArchReference.py @@ -172,7 +172,15 @@ class ArchReference: elif os.path.exists(altfile): filename = altfile else: - return None + # search for subpaths in current folder + filename = None + subdirs = splitall(os.path.dirname(filename)) + for i in range(len(subdirs)): + subpath = [currentdir]+subdirs[-i:]+[basename] + altfile = os.path.join(*subpath) + if os.path.exists(altfile): + filename = altfile + break return filename def getPartsList(self,obj,filename=None): @@ -525,3 +533,19 @@ class ArchReferenceCommand: if FreeCAD.GuiUp: FreeCADGui.addCommand('Arch_Reference', ArchReferenceCommand()) + + +def splitall(path): + allparts = [] + while 1: + parts = os.path.split(path) + if parts[0] == path: # sentinel for absolute paths + allparts.insert(0, parts[0]) + break + elif parts[1] == path: # sentinel for relative paths + allparts.insert(0, parts[1]) + break + else: + path = parts[0] + allparts.insert(0, parts[1]) + return allparts