question

Raashid Mohammed avatar image
0 Likes"
Raashid Mohammed asked Matt Long commented

how to get part of label from another label

What is the code I have to write to pull only the object part of the label

For example I have label - item /object/Value

I want to get only object out of the label called item above

so other label should give me label - DockName - object

Please help see below token

FlexSim 16.1.0
labels
capture.jpg (78.7 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Matt Long commented

I'm a little confused by your question, but looking at the values in the table I can see that the item label has a reference to the OAK5-NIGHT object inside the Dock20 object.

To get the OAK5-NIGHT object you'd just use the getlabel command:

treenode obj = getlabel(token, "item");
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Raashid Mohammed avatar image Raashid Mohammed commented ·

So item = /Dock20/OAK5-NIGHT

I want DockName value to be just /Dock20

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Raashid Mohammed commented ·
//Get the referenced object
treenode obj = getlabel(token, "item");

//Get the object that contains the referenced object
treenode parent = up(obj);

//Set the DockName label to have a reference to the parent object
setlabel(token, "DockName", parent);

Or in a single line:

setlabel(token, "DockName", up(getlabel(token, "item")));
0 Likes 0 ·
Matt Long avatar image Matt Long Matthew Gillespie ♦♦ commented ·

Using an Assign Labels activity it would look like this:

1 Like 1 ·
upitem.png (7.7 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.