The combination of three-point

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

shestakoffvs
Posts: 3
Joined: Sat Dec 15, 2012 3:31 pm

The combination of three-point

Postby shestakoffvs » Sat Dec 15, 2012 3:39 pm

Hi all) I need to write a script for combination two objects in three selected points in each object. I ran into the problem that occurs is that the script is executed immediately, but I needed that he was expecting the moment when the user selects three points. Please tell me how I can implement this, I mean the wait.

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

Postby CoDEmanX » Sat Dec 15, 2012 6:40 pm

you make it an operator and add a poll() which checks for selection, if it there are 3 selected vertices, it it will be possible to execute. User will have to run it though by clicking a button or a menu entry, or use the search popup.

http://www.blender.org/documentation/bl ... e-operator
I'm sitting, waiting, wishing, building Blender in superstition...

shestakoffvs
Posts: 3
Joined: Sat Dec 15, 2012 3:31 pm

Postby shestakoffvs » Sat Dec 15, 2012 7:42 pm

CoDEmanX wrote:you make it an operator and add a poll() which checks for selection, if it there are 3 selected vertices, it it will be possible to execute. User will have to run it though by clicking a button or a menu entry, or use the search popup.

http://www.blender.org/documentation/bl ... e-operator

Thanks, but i found better:

Code: Select all

import bpy


class ModalOperator(bpy.types.Operator):
    bl_idname = "object.modal_operator"
    bl_label = "Simple Modal Operator"

    def __init__(self):
        print("Start")

    def __del__(self):
        print("End")

    def execute(self, context):
        print
        context.object.location.x = self.value / 100.0

    def modal(self, context, event):
        print(event.type)
        if event.type == 'MOUSEMOVE':  # Apply
            self.value = event.mouse_x
            print("sdsd")
            self.execute(context)
       
        elif event.type == 'S':  # Confirm
            return {'FINISHED'}
       
        elif event.type == 'LEFTMOUSE':  # Confirm
            return {'FINISHED'}
        elif event.type in ('RIGHTMOUSE', 'ESC'):  # Cancel
            return {'CANCELLED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        self.value = event.mouse_x
        self.execute(context)

        print(context.window_manager.modal_handler_add(self))
        return {'RUNNING_MODAL'}


bpy.utils.register_class(ModalOperator)

# test call
bpy.ops.object.modal_operator('INVOKE_DEFAULT')


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest