# How to programmatically add the vtkSeedWidget or vtkSphereWidget

**URL:** https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130
**Category:** vtk.js
**Tags:** vtkjs
**Created:** [November 8, 2025, 5:04pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130 "2025-11-08T17:04:16Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [November 8, 2025, 5:04pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/1 "2025-11-08T17:04:16Z")

</div>

How to programmatically add the vtkSeedWidget or vtkSphereWidget,then execute widgetManager.enablePicking(), and you can drag the widget with the mouse

Thanks.

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [November 8, 2025, 7:55pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/2 "2025-11-08T19:55:12Z")

</div>

Isn’t `placeWidget` working ?

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [November 8, 2025, 11:15pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/3 "2025-11-08T23:15:06Z")

</div>

My requirement is for the program to automatically generate the vtkSeedWidget upon loading, rather than requiring a mouse click to do so

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [November 9, 2025, 9:17pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/4 "2025-11-09T21:17:18Z")

</div>

I made a PR to demonstrate how to programmatically place a seed widget:

> <https://github.com/Kitware/vtk-js/pull/3354>
>
> \### Context
> VTK.js is lacking an example to programmatically place a widget.
> 
> …
> \### Results
> Improve the seed widget API and enhance its example. 
> 
> \### Changes
> \- \[x\] Documentation and TypeScript definitions were updated to match those changes
> 
> \### PR and Code Checklist
> \- \[x\] \[semantic-release\](https://github.com/semantic-release/semantic-release) commit messages
> \- \[x\] Run \`npm run reformat\` to have correctly formatted code
> 
> \### Testing
> \- \[\] This change adds or fixes unit tests 
> \- \[x\] Tested environment:
> - \*\*vtk.js\*\*: master
> - \*\*OS\*\*: Windows 11
> - \*\*Browser\*\*: Chrome

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [January 2, 2026, 4:33am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/5 "2026-01-02T04:33:24Z")

</div>

It seems that I still can’t programmatically place a widget.

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 4, 2026, 10:37pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/6 "2026-01-04T22:37:45Z")

</div>

Indeed the branch was not merged and got outdated. I just rebased it and merged. Can you try again ?

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [January 14, 2026, 2:28am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/7 "2026-01-14T02:28:59Z")

</div>

I’m just starting to learn about VTK.js. Could you provide me with a demo that loads 10 VTKSeedWidgets at once by clicking a button (instead of loading one at a time by clicking with the mouse)

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 14, 2026, 9:36am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/8 "2026-01-14T09:36:11Z")

</div>

In the example I shared, You need to call 10 times `AddWidget([x, y, z])` in a for loop.

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [January 15, 2026, 12:07am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/9 "2026-01-15T00:07:17Z")

</div>

for (let k = 0; k \< 5; k++) {

```auto
widget = vtkSeedWidget.newInstance();

widgetHandle = widgetManager.addWidget(widget);

widgetHandle.setCenter([Math.random(), Math.random(), Math.random()]);

```

}

renderWindow.render();

I successfully loaded 5 vtkSeedWidgets using the code above, but when I click on these vtkSeedWidgets with the mouse, an error occurs：”Uncaught TypeError: Cannot read properties of undefined (reading ‘handleEvent’)“

I can’t drag these vtkSeedWidget with mouse either

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 15, 2026, 10:07am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/10 "2026-01-15T10:07:15Z")

</div>

Can you share your code on codesandbox or something similar ?

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [January 19, 2026, 12:31am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/11 "2026-01-19T00:31:25Z")

</div>

const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({  
background: [0, 0, 0],  
});  
const renderer = fullScreenRenderer.getRenderer();  
const renderWindow = fullScreenRenderer.getRenderWindow();

const cone = vtkConeSource.newInstance();  
cone.setResolution(50);  
const mapper = vtkMapper.newInstance();  
const actor = vtkActor.newInstance();

// Create an instance of vtkPickerManipulator to constrain movement to a target actor  
const manipulator = vtkPickerManipulator.newInstance();  
// Set the target actor, which is representing a cone  
manipulator.getPicker().addPickList(actor);

actor.setMapper(mapper);  
mapper.setInputConnection(cone.getOutputPort());  
actor.getProperty().setOpacity(0.5);

renderer.addActor(actor);

// ----------------------------------------------------------------------------  
// Widget manager  
// ----------------------------------------------------------------------------

const widgetManager = vtkWidgetManager.newInstance();  
widgetManager.setRenderer(renderer);

let widget = null;  
let widgetHandle = null;

renderer.resetCamera();

////////////////////The code below is what I added//////////////  
///////////////////begin//////////////  
for (let k = 0; k \< 5; k++) {  
widget = vtkSeedWidget.newInstance();  
widget.setManipulator(manipulator);  
widgetHandle = widgetManager.addWidget(widget);  
widgetHandle.setCenter([Math.random(), Math.random(), Math.random()]);  
}  
renderWindow.render();  
//////////////////end//////////////////

// -----------------------------------------------------------  
// UI control handling  
// -----------------------------------------------------------

fullScreenRenderer.addController(controlPanel);

document.querySelector(‘#addWidget’).addEventListener(‘click’, () =\> {  
widgetManager.releaseFocus(widget);  
widget = vtkSeedWidget.newInstance();

// Important: set the manipulator of the widget to constrain movement to the actor  
widget.setManipulator(manipulator);  
// Set the color of the seed (random color)  
widget  
.getWidgetState()  
.getMoveHandle()  
.setColor3(  
Math.round(Math.random() \* 255),  
Math.round(Math.random() \* 255),  
Math.round(Math.random() \* 255)  
);

// Start placement interaction  
widget.placeWidget(cone.getOutputData().getBounds());  
widgetHandle = widgetManager.addWidget(widget);  
widgetManager.grabFocus(widget);  
});

I only added a few lines of code in the vtkSeedWidget example.

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 20, 2026, 9:50pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/12 "2026-01-20T21:50:51Z")

</div>

Did you try with the master of VTK.js ?

Because I realized that no new release of VTK.js were cut since I merged the PR I talked about above.

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [January 21, 2026, 6:22am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/13 "2026-01-21T06:22:01Z")

</div>

I’ve tried, but there are still some errors. You can try the code above. I can’t drag those five vtkSeedWidget

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 30, 2026, 3:47pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/14 "2026-01-30T15:47:09Z")

</div>

It’s because you need to import the “Glyph” profile:

```auto
import "@kitware/vtk.js/Rendering/Profiles/Glyph";

```

[https://codesandbox.io/p/sandbox/programmatic-seed-widgets-tmqyz5](https://codesandbox.io/p/sandbox/programmatic-seed-widgets-tmqyz5)

---

<div class="post-metadata">

### Author: ![fdlyj](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/a9adbd/32.png) [@fdlyj](https://discourse.vtk.org/u/fdlyj)
#### Post date: [February 24, 2026, 1:21am UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/15 "2026-02-24T01:21:07Z")

</div>

the latest version [SeedWidget | VTK.js](https://kitware.github.io/vtk-js/examples/SeedWidget.html) Adding a widget after deleting it will result in an error

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [February 25, 2026, 2:12pm UTC](https://discourse.vtk.org/t/how-to-programmatically-add-the-vtkseedwidget-or-vtkspherewidget/16130/16 "2026-02-25T14:12:43Z")

</div>

Should be fixed: [docs(seedwidget): fix SeedWidget example by finetjul · Pull Request #3424 · Kitware/vtk-js · GitHub](https://github.com/Kitware/vtk-js/pull/3424)
