1
$\begingroup$

I am trying to run one of Blenders modal operators from within an addon / self written operator. Is it possible to do this in a way so the user will be able to benefit from the modal style of that operator? Example: Within my own operator I would like the user to add an on the fly python defined node group in the node editor. When you do this the standard way (Shift A + click on a node) Blender attaches the node to the mouse cursor and allows to drop it in a specific location which the user can decide by moving the mouse and then clicking. Can I call the operator bpy.ops.node.add_node() from Python in a way that it will add a custom node group I created, but remain in the modal function until the user clicks? Is this possible at all?

$\endgroup$
3
$\begingroup$

Adding a node and moving a node are two different actions. You will find that the two operators invoked when adding a node are bpy.ops.node.add_node() and bpy.ops.node.translate_attach_remove_on_cancel()

Using an example from a small addon I wrote a while ago -

def execute(self, context):
    if context.active_object.type == 'ARMATURE' \
            and context.active_object.mode == 'EDIT':
        bpy.ops.armature.duplicate()
        for b in context.selected_bones:
            b.parent = None
    else:
        bpy.ops.object.duplicate()
        bpy.ops.object.parent_clear(type='CLEAR')
    return bpy.ops.transform.translate('INVOKE_DEFAULT')

you can see that the object gets duplicated, with a different operator used for armatures that are being edited, then the parent info gets cleared and the translate operator is called at the end.

$\endgroup$
  • 1
    $\begingroup$ thanks man, your answer made it clear. The fact that it is two different operators was known, but the bit that makes it work the way I wanted is the ('INVOKE_DEFAULT') part. $\endgroup$ – aliasguru Mar 24 '16 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.