6
$\begingroup$

Besides the point but why is this not working as a default stack is expected to work?

I'm trying to get an operator to call another operator and wait for the operator's response before proceeding.

Doing so with sub-process doesn't work - apparently it needs to be fed "INVOKE_REGION_WIN" and that only works when calling it directly.

Doing so natively doesn't work. can't even loop like you would do for any File/IO transaction of a dialog (str = dialog(), if str!="" > move on else wait )

what's the proper way to do this for the Blender API?

NOTE: This is not a common "dialog" issue, we need to wait for the additional operator to completely finish and return {'FINISHED'}

same as it would if you stack 2 functions within one another ...

Edit. Adding in a code sample that doesn't work but it's closer then I got out of anything else.

def modal(self, context, event):
    if self.fileimport == {'FINISHED'}:
        bpy.ops.object.select_all(action='DESELECT')
        print("finished")
        return {'FINISHED'}
    else:
        print(self.fileimport,context,event)
        return {'PASS_THROUGH'}

def invoke(self, context, event):
    self.fileimport = bpy.ops.import_scene.fbx("INVOKE_REGION_WIN")
    context.window_manager.modal_handler_add(self)
    return {'RUNNING_MODAL'}

The problem with that is that the result copyed to file import is really only passed once at the start. Getting the modal function update it means locking up blender in a loop...

$\endgroup$
2
  • $\begingroup$ Yes you either let blender freeze while you wait for it to finish or you run a modal operator that allows the window to get updated. Have a look at this solution for doing a long process in the background and allowing the user to stop it. $\endgroup$
    – sambler
    Commented May 29, 2019 at 9:47
  • $\begingroup$ My problem there would be the fact that blender doesn't support an "event" style or "stack" approach by default. Basically if a user cancels the event the operator remains open - which in my case is OK, sooner or later something will be added to the scene. I think it's just some lacking blneder integration limitation for the moment. They need to add a specific operator to better handle deferred user input requests. basically a system to enable piggybacking to the open/close events of any modal window generated within the same call stack. $\endgroup$ Commented Jun 1, 2019 at 7:07

1 Answer 1

0
$\begingroup$

Path of least resistance. This works but it's hardly programmatically sound. If anyone has any other functioning solution, I'm all ears.

sceneobjects = 0
currentobjects = 0

def modal(self, context, event):
    if self.currentobjects > self.sceneobjects:
        bpy.ops.object.select_all(action='DESELECT')
        print("finished")
        return {'FINISHED'}

    self.currentobjects = len(bpy.data.objects)
    print(context.window_manager)
    return {'PASS_THROUGH'}

def invoke(self, context, event):
    #save current number of objects on scene
    self.sceneobjects = len(bpy.data.objects)
    #start the import
    bpy.ops.import_scene.fbx("INVOKE_REGION_WIN")
    context.window_manager.modal_handler_add(self)
    return {'RUNNING_MODAL'}
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .