3
$\begingroup$

My addon needs just one button currently and I'd like it to work as a start/stop button. But on every button press Blender creates a new instance of the corresponding bpy.types.Operator thus losing any connection to already created ones to stop them. What are the ways (if any) to circumvent this behaviour? How to make bpy.types.Panel button work with the same instance of operator?

The addon in question is accelblend, intended to receive accelerometer data and rotate view accordingly. The operator is modular and keeps running in the background just fine. Source: http://bazaar.launchpad.net/~xintx-ua/+junk/accelblend/view/head:/accelblend_receiver.py

$\endgroup$
4
  • $\begingroup$ Can you give a bit more context? Its hard to guess at a good answer in this case because Im not sure what you're doing. $\endgroup$
    – ideasman42
    Dec 25, 2013 at 10:55
  • $\begingroup$ Yes, I'll add the details from the comment I've just added to the question body $\endgroup$
    – int_ua
    Dec 25, 2013 at 10:59
  • $\begingroup$ I think in this case you're you really shouldn't be storing any state in the operator, If this operator has data which is spesific to the instance of Blender you have open, it makes sense to store the data globally in blender. (Probably within the python module). $\endgroup$
    – ideasman42
    Dec 25, 2013 at 22:03
  • $\begingroup$ ok, I'll try it the day after tomorrow, thanks a lot :) $\endgroup$
    – int_ua
    Dec 25, 2013 at 22:57

1 Answer 1

5
$\begingroup$

There are a few options open to you:

  • Yes you can keep the operator instance by keeping the operator running, in this case you would need to start a modal operator, then use some action to trigger it (think the knife tool - it stays running and but act's when the mouse is dragged).
    Note: This is the most direct answer to your question - however its only really useful in specific cases.

  • Store the settings externally.
    Typically when you store settings externally, the operators invoke function will read from these settings when initializing.

    • In a Python dictionary outside the operator instance (settings will be lost on restarting Blender unless you implement callbacks to write and restore them)
    • In custom properties (custom Scene properties is often used for this)
    • In the addons user preferences (not so good for per-blend-file data)
    • In a text data block (normally not optimal but including for completeness)
$\endgroup$
1

You must log in to answer this question.

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