1
$\begingroup$

I want to create a very simple add-on that will automatically call some code (e.g. see example below) that will create a custom group node to be available in the compositor. What should the simple add-on look like? Apparently this code cannot be executed in the register() of the add-on due to the following error: AttributeError: '_RestrictData' object has no attribute “node_groups”. So where should such code be automatically be called within the add-on?

def createGroupNodes():
  # create a COMBINE XYZ group
  vector_group = bpy.data.node_groups.new('CombineXYZ', 'CompositorNodeTree')

  # create group INPUTS
  group_inputs = vector_group.nodes.new('NodeGroupInput')
  group_inputs.location = (-300,0)
  vector_group.inputs.new('NodeSocketFloat','X')
  vector_group.inputs.new('NodeSocketFloat','Y')
  vector_group.inputs.new('NodeSocketFloat','Z')

  # create group OUTPUTS
  group_outputs = vector_group.nodes.new('NodeGroupOutput')
  group_outputs.location = (300,0)
  vector_group.outputs.new('NodeSocketVector','Vector')

  # create three math nodes in a group
  node_combine = vector_group.nodes.new('CompositorNodeCombRGBA')
  node_combine.location = (000,0)

  # link inputs
  vector_group.links.new(group_inputs.outputs['X'], node_combine.inputs[0])
  vector_group.links.new(group_inputs.outputs['Y'], node_combine.inputs[1])
  vector_group.links.new(group_inputs.outputs['Z'], node_combine.inputs[2])

  #link output
  vector_group.links.new(node_combine.outputs[0], group_outputs.inputs['Vector'])
$\endgroup$
3

0

You must log in to answer this question.

Browse other questions tagged .