I would like to know how to execute code in a blend file / project using Python.
Asked
Active
Viewed 461 times
0
-
1Go to the Scripting workspace, there you can create a new text data-block, paste and run the code: (https://blender.stackexchange.com/a/194425/107598). If you want to use this code interactively in Blender's Python console have a look here: Easy way to run python script in blender python console? – Blunder Jun 19 '22 at 22:19
-
Hi. I've edited my script. It now fully runs a imported script in a new blend. – RPaladin Aug 01 '22 at 19:32
1 Answers
3
Edit
Script now automatically runs in new blend.
Recap summary of what this script does:
Creates new blend file.
Imports stated script.
Replaces default
3D Viewportwindow toText Editorwindow.Assigns imported script to active
Text Editorwindow.Automatically runs imported script once
Text Editorwindow is active.
import bpy
bpy.ops.wm.read_homefile(app_template="")
bpy.ops.text.open(filepath=str("D:\Blender\Scripts\external_script.py"))
for window in bpy.context.window_manager.windows:
for area in window.screen.areas:
if area.type == "VIEW_3D":
area.ui_type = "TEXT_EDITOR"
area.spaces[0].text = bpy.data.texts["external_script.py"]
with bpy.context.temp_override(window=window, area=area):
bpy.ops.text.run_script()
break
RPaladin
- 1,235
- 1
- 5
- 17