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
)
load_float_sampled_points_callback
andrecenter_callback
? ie takeself
andcontext
as argument and returnNone
? docs.blender.org/api/current/… $\endgroup$RL_ElementProperties
is registered correctly as long as I put it in the main file. If I move it toprops.py
, I get the error described above $\endgroup$bpy.types
but I couldn't find them there. $\endgroup$bpy.types.Collection.rl_dataset_properties = bpy.props.PointerProperty(type=props.DatasetProperties)
$\endgroup$