0
$\begingroup$

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?

$\endgroup$
1

1 Answer 1

0
$\begingroup$

I now know you can't add a bpy.props.PointerProperty inside an Operator class. That was my problem, once I removed it and made new adjustments it all worked correctly.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .