I am trying to store some values in an object property. But my code does not work.
Why does my code fail?
import bpy # Kind of out-of-place but required to be declared before used. def returnIfObject(passedName=""): try: result = bpy.data.objects[passedName] except: result = None return result myObject = returnIfObject("Cube") if myObject != None: try: myProperty = myObject["myProperty"] result = True except: result = False if result == True: print("Fetched: " + str(myProperty) + ".") else: # Assign a property, none exists. try: myObject.properties["myProperty"] = "myValue" result = True except: result = False if result == True: print("myPropery is assigned!") else: print ("Failed to store myValue in myProperty.") else: print ("Failed to fetch object [Cube].")
On the default scene, it prints “Failed to store myValue in myProperty”. Is my syntax wrong?