Hi Guys sorry to bore you, but I have a problem I can’t register an attribute (into the scene fail, in an object works!)
this is my error and code: Traceback (most recent call last):
File “/run/media/rave/KINGSTON/Addon/zref.blend/zrefs.py”, line 56, in <module>
File “/run/media/rave/KINGSTON/Addon/zref.blend/zrefs.py”, line 45, in initzRef
AttributeError: ‘Scene’ object has no attribute ‘zrefs’
Error: Python script fail, look in the console for now…
CODE (smaller because ##### remarks removed):
import bpy
import mathutils
from bpy.props import *
from mathutils import Euler
from math import radians
class zRefSettings(bpy.types.PropertyGroup):
vista = bpy.props.StringProperty(name=“nombre de la vista”, default=“vista1”)
file = bpy.props.StringProperty()
ref_path = bpy.props.StringProperty()
loc = bpy.props.FloatVectorProperty(subtype=‘TRANSLATION’)
rot = bpy.props.FloatVectorProperty(subtype=‘EULER’)
scl = bpy.props.FloatVectorProperty(subtype=‘MATRIX’)
def initzRef():
global view3d
for area in bpy.context.screen.areas:
if area.type == ‘VIEW_3D’:
view3d = area.spaces.active
my_item = bpy.context.screen.scene.zrefs.add() <b><-------------------------- Error line 45</b>
print(len(my_item))
initzRef() <------------------------------ Error line 56
Any clue?, it works with an object but when I try to use Scene it doesn’t works, and I need to save these parameters into the scene not the object because it can be deleted.
I’d move this two lines from def register() bpy.utils.register_class(zRefSettings)
bpy.types.Scene.zrefs = bpy.props.CollectionProperty(type = zRefSettings)
after the class definition: class zRefSettings(bpy.types.PropertyGroup):
…
…
…
and before the function initzRef (def initzRef()….), and now it’s working, but this solution is correct, is it fine to register classes outside the register function?, only in the unregister function?, Why in an object works fine without move those 2 lines, and stop working in an scene object?, blender bug?, or am I coding badly?
I didn’t analyze well what was the script intention but… if you replace the erroneous line by this, would solve the problem?
Code:
my_item = bpy.context.scene.zrefs.add()