Turn off Light Kit through python

I am adopting a script-only workflow to free myself of the burden to create and update those non-human-readable state files. In this context:

How can I modify (or simply disable) the Light Kit through python?
Is it possible? It does not appear in traces.

I wrote the following function as a workaround:

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)

I ran into this recently myself.
Try:

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.

hth

1 Like

Such a simple and obvious solution. Thank you!

https://gitlab.kitware.com/paraview/paraview/-/issues/20902#note_1144697