# Turn off Light Kit through python

**URL:** https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988
**Category:** ParaView Support
**Created:** [February 16, 2022, 4:25pm UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988 "2022-02-16T16:25:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [February 16, 2022, 4:25pm UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988/1 "2022-02-16T16:25:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [February 16, 2022, 5:26pm UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988/2 "2022-02-16T17:26:10Z")

</div>

I wrote the following function as a workaround:

```python
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)

```

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [February 16, 2022, 8:01pm UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988/3 "2022-02-16T20:01:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [February 17, 2022, 10:07am UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988/4 "2022-02-17T10:07:28Z")

</div>

Such a simple and obvious solution. Thank you!

---

<div class="post-metadata">

### Author: ![bastian](https://discourse.paraview.org/user_avatar/discourse.paraview.org/bastian/32/7513_2.png) [@bastian](https://discourse.paraview.org/u/bastian)
#### Post date: [February 17, 2022, 10:14am UTC](https://discourse.paraview.org/t/turn-off-light-kit-through-python/8988/5 "2022-02-17T10:14:25Z")

</div>

[https://gitlab.kitware.com/paraview/paraview/-/issues/20902#note\_1144697](https://gitlab.kitware.com/paraview/paraview/-/issues/20902#note_1144697)
