0
$\begingroup$

For last night, I can't use bpy.ops.wm.open_mainfile(filepath="/media/backup/blender/file.blend") from python using this to run my python script

import bpy, os

def main(): 
    while True:
        exist = True
        try:
            srp = open("script.run", 'r')
        except FileNotFoundError:
            exist = False
            pass 
        if exist is True:
            for line in srp.readlines:
                text = bpy.data.texts.load(line)
                ctx = bpy.context.copy()
                ctx['edit_text'] = text
                bpy.ops.text.run_script(ctx)
                srp.close()
                os.remove("script.run")
main()

This command run in Text Editor, so I have no idea why this is happening.

$\endgroup$
  • $\begingroup$ You've got an endless loop in there which would freeze the UI indefinitely and it looks like the custom context that you're passing into bpy.ops.text.run_script is invalid because it doesn't set the correct area etc. which results in a crash $\endgroup$ – Robert Gützkow Dec 3 '19 at 15:46
  • 1
    $\begingroup$ This seems like an XY problem. Could you please describe what you're trying to do? I suspect the Python script execution that you're attempting to do could be simplified (e.g. by directly opening the script in the text editor or starting Blender from the command line with the -P flag). $\endgroup$ – Robert Gützkow Dec 3 '19 at 15:49
  • $\begingroup$ I'm trying to execute severals scripts in the same blender instance from a python script. $\endgroup$ – John Lihgt Dec 3 '19 at 15:58
  • $\begingroup$ You should try to import the scripts. Some adjustments to the sys.path may be necessary for the import to work, if you're not implementing an add-on that is installed into Blender. $\endgroup$ – Robert Gützkow Dec 3 '19 at 16:05
  • $\begingroup$ I've tried to run it from Blender TextEditor itself, but it crash too, so I'll do as you proposed. My only interrogation is why it's stopped to work : I've change nothing in the files, so if you have an idea, I'm listening. $\endgroup$ – John Lihgt Dec 3 '19 at 17:04

Your Answer

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

Browse other questions tagged or ask your own question.