1

I have a problem with the mode after reopening a blender file (using Blender 2.74.2). When I run the following code:

import bpy

scn = bpy.context.scene
bpy.ops.mesh.primitive_plane_add(location=(0.0, 0.0, 10.0)) 
bpy.ops.transform.resize(value=(12.5, 12.5, 1.0))

# Delete the object
bpy.ops.object.delete()

# Close the scene and reopen it.
bpy.ops.wm.save_mainfile(filepath="/home/ma/Desktop/tempdelete.blend")
bpy.ops.wm.open_mainfile(filepath="/home/ma/Desktop/tempdelete.blend")

bpy.ops.mesh.primitive_plane_add(location=(0.0, 0.0, 0.0)) 
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.transform.resize(value=(12.5, 12.5, 1.0))  

the script gives an error message and the 3D view is in a strange kind of mode, it displays "object" mode but behaves like "edit" mode. (see picture)

enter image description here Can anyone help me to figure out what the problem is? I would like to work (with python) on the added plane.

corbofix
  • 89
  • 1
  • 5
  • When I run 'bpy.ops.object.mode_set(mode='EDIT') bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.transform.resize(value=(12.5, 12.5, 1.0))' directly in the Blender Python console, I don't get the same error. – corbofix May 13 '16 at 09:26
  • 1
    related http://blender.stackexchange.com/questions/51494/how-to-bring-the-context-back-after-running-read-homefile – Chebhou May 13 '16 at 11:16
  • What about replacing the save and open with one call to bpy.ops.wm.save_as_mainfile(filepath=filepath) – batFINGER May 17 '16 at 18:05

0 Answers0