What I want to do is go through a directory and find all the blend files. Then go through each of those .blends and if ‘group x’ exists I want to link it, then add an instance of that group to the scene.
I’m stuck on the first part, I can’t find a method to get a list of files in a directory. I can imagine the rest is straight forward after I study the api more and fiddle around with it.
I know GameLogic has a getBlendFileList, but cannot find similar for regular blender.
hi Rhys S,
you will find the code in bundled scripts, e.g. import_dxf.py (def multi_import(DIR): or final “DEBUG ONLY”)
There you have to replace:
EXT = ‘.dxf’ with EXT = ‘.blend’
import os
def locate(substr, root=os.getcwd()):
for path, dirs, files in os.walk(root):
for filename in files:
if substr in filename:
yield os.path.abspath(os.path.join(path, filename))
Given a name pattern:
import os
import re
def locate(pattern, root=os.getcwd()):
regex = re.compile(pattern)
for path, dirs, files in os.walk(root):
for filename in files:
if regex.match(filename):
yield os.path.abspath(os.path.join(path, filename))