I am trying to code a simple Python script to add various effects in the compositor. I am wanting to add a custom node group that I have.
This is the script
import bpy
class CompEffects(bpy.types.Panel):
bl_label = "Comp Effects"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_label = "Comp Effects"
bl_context = "CompositorNodeTree"
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text="Camera Effects", icon='CAMERA_DATA')
row = layout.row()
bpy.ops.node.add_node(type="CompositorNodeGroup", use_transform=True, settings=[{"name":"node_tree", "value":"bpy.data.node_groups['Vignette']"}])
def register():
bpy.utils.register_class(CompEffects)
def unregister():
bpy.utils.unregister_class(CompEffects)
if __name__ == "__main__":
register()
and this is the error
Python: Traceback (most recent call last):
File "C:\Users\ethan\3D Objects\Blender\Addons\Scripts\Comp Effect_V1_1.blend\Comp Effects", line 18, in draw
File "C:\Program Files (x86)\Steam\steamapps\common\Blender\3.3\scripts\modules\bpy\ops.py", line 113, in __call__
ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Calling operator "bpy.ops.node.add_node" error, can't modify blend data in this state (drawing/rendering)
Do I need to make the node inside Python to add it?