1
$\begingroup$

I'm working on a addon that makes use of custom node groups that has a Pointer property that holds a specific custom class type. like that:

class BM_ShaderNode_mask_texture(bpy.types.ShaderNodeCustomGroup):
    ... [some other code]
    mask_texture: bpy.props.PointerProperty(name="mask texture", type=MaskTexture, update=update_node_tree)
    ... [the rest of the code]

This is the class type it's refers to: class MaskTexture (bpy.types.PropertyGroup):

I want to set this Proeprty from somewhere else, which should be simple, apparently, but when I try to do it, I get the following error: AttributeError: bpy_struct: attribute "mask_texture" from "BM_ShaderNode_mask_texture" is read-only

It's weird, I haven't come across this anywhere else, I tried changing the Property type to Object, and it worked great, for some reason it only happens in this specific situation.

I would appreciate it if someone could help me.

$\endgroup$

1 Answer 1

0
$\begingroup$

This way is an example of how I do it, Valid for all shader nodes:

from bpy.props import PointerProperty, StringProperty, BoolProperty
from bpy.types import Node, PropertyGroup


class MyClass(PropertyGroup):

    prop_string: StringProperty()
    prop_bool: BoolProperty()
    # Etc...
    

bpy.types.Node.my_pointer_prop = PointerProperty(type=MyClass, options={'HIDDEN'},
                                           name="My Pointer")

Remember to register the class

Now you can test with:

mat = D.materials['My Mat']
node = mat.node_tree.nodes['Your Node']
node.my_pointer_prop.prop_string = "This is a string"
$\endgroup$

You must log in to answer this question.

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