1
$\begingroup$

I'm working on development of the appleseed plugin and I'm trying to wrap my head around using the new ability of the Pointer Property to be used with the custom properties we add with that exporter.

Specifically we use the node system with our materials. Right now a material references it's node tree via a bpy.props.StringProperty. While this works it has serious shortcomings for linking and appending. From what I understand we should now be able to have a pointer property in that node tree reference that connects the actual node_group datablock to that property. I'm still a bit green on Blender's Python API so I'm not sure how to set that up.

$\endgroup$
2
  • $\begingroup$ Could you add a piece of code explaining what you tend to do, and elaborate what is not working in the code? This will make the question clearer and we can give better answers. $\endgroup$
    – J. Bakker
    Feb 7, 2018 at 17:16
  • $\begingroup$ Related? You can't do this tho, bpy.types.Material.somenode = bpy.props.PointerProperty(type=bpy.types.Node) since Node is not derived from an ID. See this q ... but you can bpy.types.Material.somenodetree = bpy.props.PointerProperty(type=bpy.types.NodeTree) $\endgroup$
    – batFINGER
    Feb 7, 2018 at 17:51

1 Answer 1

2
$\begingroup$

This is how I do it in the Blender addon for LuxCore:

import bpy
from bpy.props import PointerProperty

def init():
    bpy.types.Material.luxcore = PointerProperty(type=LuxCoreMaterialProps)

class LuxCoreMaterialProps(bpy.types.PropertyGroup):
    node_tree = PointerProperty(name="Node Tree", type=bpy.types.NodeTree)

(The init() function is called in the top-level register() function)
You can then access the node tree like this (example from the Python console):

>>> material = bpy.data.materials['Material']
>>> material.luxcore.node_tree
bpy.data.node_groups['Material']

I think it's a good idea to add all properties specific to an external renderer to a PropertyGroup like "luxcore" or "appleseed" to prevent any conflicts. Cycles does the same thing.

Important

Note that PointerProperties attached to the material are not properly loaded in versions prior to 2.79a RC1: https://developer.blender.org/T53509

See also my notes on PointerProperties in the blenderseed bug tracker for issues with backwards/forwards compatibility: https://github.com/appleseedhq/blenderseed/issues/31

$\endgroup$
2
  • $\begingroup$ I think there are some pointer properties in there already for the material props, much like what you have (for all I know the original blenderseed borrowed that technique from Luxrender's old exporter). I'll see if I can work your example in. $\endgroup$
    – user52073
    Feb 28, 2018 at 18:35
  • $\begingroup$ So BYOB' method works fine. Only downside is that all the texture paths break since relative path mapping doesn't translate for some reason. $\endgroup$
    – user52075
    Mar 1, 2018 at 14:23

You must log in to answer this question.