0
$\begingroup$

I'd like to add a curve mapping in my operator's undo panel, along with its properties.

As far as I know, is not possible and is pretty hacky; we have to basically add a Curve node in shader tree, and then get it from here.

I found this great answer that explains how to add a curve in a panel.

But after adapting the code to make it work in my operator...:

def myNodeTree():
    if 'TestCurveData' not in bpy.data.node_groups:
        ng = bpy.data.node_groups.new('TestCurveData', 'ShaderNodeTree')
        # ng.fake_user = True
        ng.use_fake_user = True
    return bpy.data.node_groups['TestCurveData'].nodes

curve_node_mapping = {}
def myCurveData(curve_name):
    global curve_node_mapping
    if curve_name not in curve_node_mapping:
        cn = myNodeTree().new('ShaderNodeRGBCurve')
        curve_node_mapping[curve_name] = cn.name
    return myNodeTree()[curve_node_mapping[curve_name]]

class OT_with_curve(bpy.types.Operator):
    bl_idname = "test.curve_property"
    bl_label = "test"
    bl_options = {'REGISTER','UNDO'}


    def draw(self, context):
        self.layout.template_curve_mapping(myCurveData('TestOne'), "mapping")

def register():
    bpy.utils.register_class(OT_with_curve)

... I can't get it to work.

The main problem seems that I can't set use_fake_user in that context.

So I guess that, when I edit the curve, it calls undo on the operator, and the curve goes back to its default state:

enter image description here

(After editing it, the changes are gone).

I tried calling myNodeTree in a handler when the file loads (bpy.app.handlers.load_post.append(myNodeTree).

But when I do that, bpy.data.node_groups is empty, I can't understand why. I tried also to inite the node tree with a timer.

Also tried __init__() function in my operator, but again, Im having problems with the context.

So... is it possible to achieve what I want to do? If so, any idea how?

Thank you so much for the help, much appreciated!

$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .