0

I would like to know how to execute code in a blend file / project using Python.

RPaladin
  • 1,235
  • 1
  • 5
  • 17

1 Answers1

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 Viewport window to Text Editor window.

  • Assigns imported script to active Text Editor window.

  • Automatically runs imported script once Text Editor window 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