Page MenuHome

Python API: created property is not recognized
Closed, ArchivedPublic

Description

System Information
Operating system: Linux-5.11.0-38-generic-x86_64-with-glibc2.33 64 Bits
Graphics card: NVIDIA GeForce RTX 2070 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 470.74

Blender Version
Broken: version: 3.0.0 Beta, branch: master, commit date: 2021-11-02 22:38, hash: rB11392829adfe
Worked: (newest version of Blender that worked as expected)

Short description of error
Blender can't find a property created by a script

Exact steps for others to reproduce the error
In the attached file, run the scriptbug file text
it shows this error:

AttributeError: 'Scene' object has no attribute 'current_iteration'

despite the property has been created by:

def register():

bpy.types.Scene.current_iteration = bpy.props.IntProperty(
    name= 'current_iteration',
    default = 1,
    update = set_max_iteration,
    )

Event Timeline

That's a bug in your code. A Python script is executed in order from top to bottom, and you are trying to access the property before you have created it.

def assignmaxvalues():
    x = scn.current_iteration  # property accessed here

# Scene.current_iteration does not exist yet
# so this will error.
assignmaxvalues()

def register():
    bpy.types.Scene.current_iteration = bpy.props.IntProperty(
        name= 'current_iteration',
        default = 1,
        update = set_max_iteration,
        )

if __name__ == "__main__":
    register()
    # Property now exists; you can access it starting from here.

That's a bug in your code (...)

I assume the report can be closed then.

For help using Blender, please try one of the community websites: https://www.blender.org/community/

If you think you found a bug, please submit a new report and carefully follow the instructions. Be sure to provide system information, Blender version, and a .blend file with exact steps to reproduce the problem.