0

I'm trying to add a Pointer Property in my code that would be able to reference an Integer Property that exists on some data block of some object.

What is the proper way of doing it? I thought it should be as simple as the code below, but it doesn't work.

I do use PointerProperties a lot to reference specific object types etc., but I'm not sure how to point to a simple Int Property. How should I do it?

Thank you so much and I apologize if this is a trivial question.

enter image description here

import bpy

class Example_Class(bpy.types.PropertyGroup):

int_pointer: bpy.props.PointerProperty(
    type=bpy.types.IntProperty,
    name="Int Property Pointer",
    description = "This is the pointer to Int Property that exists somewhere else",
)    

def register(): bpy.utils.register_class(Example_Class)

def unregister(): bpy.utils.unregister_class(Example_Class)

if name == "main": register()

The error message is:

TypeError: PointerProperty(...) expected an RNA type derived from ID or ID Property Group
Error: Python: Traceback (most recent call last):
  File "\Text", line 20, in <module>
  File "\Text", line 12, in register
ValueError: bpy_struct "Example_Class" registration error: 'int_pointer' PointerProperty could not register (see previous error)
Blunder
  • 13,925
  • 4
  • 13
  • 36
  • The Blender 3.x documentation is confusing and very vage about this because it tells you nothing about the type. If you check the old 2.79 documentation or enter bpy.props.PointerProperty( in the Python console and hit the Tab key then you will see ":arg type: A subclass of :class:bpy.types.PropertyGroup or :class:bpy.types.ID." - Basically the same as what the error message tells you. – Blunder Dec 07 '22 at 01:24
  • IntProperty(Property) has the base classes "bpy_struct" and "Property". That's the reason why it does not work. So you probably need to encapsulate it in another PropertyGroup. -- Related question and an answer: https://blender.stackexchange.com/a/6977/107598 – Blunder Dec 07 '22 at 01:30
  • Ahh!!! Got it! Thank you so much!!! – Maciej Gliwa Dec 08 '22 at 20:18

0 Answers0