Universal Robots Forum

GenerateURscript at first program run once

Hi try to generate some initial code using generateScript, at first I added the code to my installation-node, but the code wasn’t generated if you didn’t click on the installation node.
The other idea was that I added a simple bool checking if the code has already been generated:
if(!initialized){
generateInitScript();
}
the only problem using this way, is that I need to know when the program has ended, so that i can set
initialized = false.
I want to know if there is a way of generating a certain script once, or do I need to use the dashboard server to look up the state?

I solved this quite simple, I created a static class with an id counter :stuck_out_tongue:
example below:

public class ProgramNodeCounter {
          public static ids = 0;
}    

public class FooProgramNodeContribution implements ProgramNodeContribution {
          private int currentId;
          public FooProgramNodeContribution(){
                ProgramNodeCounter.ids++;
                currentId = ProgramNodeCounter.ids;
          }
          @Override
          public void generateScript(ScriptWriter scriptWriter){
              if(currentId == 1){
                    generateInitScript(scriptWriter);
              }
          }
    }

Only problem is when you begin to delete the node.

1 Like