2
$\begingroup$

So I want to make a modal operator that allows mouse input to set up another parameter in the bevel like the width. I read the wiki on modals however I don't think i understand it right. Now right now my script is one big 1263 line mess so I was thinking I needed to reference a modal operator externally. Any ideas?

$\endgroup$
2
  • $\begingroup$ Any registered operators can be called from another script. If it's an addon split into logical parts, and import / register in __init__.py. Look in the addons folder for multiple examples. $\endgroup$
    – batFINGER
    Oct 24, 2015 at 12:18
  • $\begingroup$ i should probably get to that for the next version. Ive been learning loads by just reading other peoples code. $\endgroup$ Oct 24, 2015 at 12:21

1 Answer 1

1
$\begingroup$

Using Update

For this example I've used the modal timer operator available in the templates > python menu of the text editor.

Around line 16 add this bit, I've used an operator named CSharpen (from a prev answer to test, change to suit the operator you want to "go modal" from.

    if event.type == 'TIMER':
        print("timer")
        op = context.active_operator
        if op is None:
            self.cancel(context)
            return {'CANCELLED'} 

        if op.name == 'CSharpen':
            op.angle += 0.001
            if not op.run_modal:
                #stop it
                self.cancel(context)
                return {'CANCELLED'} 

Leaving in the bg color change lets you know it's running, as well as the angle value of your operator changing. Change the events to suit your needs.

In your operator set up an update function

class sharpenOperator(bpy.types.Operator):
    '''ToolTip'''
    
    def go_modal(self, context):
        if self.run_modal:
            bpy.ops.wm.modal_timer_operator()

and a property to turn on the modal timer

run_modal = BoolProperty(update=go_modal)

and in the draw

    box.row().prop(self, "run_modal")
$\endgroup$
3
  • $\begingroup$ haha Csharpen. I was that same guy. haha. $\endgroup$ Oct 24, 2015 at 13:25
  • $\begingroup$ that answer totally lost me. I guess I dont understand modals.... at all haha. So within a class I would have operations and then a checkbox that would begin the modal operation? So would I need that to be a completely separate class? I guess it's getting confusing since it' $\endgroup$ Oct 24, 2015 at 13:48
  • $\begingroup$ sorry kept getting cut out "that answer totally lost me. I guess I dont understand modals.... at all haha. So within a class I would have operations and then a checkbox that would begin the modal operation? So would I need that to be a completely separate class? I guess it's getting confusing since it's all one big long script. So the run_modal is just a bool property. So the update=go_modal begins the operator of go_modal which then uses the above text to get the input value from the keystroke. Sorry I think my newb is showing now. " $\endgroup$ Oct 24, 2015 at 13:54

You must log in to answer this question.

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