Interactive transform from script

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

linsnos
Posts: 3
Joined: Wed Nov 14, 2012 9:28 am

Interactive transform from script

Postby linsnos » Wed Nov 14, 2012 9:49 am

Hi!

I'm trying to scale an active and selected vertex group via an UI Panel with a custom property. I tried using bpy.ops.transform.resize and bpy.ops.transform.transform in the update method of the custom property. That did not work well, since each time the property is changed by the user in the panel, the transform is applied on the last transformed mesh, incrementally.

I would like to find a way to let the user scale the mesh interactively in the same way as when the key S is used. Is that possible? Is there a python modal operator I have missed?

/Tobias

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Wed Nov 14, 2012 12:18 pm

transform operators are C live operators, you can call them via python like

bpy.ops.transform.resize('INVOKE_DEFAULT')

but your operator must then be called from 3d view (spacebar menu or operator button from 3d view's tool panel)

you can write your own modal python operators, but they will run way less responsive compared to C operators.
I'm sitting, waiting, wishing, building Blender in superstition...

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Wed Nov 14, 2012 12:49 pm

here's an example:

Code: Select all

import bpy


def main(context):
    for ob in context.scene.objects:
        print(ob)


class SimpleOperator2(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator2"
    bl_label = "Simple Object Operator2"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):

        context.object.location.y += 1
        return {'FINISHED'}
   
class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        #main(context)
        bpy.ops.mesh.select_all(action='SELECT')
        print(bpy.ops.transform.resize('INVOKE_DEFAULT'))
        bpy.ops.mesh.select_all(action='DESELECT')
        context.object.location.z += 2
        print(context.active_operator)
        bpy.ops.object.simple_operator2()
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)
    bpy.utils.register_class(SimpleOperator2)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    bpy.utils.unregister_class(SimpleOperator2)


if __name__ == "__main__":
    register()

    # test call
    #bpy.ops.object.simple_operator()


the problem is, that the last operator has already been executed while the transform is running. Same applies to changes to the object (z-location).
I'm sitting, waiting, wishing, building Blender in superstition...

linsnos
Posts: 3
Joined: Wed Nov 14, 2012 9:28 am

Postby linsnos » Wed Nov 14, 2012 3:10 pm

Thank you very much!

I will try it out and see the effects.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests