Reference to current open polyscope program

Is there any way to get a reference/id of the currently loaded polyscope program (urp)?

I want to use this ID to detect if the user creates a new program - if new program is created I want to reinitialize a counter (static field) to 0.

I have a counter that increments by one everytime a node is created.
I do this by having a static field in the ProgramNodeService class.
I increment the field by 1 if the creationContext is NEW.
I put it directly into the datamodel passed in the createNode function like this:

	@Override
public ProgramNodeContribution createNode(ProgramAPIProvider apiProvider, ProgramNodeView view,
		DataModel model, CreationContext context) {
	
	if (context.getNodeCreationType() == CreationContext.NodeCreationType.NEW) {
		model.set(NODE_ID, increaseNodeCount());
	}

	return new ProgramNodeContribution(apiProvider, view, model);
}

Hi Harald,

From the Dashboard server you can get the loaded program path with the command “get loaded program”. Bu for your case you will be expose for the case that the program is unnamed and a new unnamed program is created:
get loaded program
Loaded program: /home/ur/ursim/ursim-5.5.1.82186/programs/.urp
get loaded program
Loaded program: /home/ur/ursim/ursim-5.5.1.82186/programs/.urp

But your counter will not be capable of detecting deleted nodes as well. Can I ask what your over all target is by the this node counter/ID?

Hi Ebbe,

Thanks for the tip about the dashboard server. How can I access “get loaded program” from urcapapi?

Overall target is that the user should be able to separate the different nodes by an ID. Each node represents in this case a task.

So one possibility could be to detect if the program is unnamed I want to reset the ID. If the program has a name - dont reset it - never.

Deletion of nodes would be nice to detect to be able to decrease and keep a count of the nodes - but strictly not necessary. Most important is that IDs are distinct.

@OnRobot_ebbe: I accessed the DashBoardServer from my service class via a Socket. I can get the program name. However ---- it seems that the program i get is not the current one - it is always the previous program that was loaded.

Function to get loaded program is run from within the ProgramNodeService function createNode. (is there a better place to run it from?)

Example:
robot boots
user loads program 1.urp
currentProgramName (dashboard command: isProgramSaved) results in null
user loads program 2.urp
currentProgramName (dashboard command: isProgramSaved) results in 1.urp
user loads program 2.urp
currentProgramName (dashboard command: isProgramSaved) results in 2.urp
user loads program 1.urp
currentProgramName (dashboard command: isProgramSaved) results in 1.urp

Is this expected?

I would recommend you to take a look at the tutorial “working_with_variables.pdf” and then user those variables as your thread reference.

Regarding your Dashboard findings. You have asked with “IsProgramSaved” so I think it you change if you made a change in the program and saved it before asking.