Universal Robots Forum

Program node exist check

Hi,

I’m trying to have my Cap installation node code generate only if the user has added a Cap program node to their program. Is there a simple way to check if a program node has been created in the installation node? I’m not having much luck combing through the API reference looking for it.

Thanks!

I don’t think if there are specific methods in the API for this, however I believe there is a way of doing it.
The constructor of a program node’s contribution is called when it is added to the program tree. As a result, we use it as the trigger for the creation of a program node.
In the constructor of your ProgramNodeContribution, add the line

YourInstallationNodeContribution installation = api.getInstallationNode(YourInstallationNodeContribution.class)

This will store the current instance of the installation node in a variable called installation.
Now in your installation file, define a boolean field at the top, something like

private boolean areThereChildren = false

and a public method:

public void setAreThereChildren(boolean b)
{
    areThereChildren = b;
}

Now back in the constructor of your contribution, call

installation.setAreThereChildren(true)

Finally, in the installation’s generateScript() method, simply add

if(areThereChildren)
{
    //generate your script
}
else
{
    //do something else? remove if nothing else needs to be done
}

Hope this helps.
Sam

This is a decent workaround.

But on purpose, we did not intend installation nodes to be aware if there are program nodes.
Basically, they should be “self contained”. I.e. the installation node could only define functions, which are then used by the program node, when required.

In the above workaround, this is not guaranteed that the program node is indeed present.
I.e. if the node is deleted or suppressed, the installation is not notified.

2 Likes