# How to delete a specific urcap node

**URL:** <https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133>\
**Category:** Java\
**Created:** [December 12, 2021, 7:44pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133 "2021-12-12T19:44:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon2293033](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@anon2293033](https://forum.universal-robots.com/u/anon2293033)\
**Post date:** [December 12, 2021, 7:44pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/1 "2021-12-12T19:44:55Z")

</div>

**Hello! I can’t figure out how to delete a specific urcap node using the button on this node**

I’m trying to make an analog of a button from a standard waypoint tab

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/9/9f6bf446be4a9ae11a9ae63e659e9059119006fc.png)

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [December 13, 2021, 6:57pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/2 "2021-12-13T18:57:53Z")

</div>

Take a peek at the TreeNode data type. Each node can be accessed as a TreeNode, which has a removeChild() method. I can’t say I’ve seen that button you’re referring to. I have only worked with the e-series, so maybe that’s a CB? I’m not sure what it’s functionality is. If you can delete the node from itself, you will likely have to do a fair bit of additional work, as you will need to create a custom interface so you can access different contributions from within others in order to call something like “parent.removeChild(activeTreeNode).”

Essentially you call a function from a different contribution (in this case it would be the Move node) and pass it a TreeNode from the active contribution (the waypoint node) in order to delete itself. It is, unfortunately, not as trivial as you would think.

---

<div class="post-metadata">

**Author:** ![anon2293033](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@anon2293033](https://forum.universal-robots.com/u/anon2293033)\
**Post date:** [December 15, 2021, 9:12pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/3 "2021-12-15T21:12:49Z")

</div>

Hi! Thanks for the answer! In the course of work, I came across the fact that the getChildren() function gives a different result every time it is called) Perhaps you know why this can happen?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [December 15, 2021, 9:45pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/4 "2021-12-15T21:45:53Z")

</div>

Yeah, dealing with the TreeNode structure is pretty strange. Lets pretend the node you’re calling getChildren() on is called “root.” Basically, any time you’re dealing with root, put this line first:

root = programModel.getRootTreeNode(exampleContribution.this);

Then do something like root.getChildren(). For some reason the exact reference changes, but calling this every time before using it seemed to fix it for me. It’s a solution I’d found posted somewhere else here on the forum as well.

Likewise, the exact ID of the children might change too, if I remember correctly. For this you might have to get creative about how you identify each child. You could use their indexed position of the array returned from getChildren(), or add a custom type of something like NodeType and check for this if you’re populating the tree with custom UR Cap nodes. Not knowing your exact use case, I can’t get much more specific than that.

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 25, 2022, 1:50pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/5 "2022-02-25T13:50:08Z")

</div>

Hi!

I am currently working on this and i face faced a little issue: i have a main custom node and as a child i want to insert a customNode1. I have successufully added this customNode1 as a consequence of enable of a checkbox. Now my goal is to remove this customNode1 as i disable the checkbox.

I have created my customNode1 as ProgramNode since i need to insert it inside a .insertChildAfter() which only supports promanNodes and not casting. Unfortunately the removeNode() works only with TreeNodes and not with ProgramNodes.

Unfortunately i could not find a solution to my issue

has someone faced this issue?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 25, 2022, 2:30pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/6 "2022-02-25T14:30:47Z")

</div>

Can you post a screenshot of your Polyscope so I can see the tree structure you have going on? Yes there’s a way to do what you’re asking, I just want to make sure I understand what you want first.

I’m also assuming the checkbox you’re using is on the parent node?

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 25, 2022, 2:50pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/7 "2022-02-25T14:50:56Z")

</div>

![Senza nome](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/3/3f8bea8ce983fd266d1cf7778bef660a705ce0f3.png)

Hi!

As you can see, on the right i have a checkbox: by pressing the checkbox i am able to insert the green Instructions

Here i have two problems:

- As you can see, once i have pressed this checkbox, the program adds twice my instruction and this behavior goes on increasingly as i add other custom main program.

