Previous Thread  Next Thread

chat icon Interactive transform from script

linsnos

Posted: Wed Nov 14, 2012 9:49 am
Joined: 14 Nov 2012
Posts: 3
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
Reply with quote


CoDEmanX

Posted: Wed Nov 14, 2012 12:18 pm
Joined: 05 Apr 2009
Posts: 690
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...
Reply with quote


CoDEmanX

Posted: Wed Nov 14, 2012 12:49 pm
Joined: 05 Apr 2009
Posts: 690
here's an example:

Code:
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...
Reply with quote


linsnos

Posted: Wed Nov 14, 2012 3:10 pm
Joined: 14 Nov 2012
Posts: 3
Thank you very much!

I will try it out and see the effects.
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group