Call python and java function in Program Node and retrieve the values inside

Hi all,

I have a python program that uses XMLRPC and has a couple of functions which I want to call from a program node in the URCap I’m developing. The problem is I don’t know where to start with this implementation.

The program looks like the following:

Example:
When the program reaches line 2. I want it to trigger a java function or python function(preferably both) and pass the values WR:WRITE_EXAMPLE and 1 as parameters. The application uses the command name to retrieve associated values from the database. These values get passed into the function on the python XMLRPC server.

My question: How can I retrieve these values and run appropriate functions when the program reaches this point?

So a simple way you can do it is by appending a command to your generateScript function in the programNodeContribution that calls the function on the xmlrpc server.

For example:

public void generateScript(ScriptWriter writer) {
  writer.appendLine("xmlrpc_server.writeToCNC(" + getCommand() + "," + isSet() + ")");
}

This will add this line to the generated script at that point of the program.

Hope this helps.

First of all thank you for your input. This definitely clarifies some things.

So if I understand correctly when I implement something like the example you gave that script would run when it reached that point in the program where my node would be?

And also is there a way for me to easily access the command field from my screenshot? As far as I know this is only possible with a large work around.

No problem.

Essentially the generate script function will add that function the overall script that polyscope will run. You can view this by saving the program and opening the .script file as well. So if you had a program tree with some nodes in line 2-10 and then your urcap node line 11 it will simply add the script from the function to that point.

To access the command, you will have to interface with your view. For example when the command is selected you can save the selected command in the programNode’s data model (via the contributionProvider), then simply get the value from the data model and use it in your generateScript like the snippet I shared earlier. Also I have only worked with the Swing interface, so if you are using the HTML one, I’m not sure how that works.

Regards.

Thank you! I think I know how to continue now. I appreciate your help.

Kind regards.