0
$\begingroup$

I am trying a simple script to change a material attribute (Emission Level).

The command works in the python console but not as a script run from the text editor. No error messages.

Script below, delays put in for tracing purposes.

#set frame to 0
bpy.data.scenes["Scene"].frame_current = 0

#set segment g on
print("setting segment g on")

bpy.data.materials["segment g"].node_tree.nodes["Principled BSDF"].inputs[20].default_value = 10.0

print("wait 5")
time.sleep(5)

#set segment g off
print("setting segment g off")
bpy.data.materials["segment g"].node_tree.nodes["Principled BSDF"].inputs[20].default_value = 0.0

print("wait 5")
time.sleep(5)
print("finished")
$\endgroup$
1

2 Answers 2

1
$\begingroup$

There probably are error messages of some kind in the system console. Get to the system console by, on Linux, running blender from CLI, or on Windows, clicking Window -> Toggle System Console, and then look for errors there.

One thing I notice is that you never imported bpy, which happens automatically in the Blender Python console but not when running scripts. Try adding that.

$\endgroup$
1
  • $\begingroup$ Sincere apologies. The import commands are includes. Quite why I didn't copy and paste them is beyond me. I had a OS console open, the print statements work but not the emission changes, no errors. The emission changes work in python console as single lines. $\endgroup$ Commented Oct 26, 2022 at 13:43
1
$\begingroup$

insert

import bpy
import time

as your first 2 lines. Then it works. As TheLabCat already stated right, in the console some libraries are imported by default which doesn't happen if you run your script.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.