From f734f01c21210546a445b141db0c75edbc99bf19 Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Wed, 15 Sep 2021 09:53:02 +0200 Subject: [PATCH] Fix restoring area type --- io_export_psx_tmesh.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/io_export_psx_tmesh.py b/io_export_psx_tmesh.py index fb42d79..7b883af 100644 --- a/io_export_psx_tmesh.py +++ b/io_export_psx_tmesh.py @@ -587,10 +587,14 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper): TIMbpp = 4 TIMshift = 2 # Set context area to 3d view - previousAreaType = bpy.context.area.type - bpy.context.area.type="VIEW_3D" - # Leave edit mode to avoid errors - bpy.ops.object.mode_set(mode='OBJECT') + previousAreaType = 0 + if bpy.context.object.mode != 'OBJECT' : + previousAreaType = bpy.context.area.type + bpy.context.area.type="VIEW_3D" + # Leave edit mode to avoid errors + bpy.ops.object.mode_set(mode='OBJECT') + # restore previous area type + bpy.context.area.type = previousAreaType # If set, triangulate objects of type mesh if self.exp_Triangulate: for o in range(len(bpy.data.objects)): @@ -1939,8 +1943,6 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper): for symbol in level_symbols: h.write( "extern " + symbol + ";\n") h.close() - # Restore previous area type - bpy.context.area.type = previousAreaType return {'FINISHED'}; def menu_func(self, context): self.layout.operator(ExportMyFormat.bl_idname, text="PSX Format(.c)");