5
$\begingroup$

I had an animation export script that was working well in Blender 2.7, but I copied it over to my other computer that’s using Blender 2.9 and it’s not working anymore.

It seems that Blender cannot find the string corresponding to the desired path for the exported file. The script always breaks when I try to open the file path, saying: AttributeError: ‘EXPORT_OT_ss_animation has no attribute ‘filepath’.

I’ve looked through several tutorials, but they’re all using the same approach that I’m using (as well as appear to be written for past Blender versions), so I don’t know what’s going wrong. I did learn that I needed to switch to TOPBAR_MT_file_export from INFO_MT_file_export, but that didn’t fix this new problem.

Here’s the relevant code:

import bpy

class AnimationOperator(bpy.types.Operator):
    bl_idname = “export.ss_animation”
    bl_label = “Export SS Animation”

    filepath = bpy.props.StringProperty(subtype=“FILE_PATH”)

    def execute(self, context):
        exportAnimation(self, context)
        return {‘FINISHED’}

    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {‘RUNNING_MODAL’}

def exportAnimation(self, context):
    #I claim that what comes before attempting to open the file is irrelevant because none of it references self, but I’ll add it if users disagree with me.

    file = open(self.filepath, ‘w’) #Breaks here; states AttributeError: ‘EXPORT_OT_ss_animation has no attribute ‘filepath’
    
    #More code follows, but it’s irrelevant because it breaks before getting there

def menu_func(self, context):
    self.layout.operator_context = ‘INVOKE_DEFAULT’
    self.layout.operator(AnimationOperator.bl_idname, text=“Animation Exporter”

def register():
    bpy.utils.register_class(AnimationOperator)
    bpy.types.TOPBAR_MT_file_export.append(menu_func)

def unregister():
    bpy.utils.unregister_class(AnimationOperator)
    bpy.types.TOPBAR_MT_file_export.remove(menu_func)

if __name__ == ‘__main__’:
    register()
$\endgroup$
2
5
$\begingroup$

As of Blender 2.93 you have to use annotations. Support is dropped for 'non-annotation' properties.

From https://wiki.blender.org/wiki/Reference/Release_Notes/2.93/Python_API:

Remove support for non-annotation properties in classes as this was only enabled while porting scripts to 2.8x API (afa5da9ce0)

Means in practice, just replace the assignment operator = for your properties by a colon :

filepath = bpy.props.StringProperty() # OLD
filepath: bpy.props.StringProperty()  # NEW
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.