2
$\begingroup$

So I am aware that you can create a custom property directly in Blender, and use it into an Attribute Node,

enter image description here

but in my case, I would like to try to use my pointerproperty as an Attribute, it is written in python and is of type Object. Here is how it is in Python:

from bpy.props import PointerProperty, FloatVectorProperty
from bpy.types import Object, PropertyGroup


class MyClass(PropertyGroup):

    my_vectors: FloatVectorProperty()
    

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

To access the property, with python you do this:

ob = C.object
ob.my_pointer_prop.my_vectors

Now I would like to set this property in the Attributes node, but I don't know if it is possible, and if so, how to write into it.

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

Yes, it's possible, use my_pointer_prop.my_vectors

if you change the values via scripting C.object.my_pointer_prop.my_vectors = (1, 0, 1), you need to update the object tag C.object.update_tag()

enter image description here

import bpy
from bpy.props import PointerProperty, FloatVectorProperty
from bpy.types import Object, PropertyGroup


class XX_PG_MyClass(PropertyGroup):

    my_vectors: FloatVectorProperty(default=(1, 0, 0))
    

class XX_PT_HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Test"

    def draw(self, context):
        layout = self.layout
        layout.use_property_decorate=False
        layout.use_property_split=True

        prop = context.object.my_pointer_prop
            
        col = layout.column()
        col.prop(prop, 'my_vectors')


def register():
    bpy.utils.register_class(XX_PG_MyClass)
    bpy.utils.register_class(XX_PT_HelloWorldPanel)
    bpy.types.Object.my_pointer_prop = PointerProperty(type=XX_PG_MyClass)


def unregister():
    del bpy.types.Object.my_pointer_prop
    bpy.utils.unregister_class(XX_PG_MyClass)
    bpy.utils.unregister_class(XX_PT_HelloWorldPanel)


if __name__ == "__main__":
    register()
$\endgroup$
1
  • 1
    $\begingroup$ Ok, perfect, I'm having a problem but I think I solved it. I was assigning values ​​to that property, but they are not updating, unless you do ob.update_tag() they will not change the values ​​in the node. I suggest you add this to the answer, as it will be useful for many. $\endgroup$
    – Noob Cat
    Commented 6 hours ago

You must log in to answer this question.

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