ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
||||
|
||||
Add Label
Hello
I am trying to create new nodes in the tree structure, and my code works well in creating the nodes, but i just dont know how to name those just created nodes. My code is as follows. nodeinsertafter(node("/SWITCH-3530>stored", model())); // I basically want a node after stored named "Availability Tables". I did try add label, nodeadddata, setlabelstr, but it doesnt work, as i cannot reach the newly created node. In the end what i am trying to do is make this generic, so that all the network nodes in my tree structure, do get this newly added node called availability tables. Please help... thanks |
#2
|
|||
|
|||
Probably the easiest way is to just use addlabel and pass in the object and label name, and if you want a type set - the value. Then reference the label node using label(<object>,<labelname>).
Generally if you add a node somewhere in the tree (using nodeinsertinto - sorry SH!) you can use last(<nodecontainer>) in order to rename it, as new nodes get added at the highest rank. In this case that would be the same as last(labels(<object>)) Last edited by Jason Lightfoot; 03-14-2011 at 09:29 AM. Reason: Clarified after Steven's feedback below |
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Nischith Kashyap (03-14-2011) |
#3
|
||||
|
||||
All that Jason said is true but in the case of using "nodeinsertafter" the "last" command is not going to work because you create an extra node after the node you specify and that may be any node in the tree. In that case you can use the "next" command to get to to the next node. So in your case that would be somethink like:
treenode MyNode = next( node( "/SWITCH-3530>stored", model() ) ); |
The Following 2 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Nischith Kashyap (03-14-2011) |
#4
|
||||
|
||||
Hello
I tried with the code below, and it still doesnt work, is there something wrong with my code, as i dont think the add label is reaching the node in the tree structure.... nodeinsertafter(node("/SWITCH-3530>stored", model())); treenode newlabel = addlabel(next(node("/SWITCH-3530>stored", model())),"Availability Tables"); Thanks... |
#5
|
|||
|
|||
You're trying to use addlabel in the wrong way. For your reference, the addlabel command creates a new node in the >labels part of the object's tree, and gives it the name and value you pass in. Also note in this case that the object needs to be a Flexsim object which means it has object data type and an attributes subtree containing the labels node. So if you really want a label just use addlabel command and then reference the node with label(<object>, <labelname>). If you want to add a node inside your "Availability Tables" label, then you can use nodeinsertinto(label(<object>,"Availability Tables")) and then find that new node using last(label(<object>,"Availability Tables"))
If you want a variable use nodeinsertinto(variables(<object>)) and then use last(variables(<object>)) to access the new node. For your reference, this creates a new node in the >variable part of the object's tree. Unlike the addlabel command it doesn't set the name of the node, the datatype or value, so you need to do that yourself. To add a node inside this variable you'd use nodeinsertinto(getvarnode(<object>,"Availability Tables")) and then reference the new node with last(getvarnode(<object>,"Availability Tables")) If the new node has to be after the 'stored' node (I can't think why you'd need this) then use nodeinsertafter(node(">stored",<object>)) and then refer to it by next(node(">stored",<object>)). So then a nested node inside that would be created with nodeinsertinto(next(node(">stored",<object>))). Again you need to set the node names yourself. If you want to create a node at the based attribute level (same level as variables,labels and stored) use nodeinsertafter(rankobj(<object>,contentobj(<objec t>))) and then reference that node with rankobj(<object>,contentobj(<object>)). Once again this method needs you to set the names. In all of the above examples you replace <object> with the pointer to your object which can be set up using treenode myobject=node("/SWITCH-3530",model()), but if you're doing all this when you create the objects you'll already have a pointer to the object via last(<objectcontainer>) where the objectcontainer is the model or a visual tool. |
The Following 3 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Phil BoBo (03-15-2011) |
Thread | Thread Starter | Forum | Replies | Last Post |
Record label | manuel fernandez | Q&A | 1 | 03-21-2010 12:29 PM |
Can not catch the number of label | Vic Li | Q&A | 2 | 11-10-2008 12:40 PM |
how to set preempt by label? | Vic Li | Q&A | 4 | 10-19-2008 01:51 AM |
String as label of a flowitem | Matthias Hofmann | Q&A | 2 | 09-18-2008 11:15 AM |
Checking to see if a label exists | Paul Dowling | Q&A | 3 | 04-28-2008 11:03 PM |