- As I press a second time on y checkbox, i want to be able to remove the green instruction. here i have uploaded a snippet of my code that does not work (i have seen that this instruction works only if i give him as input a treeNode. In this case i am using a programNode since the .insertChildAfter used to set the green instruction works only with a programNode as second argument. I have tried to use a cast in order to cast a ProgramNode to a TreeNode but this does not work

```auto
	
	public void removeNodes() {
		ProgramModel programModel = apiProvider.getProgramAPI().getProgramModel();
		final TreeNode rootTreeNode = programModel.getRootTreeNode(this);
		undoRedoManager.recordChanges(new UndoableChanges(){
			@Override
		
		public void executeChanges() {
			try {
				rootTreeNode.removeChild((TreeNode) Node);
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			}
		});
	}

```

Do you have any ideas about this behavior?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 25, 2022, 5:24pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/8 "2022-02-25T17:24:43Z")

</div>

If you are wanting what I think you want, can you use the “locateDescendantTreeNode()” method on your parent node? It takes a programNode as a parameter and returns it as a TreeNode.

So basically, replace (TreeNode) Node in your code above with

```auto
rootTreeNode.removeChild(rootTreeNode.locateDescendantTreeNode(Node))

```

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 28, 2022, 8:21am UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/9 "2022-02-28T08:21:30Z")

</div>

Good morning.

Thank you for your help!  
in my set-up i have declared at the beginning of my contribution the following:

```auto
private ProgramNode StitchNode;

```

I have tried doing the proposed substitution and reading some api but i keep getting the following error on the locateDescendantTreeNode method:

```auto
The method locateDescendantTreeNode(ProgramNode) is undefined for the type TreeNode

```

i can’t figure this out since the stitchNode is a programNode and it is the only parameter that i pass to this function.

In addition to this, as you can see, the rootTreeNode is declared as TreeNode and the locateDescendantTreeNode is a property of treeNodes.

has this happend to you too?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 28, 2022, 1:30pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/10 "2022-02-28T13:30:59Z")

</div>

I’m just kinda looking through some of my code, and it looks like the type I’m using is actually “URCapProgramNode” instead of just ProgramNode. Maybe try that?

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 28, 2022, 1:50pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/11 "2022-02-28T13:50:05Z")

</div>

I have just tired your suggestion!

Unfortunately it did not work. I assume that the displayed errore refers to the “treeNode” being “rootTreeNode” since now my error has become

```auto
The method locateDescendantTreeNode(URCapProgramNode) is undefined for the type TreeNode

```

due to the fact that i have changed the type of my custom node from ProgramNode to URCapProgramNode.

the quick-fix suggest to add a cast to rootTreeNode but this does not make sense in my mind since the locateDescendand works with treeNodes and rootTreeNode is a treeNode.

i have tried various casting types but this does not work

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 28, 2022, 2:15pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/12 "2022-02-28T14:15:24Z")

</div>

OK I agree with your assessment. Last thing I can think of then is that there are technically 2 TreeNode data types.

```auto
import javax.swing.tree.TreeNode;

```

and

```auto
import com.ur.urcap.api.domain.program.structure.TreeNode;

```

Can you verify you have imported the 2nd option here, the one that includes urcap.api?

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 28, 2022, 2:25pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/13 "2022-02-28T14:25:06Z")

</div>

> [@eric.feldmann](#):
>
> `import javax.swing.tree.TreeNode;`

Hi!

I have just checked and the library that i have installed is

```auto
import com.ur.urcap.api.domain.program.structure.TreeNode;

```

so it looks like it is the correct one. Could this be a problem of the compiler? i am using Eclipse

```auto
Version: 2020-03 (4.15.0)
Build id: 20200313-1211

```

with

```auto
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

```

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 28, 2022, 2:41pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/14 "2022-02-28T14:41:50Z")

</div>

Weeeeeellllll Now I’m stumped. Maybe it’s something to do with the compiler? I’m using Eclipse as well, same version as you…

Same JDK version too I think, 1.8. What version of the URCap API are you using? I’m using 1.10 for reference.

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 28, 2022, 4:06pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/15 "2022-02-28T16:06:21Z")

</div>

i am using sdk-1.13.0 and i am woking with the following simulato`

```auto
ursim-5.11.0.108249

```

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [February 28, 2022, 4:11pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/16 "2022-02-28T16:11:56Z")

</div>

EDIT: just opened the pom.xml file and found this

```auto
com.ur.urcap.api*;version="[1.7.0,2.0.0)", * 

