Arch: more thorough file search in arch references

This commit is contained in:
Yorik van Havre
2018-12-18 21:49:27 -02:00
parent b5a3b7d3df
commit 47a38eceb3

View File

@@ -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