Hi all,
I was wondering what the best practice is for saving the user input of multiple program nodes. I am using Swing for this URCap.
The problem arises when I have more than one of the same node. Since the way I implemented this stores the information at the same address in the DataModel the last program node overwrites the data of all the previous ones and only that one gets processed. Instead of all of them back to back.
This is how the DataModel currently saves data:
model.set(CBOX_SELECTION_ID, CBOXselection);
model.set(RBUTTON_SELECTION_ID, rbutton_selection);
Here is an example of the program where the problem arises:
In the image above I have a node for a two write implementations. The first one sets the value to 1 and the second one sets it to 0. In this example. The program saves the input for the write on line 5, and then overwrites it with the input on line 6. Which causes it to only process the node on line 6.
What is the best way to process multiple of the same nodes? Do I save every single one seperately on the DataModel? Like this:
model.set(CBOX_SELECTION_ID1, CBOXselection);
model.set(CBOX_SELECTION_ID2, CBOXselection);
model.set(CBOX_SELECTION_ID3, CBOXselection);
model.set(CBOX_SELECTION_ID4, CBOXselection);
Or is there a better way?
The datamodel is instanced per node. No, you don’t need to do anything differently. What’s happening right now is that you are writing too quickly back to back, so it LOOKS like only line 6 is executing. Assuming that 1 and 0 is for opening the door on your CNC machine, you should program some sort of Wait statement for feedback from the CNC that the door is opened/closed. You could also just throw in a 10 second wait or whatever for testing purposes.
You can verify this for yourself by saving your program, then insert a Script node from the Advanced tab. Select “File” and open the program you just saved. You’ll be able to scroll through and see both URCap Nodes, one which is writing a 0 and the other which is writing a 1
The thing is I save the data at the same time of the input of the user. So the second node already overwrites the data while the user is putting in the inputs. So when it runs the datamodel only contains the data of the second node. So it is in fact only executing one and not both quickly back to back.
UR has taken steps to deliberately make it difficult to access the datamodel of sibling nodes. Without having implemented a custom API and without being a child of another URCap Program node, I really don’t think there’s any way you’re overwriting the datamodel of the other nodes. Unless you’ve somehow declared a static datamodel, or are writing to the installation’s model, all those program nodes will have their own datamodel.
This is how the DataModel currently saves data:
model.set(CBOX_SELECTION_ID, CBOXselection);
model.set(RBUTTON_SELECTION_ID, rbutton_selection);
This is totally fine. I have somewhere like 8 different nodes that all reference the same named key:
I can insert any number of these nodes, which all reference the same datamodel key. None of them overwrite each other, none of them are uniquely named. Your other post addresses the possibility of the UI simply reflecting the wrong information in the openView() method. I think there’s likely some miscommunication. For example, you’re saying it “overwrites” the other nodes. This could mean either the underlying datamodel is being overwritten, or that just the UI is being overwritten. Posting the code of your openView() method may clarify that.
Hi @eric.feldmann . It was indeed the UI that was being overwritten and not the datamodel. After fixing my OpenView method it works perfectly. Thank you for your time and input!