1
$\begingroup$

In order to make my code a bit more organized, I decided to put all my properties in an external file. However, when I do so, I get the following error when attempting to attach my properties to Object or Collections:

TypeError: PointerProperty(...) expected an RNA type, failed with: RuntimeError: , missing bl_rna attribute from 'RNAMetaPropGroup' instance (may not be registered)
ValueError: bpy_struct "Object" registration error: 'rl_dataset_properties' PointerProperty could not register (see previous error)

I the following code, the class RL_ElementProperties (which is on the same file as the registering function) is registered correctly. The Dataset_Properties, which is in an external file, is not.

bl_info = {
    "name": "Object Adder",
    "author": "Sergio Bromberg",
    "version": (0,1),
    "blender": (2,80,0),
    "location": "View3d > Tool",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh"
    
}

# Blender imports
import bpy
from bpy.types import PropertyGroup
from bpy.props import  PointerProperty, EnumProperty

import panels, callbacks, ops, props # --> props.py holds my custom properties

class RLMenu(bpy.types.Menu):
    bl_label = "RLTools"
    bl_idname = "OBJECT_MT_rl_tools"

    def draw(self, context):
        layout = self.layout

        # Add operator for loading the dataset
        layout.operator(ops.OpenFilebrowser.bl_idname)
        # Add operator for refreshing everything
        # layout.operator("wm.open_mainfile")
        # layout.operator("wm.save_as_mainfile").copy = True

def draw_item(self, context):
    layout = self.layout
    layout.menu(RLMenu.bl_idname)

# ------------------------------------------------------------------------
#     Debug --> Class RL_Elements is registered correctly
# ------------------------------------------------------------------------

RL_elements = [
    ("IMAGE", "Image", "", 1),
    ("MODEL", "Model", "", 2),
    ("SPARSE", "Sparse", "", 3),
    ("NONE", "None", "", 4)
]


class RL_ElementProperties(PropertyGroup):
    element_type : EnumProperty(
        name = "RL_element type",
        description = "trin",
        items = RL_elements,
        default = "NONE"
    )

# ------------------------------------------------------------------------
#     Registration
# ------------------------------------------------------------------------

classes = (
    ops.OpenFilebrowser,
    panels.MetaRecon_PT_LoadDataPanel,
    
    # Props
    props.DatasetProperties, # ---> Cannot register
    props.ToolProperties,
    RL_ElementProperties #-- > Correctly registered
    # props.RL_ElementProperties
)

def register():
    print("Registering")
    bpy.utils.register_class(RLMenu)

    # -------------------
    #     Registration
    # -------------------
    for custom_class in classes:
        print("Registering " + str(custom_class))
        bpy.utils.register_class(custom_class)     

    # ------------------------
    #     Add props to objects
    # ------------------------
    # Object-level properties
    bpy.types.Object.rl_element_properties = bpy.props.PointerProperty(type=RL_ElementProperties)

    # Dataset-level properties -> ERROR HERE
    bpy.types.Collection.rl_dataset_properties =  bpy.props.PointerProperty(type=props.DatasetProperties)

    # Tool-level properties
    bpy.types.Scene.rl_globals = PointerProperty(type=props.ToolProperties) 

    # -------------------
    #     Menu
    # -------------------
    bpy.types.TOPBAR_MT_editor_menus.append(draw_item)

def unregister():
    bpy.types.TOPBAR_MT_editor_menus.remove(draw_item)
    # load_dataset.unregister()
    bpy.utils.unregister_class(RLMenu)
    
    del bpy.types.Scene.rl_globals
    del bpy.types.Collection.rl_dataset_properties
    del bpy.types.Object.rl_element_properties

    for custom_class in reversed(classes):
        bpy.utils.unregister_class(custom_class)

For reference, this is my props.py file, which is in the same folder as the main file above:


import bpy
from bpy_extras.io_utils import ImportHelper 
from bpy.types import Operator, OperatorFileListElement, PropertyGroup
from bpy.props import CollectionProperty, StringProperty, BoolProperty, FloatProperty, PointerProperty, EnumProperty
import gpu
from gpu_extras.batch import batch_for_shader
from mathutils import Matrix

# Custom imports
import sys
import os
import importlib
sys.path.append(os.getenv("RL_RUNPATH") + "/..")
# sys.path.append("/Users/sergiobromberg/Documents/RECON/Research/Blender/plicar-metarecon")

import RLResearch
importlib.reload(RLResearch)
import RLResearch.utils.pose_utils as pu
import RLResearch.utils.gen_utils as gu


import numpy as np
from pathlib import Path

import callbacks

# -----------------
#     PROPERTIES
# -----------------

RL_elements = [
    ("IMAGE", "Image", "", 1),
    ("MODEL", "Model", "", 2),
    ("SPARSE", "Sparse", "", 3),
    ("NONE", "None", "", 4)
]

class ToolProperties(PropertyGroup):

    image_size : FloatProperty(
        name="Enable or Disable",
        description="Size of images",
        default = 0.1,
        soft_min = 0,
        update = callbacks.update_image_size_callback
        )

class RL_ElementProperties(PropertyGroup):
    element_type : EnumProperty(
        name = "RL_element type",
        description = "trin",
        items = RL_elements,
        default = "NONE"
    )


class DatasetProperties(PropertyGroup):

    dataset_path: StringProperty(
        name = "Project Folder location",
        description = "Project Folder Location",
        default = ""
    )
    draw_poses : BoolProperty(
        name="Enable or Disable",
        description="Draw poses",
        default = True
        )
    
    draw_model : BoolProperty(
        name="Enable or Disable",
        description="Draw model",
        default = True
        )

    draw_sparse : BoolProperty(
        name="Enable or Disable",
        description="Draw sparse",
        default = True
        )
    
    draw_sampled : BoolProperty(
        name="Enable or Disable",
        description="Draw sampled",
        default = False,
        update = callbacks.load_float_sampled_points_callback
    )

    reorient : BoolProperty(
        name="Enable or Disable",
        description="Reorient dataset based on recentering matrix and rescale factor",
        default = False,
        update = callbacks.recenter_callback
    )
$\endgroup$
5
  • $\begingroup$ Hello ! Do your callbacks have the right signature ? load_float_sampled_points_callback and recenter_callback ? ie take self and context as argument and return None ? docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Commented Oct 17, 2022 at 8:59
  • $\begingroup$ They do. To me it would seem that the problem is elsewhere since RL_ElementProperties is registered correctly as long as I put it in the main file. If I move it to props.py, I get the error described above $\endgroup$
    – Sergio
    Commented Oct 17, 2022 at 10:34
  • $\begingroup$ Once I register the classes, is there another way to reference them apart from their original source location? I tried bpy.types but I couldn't find them there. $\endgroup$
    – Sergio
    Commented Oct 17, 2022 at 10:38
  • $\begingroup$ I wonder if the problem is not when I register the class, but when I reference it in bpy.types.Collection.rl_dataset_properties = bpy.props.PointerProperty(type=props.DatasetProperties) $\endgroup$
    – Sergio
    Commented Oct 17, 2022 at 10:45
  • $\begingroup$ Looking at the list of imports you may be trying to cram a bit too much inside your files. Does the error still apear when you remove the callbacks in the props definition ? $\endgroup$
    – Gorgious
    Commented Oct 17, 2022 at 14:43

0

You must log in to answer this question.

Browse other questions tagged .