0
$\begingroup$

I'm looking for the source code of the operator bpy.ops.wm.save_mainfile.

I searched on their github repo, but I couldn't find the class linked to this operator. As I want to rewrite this operator, I would like to see how it is implemented to adapt it.

$\endgroup$
6
  • 1
    $\begingroup$ the source code is written in C++, it's in /source/blender/windowmanager/intern/wm_files.cc but you can overwrite the Python operator or use an app handler as shown here: blender.stackexchange.com/q/164370/107598 $\endgroup$
    – Blunder
    Jan 21 at 22:27
  • $\begingroup$ @Blunder that appears to be a full correct answer. Please post it as such. $\endgroup$
    – TheLabCat
    Jan 22 at 1:12
  • $\begingroup$ @Blunder I followed every links starting from your link to the app handler. I tried what I found here: link, but it didn't work. However, the code identified that save_mainfile is a function in which I can get idname through python code. So, even if it calls a C++ function, it should be written somewhere in python code isn't it? $\endgroup$ Jan 22 at 19:37
  • $\begingroup$ I'm not a Python expert but yes, on the Python side, you have a wrapper operator and the operation itself is a C++ function (wm_files.cc:3538). If you enter type(bpy.ops.wm.save_mainfile) in the Python console it will tell you that it's a <class 'bpy.ops._BPyOpsSubModOp'>, a wrapper defined in blender/scripts/modules/bpy/ops.py:22. So, save_mainfile() is the constructor? and save_mainfile.id_name() is one of its methods that gives you the C++ id='WM_OT_save_mainfile'. There is also a py id='wm.save_mainfile'. $\endgroup$
    – Blunder
    Jan 23 at 20:52
  • $\begingroup$ in ops.py:107 you can see that the operator is called by its py id ret = _op_call(self.idname_py(), .... This _op_call seems to do the magic and calls the C++ code. It's imported from _bpy. I have no idea where this _bpy module comes from. But you can call the operator when you do a from _bpy import ops as ops_module and then ops_module.call('wm.save_mainfile', { 'filepath': 'c:/tmp/test.blend'}) for example. Related question: How to call original operator from operator's override? $\endgroup$
    – Blunder
    Jan 23 at 21:11

0

You must log in to answer this question.

Browse other questions tagged .