I'm writing an Add-on in which I create a new Collection and then invoke the ImportHelper to load an FBX file. After that I would like to process the loaded data. My Problem is, that my script doesn't wait until the ImportHelper is finished.
I defined the Import Helper like this:
class ImportFBXData(bpy.types.Operator, ImportHelper):
bl_idname = "import_fbx.read_data"
bl_label = "Import FBX"
ImportHelper mixin class uses this
filename_ext = ".fbx"
filter_glob: StringProperty(
default="*.fbx",
options={'HIDDEN'},
maxlen=255,
)
use_setting: BoolProperty(
)
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
def execute(self, context):
bpy.ops.import_scene.fbx(filepath = self.filepath)
return {'FINISHED'}
I start this inside my Operator:
bpy.ops.import_fbx.read_data('INVOKE_DEFAULT')
Everything in front of this call gets executed properly. The File Browser comes up and I can select a file which is loaded properly. Because the File Browser runs modal, everything after it's call runs immediately but there is no data yet. How can I make the rest of the script to wait until I select a file, the FBX conversion is done and the data is loaded in to Blender?
I don't mind if the UI is locked up until the conversion is finished but I definitely need the file browser to select the FBX file.
bpy.data.collections[context.collection.name]iscontext.collectionwhich I assume the idea is to usenew_fbx_collectionso can simply use that reference. Re setting active collection https://blender.stackexchange.com/a/155433/15543 – batFINGER Feb 27 '21 at 20:34obs = [o for o in bpy.data.collections[new_fbx_Collection].all_objects if not o.parent and len(o.children)]now. Many thanks for the suggestion! Dumb copying is the first step to learn but now I begin to understand the actual structure behind the copied lines. – Steve Mar 01 '21 at 11:29