1
$\begingroup$

I'm trying to create an add-on that executes a few steps before opening the save as menu. I am the point where I can execute the options and save the file, but I would like to open the save as menu, instead of directly saving over an already existing file.

import bpy

bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, 
properties=False)

bpy.ops.transform.rotate(value=1.5708, orient_axis='X', 
orient_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, 
use_proportional_edit=False, proportional_edit_falloff='SMOOTH', 
proportional_size=1, use_proportional_connected=False, 
use_proportional_projected=False)

bpy.ops.object.transform_apply(location=False, rotation=True, scale=False, 
properties=False)

bpy.ops.transform.rotate(value=-1.5708, orient_axis='X', 
orient_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, 
use_proportional_edit=False, proportional_edit_falloff='SMOOTH', 
proportional_size=1, use_proportional_connected=False, 
use_proportional_projected=False)

bpy.context.area.type = 'VIEW_3D'
bpy.ops.wm.save_as_mainfile()
bpy.context.area.type = 'TEXT_EDITOR'

This is what I currently have, is there any way to instead of saving directly to the save_as_mainfile() , open the save as menu?

$\endgroup$
3
  • $\begingroup$ Is there any particular reason why you've just unchecked the accepted answer? $\endgroup$
    – Robert Gützkow
    Jan 17, 2020 at 18:04
  • $\begingroup$ No, didn't realize I unchecked it TBH, my apologies $\endgroup$ Jan 20, 2020 at 14:03
  • $\begingroup$ No problem, I was just wondering. $\endgroup$
    – Robert Gützkow
    Jan 20, 2020 at 14:05

1 Answer 1

2
$\begingroup$

In order to open the file browser you need the operator's invoke() function to be called. This can be accomplish by setting the execution context. Pass the argument 'INVOKE_DEFAULT' into the function call and the file browser will open.

bpy.ops.wm.save_as_mainfile('INVOKE_DEFAULT')

The manual explains the execution context in the following way:

Execution Context

When calling an operator you may want to pass the execution context.

This determines the context that is given for the operator to run in, and whether invoke() is called or only execute().

‘EXEC_DEFAULT’ is used by default, running only the execute() method, but you may want the operator to take user interaction with ‘INVOKE_DEFAULT’ which will also call invoke() if existing.

[...]

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .