Assign label to item

Assign label to item

AMITKUMAR
Not applicable
304 Views
6 Replies
Message 1 of 7

Assign label to item

AMITKUMAR
Not applicable

[ FlexSim 22.2.0 ]

Sample01.fsmI am creating a part from process flow and assigning a label.

I want to assign same label with same value to the created item how can I do that sample model is attached.

0 Likes
Accepted solutions (1)
305 Views
6 Replies
Replies (6)
Message 2 of 7

kavika_faleumu
Autodesk
Autodesk
Accepted solution

Hey @AMIT KUMAR, if you want to assign a label to an item that you create, you can click the green plus button under "Assign Labels to Created Objects" in the "Create Object" activity.

1694011926620.png

0 Likes
Message 3 of 7

Jeanette_Fullmer
Community Manager
Community Manager

Hi @AMIT KUMAR, was Kavika F's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes
Message 4 of 7

Felix_Hagemeister
Contributor
Contributor

I know that this is an old post but I have kinda a similar question: If I already set labels in the "Token Creation Event" (e.g. Schedule Source) can I also use the "Assign Labels to Created Objects" function? I would wanna have the exact same labels on the item as on the token that has created the item/object.

0 Likes
Message 5 of 7

SchreyerNicholasB
Contributor
Contributor

I am using FlexSim 24.0.2, but I am going to assume this has not changed over the past few versions. If the token which you are using to create the object has the label you want to copy and you know specifically what labels you want to copy then yes, you can. Let's say you have a label named "LabelToken" that you apply to the token through a schedule source. I have given this token label a value of 25. In your create object, you can simply put what you want the label on the object to be named in the "Name" textbox; this does not need to match the label name on the token to copy the values, so I used "LabelItem" as the label name. Then in the "Value" textbox of your create objects, you will want to specify which token label you want to assign to that label name. For this example, I want to assign the value of the token's "LabelToken" label to the "LabelItem" label on the item. Therefore, I will put "token.LabelToken" in the "Value" textbox. This can be repeated for the labels which you want to apply from the token to the item.

Create ObjectCreate ObjectSchedule SourceSchedule SourceLabel on ItemLabel on ItemLabel on TokenLabel on Token

Message 6 of 7

moehlmann_fe
Enthusiast
Enthusiast

If you want to copy over all labels from the token, you could also use the following code in a Custom Code activity to cut down on the work of assigning all labels individually.

Note that I use "<" in the condition of the for-loop. This is done with the assumption that "item" is the last label that was added to the token (in Create Objects activity). It wouldn't make much sense to assign a reference to itself to the item so I don't copy the last label.

Object item = token.item;
treenode tokenLabels = token.as(treenode).subnodes["labels"];
for(int i = 1; i < tokenLabels.subnodes.length; i++)
{
	item.labels.assert(tokenLabels.subnodes[i].name, tokenLabels.subnodes[i].value);
}

 

Message 7 of 7

Felix_Hagemeister
Contributor
Contributor

Perfect! Big thanks to both of u 🙂 I've implemented the solution of @SchreyerNicholasB and it works well