I have a very small script that's killing me. I can't see what I'm doing wrong. Can someone help spot the error. I feel like I'm registering everything correctly yet, I keep getting Attribute error.
import bpy
import random
class ShifterOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.shifter"
bl_label = "Shifter"
bl_options = {'REGISTER', 'UNDO'}
coll: bpy.props.PointerProperty(type=bpy.types.Object)
X: bpy.props.FloatProperty(name="X", description="Width", min=0.01, max=10, default=.1)
Y: bpy.props.FloatProperty(name="Y", description="Length", min=0.01, max=10, default=.1)
def execute(self, context):
for obj in list(bpy.data.collections[self.coll.name].objects):
obj.location.y += random.uniform(-self.Y, self.Y)
for obj in list(bpy.data.collections[self.coll.name].objects):
obj.location.x += random.uniform(-self.X, self.X)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop(self, 'coll')
col.prop(self, 'X')
col.prop(self, 'Y')
# Register and add to the "object" menu (required to also use F3 search "Simple Object Operator" for quick access).
def register():
bpy.utils.register_class(ShifterOperator)
def unregister():
bpy.utils.unregister_class(ShifterOperator)
if __name__ == "__main__":
register()
Error for trying to use 'self.coll'
AttributeError: 'ShifterOperator' object has no attribute 'coll'
I feel it's all related, things aren't getting registered?
layout.context_pointer_set
to pass IDs to operators. See blender.stackexchange.com/a/203443/86891 $\endgroup$