# Remove auto inserted waypoint not working

**URL:** <https://forum.universal-robots.com/t/remove-auto-inserted-waypoint-not-working/9389>\
**Category:** Java\
**Created:** [October 27, 2020, 7:33pm UTC](https://forum.universal-robots.com/t/remove-auto-inserted-waypoint-not-working/9389 "2020-10-27T19:33:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tulio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/tulio/32/1690_2.png) [@tulio](https://forum.universal-robots.com/u/tulio)\
**Post date:** [October 27, 2020, 7:33pm UTC](https://forum.universal-robots.com/t/remove-auto-inserted-waypoint-not-working/9389/1 "2020-10-27T19:33:31Z")

</div>

Hi, I’m trying to create a MoveNode, and I want to remove the auto inserted waypoint, but the remove opeartion always returns false. Here is the code:

> ```
> public void createTree()
> {
> ProgramModel model = programAPI.getProgramModel();
> ProgramNodeFactory nf = model.getProgramNodeFactory();
> TreeNode root = model.getRootTreeNode(this);
> try {
> TreeNode treeNode = root.addChild(nf.createMoveNode());
> treeNode.removeChild(treeNode.getChildren().get(0));	
> } catch (TreeStructureException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![tulio](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/tulio/32/1690_2.png) [@tulio](https://forum.universal-robots.com/u/tulio)\
**Post date:** [October 27, 2020, 10:47pm UTC](https://forum.universal-robots.com/t/remove-auto-inserted-waypoint-not-working/9389/2 "2020-10-27T22:47:46Z")

</div>

Funny fact…  
If I use the method above called createTree() in the constructor in the contribution class:

> public MyappProgramNodeContribution(MyAppProgramNodeView view, DataModel model, ProgramAPIProvider apiProvider, CreationContext context) {  
> this.view = view;  
> this.model = model;  
> this.programAPI = apiProvider.getProgramAPI();
> 
> ```
> if (context.getNodeCreationType() == CreationContext.NodeCreationType.NEW) {
> createTree();
> }
> 
> ```

It will not delete anything at all with removeChild…  
However if I place the code from createTree in the view, such as:

```
@Override
	public void openView() {
		ProgramModel model = programAPI.getProgramModel();
		TreeNode root = model.getRootTreeNode(this);
		if(root.getChildren().size() <=0)
			createTree();		
	}

```

It works like a charm!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/system/32/1_2.png) [@system](https://forum.universal-robots.com/u/system)\
**Post date:** [December 2, 2020, 3:19pm UTC](https://forum.universal-robots.com/t/remove-auto-inserted-waypoint-not-working/9389/3 "2020-12-02T15:19:11Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
