Python Forum

Full Version: I can't run Scirpt Blender in background - Blender + Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.
I try create a external graphics user interface, which will do a visualization music (I use Blender as Graphics Engine).

I have problem, because i can’t run script python to blender in command line level (The blender is supposed to run in the background). I have error about bpy.context.area.type:

bpy.context.area.type = "GRAPH_EDITOR";
AttributeError: ‘NoneType’ object has no attribute ‘type’

Please, help me!

CODE Blender script:
import bpy
import sys



for i in range(0,7):
    print(sys.argv[i])
print(type(sys.argv[3])) 
File_save = sys.argv[5]
print(sys.argv[5])
bpy.context.scene.render.filepath = File_save
bpy.context.scene.render.image_settings.file_format = "PNG"                                     
bpy.context.area.type = "GRAPH_EDITOR";
bpy.context.area.type = "TEXT_EDITOR";                                                     

bpy.ops.render.render(animation=False, use_viewport=True)                                                              
bpy.ops.wm.console_toggle()   
CODE GUI:
import tkinter as tk
import os

def Run_Blender():
    FS = '-- D:\Python\TPNG'
    os.system('blender -b -P D:\\Praca_Inżynierska_test\\Blender_testy\\TestBlender.py ' + FS)

WINDOW_SIZE = "450x450"

root = tk.Tk()

root.geometry(WINDOW_SIZE)

myButton = tk.Button(root, text="Run Blender", command=Run_Blender, padx=50, pady=50, fg="blue", bg="yellow")

myButton.grid(row=1, column=0)


root.mainloop()