```

could this be the problem in your mind? how can i perform an update of the api without causing troubles?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [February 28, 2022, 4:43pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/17 "2022-02-28T16:43:19Z")

</div>

OK so I went to the API manual here: [https://plus.universal-robots.com/urcap-basics/api-reference-docs/?v=1.7.0](https://plus.universal-robots.com/urcap-basics/api-reference-docs/?v=1.7.0)  
and checked version 1.7, since that’s what you found you’re running. There is no locateDescendant method under TreeNode.

If you switch it to the 1.10 version of the API, it shows this method exists. Not exactly sure which version this got added in, but it sounds like this is the answer as to why you’re getting this error.

I’m a little out of my element when it comes to Maven and the pom file. I’ve mostly managed by just poking around at it until it works, but here’s what I have to use API ver 1.10, placed into the dependecies section:

```auto
<dependency>
  <groupId>com.ur.urcap</groupId>
  <artifactId>api</artifactId>
  <version>1.10.0</version>
  <scope>provided</scope>
</dependency>

```

I guess my advice would be to (of course) backup your code to git or wherever you’re storing it, then try changing the API version. The “without causing troubles” part is where I can’t really help much haha. I cause plenty of troubles for myself all the time.

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [March 1, 2022, 10:38am UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/18 "2022-03-01T10:38:25Z")

</div>

Since i am not familiar with Maven, the only approach i had in my mind was to brutforce-fully change the pom file from 1.7.0 to 1.10.0 😂

I am very good in creating troubles in a almost-working code myself too haha

Now i will try and let you know if something happens

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [March 1, 2022, 1:44pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/19 "2022-03-01T13:44:28Z")

</div>

UPDATE: i have updated the api by just changing the name in the dependency section.  
Unfortunately, in addition to this, i had to implement some workaround due to the following facts:

- from api 1.7.0 to 1.13.0, you should add the compatibility flags that were not required or needed in api 1.7.0

```auto
	<dependency>
			<groupId>com.ur.urcap</groupId>
			<artifactId>api</artifactId>
			<version>1.13.0</version>
			<scope>provided</scope>
		</dependency>

```

- i have changed the configuration section in the pom file as it follows

```auto
<configuration>
					<instructions>
						<!-- **********DO NOT MODIFY THE ENTRIES OF THIS SECTION********** -->
						<Bundle-Category>URCap</Bundle-Category>
						<Bundle-Activator>com.StudioRatio.WeldURCap.impl.Activator</Bundle-Activator>
						<Bundle-Vendor>${urcap.vendor}</Bundle-Vendor>
						<Bundle-ContactAddress>${urcap.contactAddress}</Bundle-ContactAddress>
						<Bundle-Copyright>${urcap.copyright}</Bundle-Copyright>
						<Bundle-LicenseType>${urcap.licenseType}</Bundle-LicenseType>
						<Bundle-Description>${urcap.description}</Bundle-Description>
						<URCapCompatibility-CB3>${urcap.compatibility.CB3}</URCapCompatibility-CB3>
						<URCapCompatibility-eSeries>${urcap.compatibility.eSeries}</URCapCompatibility-eSeries>
						<!-- *************************************************************** -->
						<Import-Package>
							com.ur.urcap.api*;
							*
						</Import-Package>
					</instructions>
				</configuration>

```

This worked for me for the API update. Regarding the removeNode, i still have some problems: the api recognises the locate structure but it still does not remove the custom child.

it says that the program is unable to retrieve the TreeNode

```auto
com.ur.urcap.api.domain.program.structure.ProgramNodeNotInSubTreeException: TreeNode not found. Program node not in the tree.

```

Did you implement an interface to the child node in order to achieve this goal?

EDIT: with some workaround, it finally worked.

thank you for your help

---

<div class="post-metadata">

**Author:** ![anon84921795](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon84921795](https://forum.universal-robots.com/u/anon84921795)\
**Post date:** [March 1, 2022, 3:43pm UTC](https://forum.universal-robots.com/t/how-to-delete-a-specific-urcap-node/18133/20 "2022-03-01T15:43:58Z")

</div>

Here i have added a new post about the issue that i have with the checkbox inside another checkbox

> [@Checkbox inside checkbox](https://forum.universal-robots.com/t/checkbox-inside-checkbox/19577):
>
> Hi! i am developing a custom URCap having the following structure for the first case: Inside the installation tab i have two independent checkboxed making visible two checkboxes in the program page that we will call checkboxA and checkboxB checknoxA is a checkbox independent from B checkboxB is a checkbox independent from A By pressing on checkbox A, a custom Node is added to the program Node, By pressing on checkbox B , a second custom node is nested correcly inside the custom programNode…
