# vtkColorMaps getPresetByName with vtk.js as external script

**URL:** https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183
**Category:** Support
**Created:** [June 20, 2019, 11:24am UTC](https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183 "2019-06-20T11:24:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![PBrockmann](https://discourse.vtk.org/user_avatar/discourse.vtk.org/pbrockmann/32/524_2.png) [@PBrockmann](https://discourse.vtk.org/u/PBrockmann)
#### Post date: [June 20, 2019, 11:24am UTC](https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183/1 "2019-06-20T11:24:13Z")

</div>

From [https://kitware.github.io/vtk-js/examples/ScalarToRGBA.html](https://kitware.github.io/vtk-js/examples/ScalarToRGBA.html)  
there are those lines to preset a lookup table:

```auto
import vtkColorMaps from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps';
import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';

const lookupTable = vtkColorTransferFunction.newInstance();
const preset = vtkColorMaps.getPresetByName('erdc_rainbow_bright');
lookupTable.applyColorMap(preset);
lookupTable.setMappingRange(...dataRange);
lookupTable.updateRange();

```

But how to do the same when you use vtk.js as an external script ?  
I cannot find how to instantiate vtkColorMaps.

```auto
const lookup = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
const preset = vtk.Rendering.Core.???????
preset.getPresetByName('erdc_rainbow_bright');
lookup.applyColorMap(preset);
lookup.build();

```

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [June 25, 2019, 2:51am UTC](https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183/2 "2019-06-25T02:51:27Z")

</div>

Hi Patrick,

This is a missing export. I will add the export in and you should be able to use it shortly like so:

```auto
const vtkColorMaps = vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps;
const preset = vtkColorMaps.getPresetByName('erdc_rainbow_light');

```

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [June 25, 2019, 3:23am UTC](https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183/3 "2019-06-25T03:23:30Z")

</div>

Update: the latest vtk.js version now supports the above export. Let me know if it doesn’t work for you for some reason.

---

<div class="post-metadata">

### Author: ![PBrockmann](https://discourse.vtk.org/user_avatar/discourse.vtk.org/pbrockmann/32/524_2.png) [@PBrockmann](https://discourse.vtk.org/u/PBrockmann)
#### Post date: [June 25, 2019, 10:58am UTC](https://discourse.vtk.org/t/vtkcolormaps-getpresetbyname-with-vtk-js-as-external-script/1183/4 "2019-06-25T10:58:35Z")

</div>

Thank you for the support and action !  
It works now.  
Also note that ‘erdc\_rainbow\_light’ is now named ‘erdc\_rainbow\_bright’

```auto
var lookup = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
var preset = vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps.getPresetByName('erdc_rainbow_bright');
lookup.applyColorMap(preset);
lookup.setNanColor(1.0, 1.0, 1.0, 1.0); // should be after applyColorMap
lookup.build();

```

To get all preset color maps:

```auto
console.log(vtk.Rendering.Core.vtkColorTransferFunction.vtkColorMaps.rgbPresetNames);

```

![image](https://discourse.vtk.org/uploads/default/original/1X/c5d9a117152736dcc5788a529e514edbd79e42a2.png)
