def TurnOffLightKit():
""" Turns off the Light Kit by writing the state to file, modifying it and reloading it. """
from paraview.simple import SaveState, GetActiveViewOrCreate, LoadState
import tempfile
import re
renderView1 = GetActiveViewOrCreate('RenderView')
fp = tempfile.NamedTemporaryFile()
pathstatefile = fp.name
SaveState(pathstatefile)
with open(pathstatefile, 'r') as fin:
lines = fin.readlines()
for i,line in enumerate(lines):
result = re.match(r'^\s*<Property name="UseLight" id="\d+.UseLight" number_of_elements="1">\n*$', line )
if result is not None:
result = re.match(r'^(\s*<Element index="0" value=")(\d)("/>\n)$', lines[i+1])
lines[i+1] = f"{result.group(1)}0{result.group(3)}"
break
with open(pathstatefile, 'w') as fout:
fout.writelines(lines)
LoadState(pathstatefile)
renderView1.UseLight = 0
and = 1 to turn it back on.
From there you can light1.AddLight(view=renderView1) and light1.Position=…
if you want precise control over lights. Ie all the things you can get to via the Light Inspector panel.