Display the name of the goods

a9080109
New Member New Member
2 Views
18 Replies
Message 1 of 19

Display the name of the goods

a9080109
New Member
New Member

[ FlexSim 20.0.10 ]

i want to show the name on the box how can i do

0826new_2 (1)_autosave.fsmexcel.xlsx

0 Likes
Accepted solutions (1)
3 Views
18 Replies
Replies (18)
Message 2 of 19

moehlmann_fe
New Member
New Member
Accepted solution

In the attached model I created a custom text object. When it is not inside any object it will display "No Container". When moved into an object it will instead display the name of that object and adjust its position and size to fit the object. (Not entirely, as the size difference between characters isn't taken into account)

Have a look at the custom code in the "Text Display" option to see how it works.

In an "On Creation" trigger of the source I create of copy of this object inside each newly created item.

If you run the model, you will see eight items with different names get created, with their names displayed by the copies of the text object inside the items.

1630568008584.png

Display_Item_Name_fm.fsm

0 Likes
Message 3 of 19

a9080109
New Member
New Member
so what can i add to my model??
0 Likes
Message 4 of 19

moehlmann_fe
New Member
New Member

You can copy the text object over into your model and add the code line you find in the trigger of my source to yours. Make sure the name you enter in the code is the same as the name of the text object. A copy of the text will then be added to your items, displaying their name (currently just "Box").

1630576792137.png

0826new-2-1_fm.fsm

0 Likes
Message 5 of 19

a9080109
New Member
New Member

Where should I put your textcode

0 Likes
Message 6 of 19

moehlmann_fe
New Member
New Member

The text object itself can be anywhere in the model. You can hide it under the model floor (z < 0) if you want.


Modify the "OnCreation" trigger of the source by adding the marked line in the screenshot.

1630582991147.png

"NameDisplay" has to be replaced by the name of the text object in your model.

You can also add this command to other triggers/custom code if you want to add a the name display to an item after creation.

Have a look at the model I attached in my last comment. I already integrated the code and text to "Source1" in your model.

0 Likes
Message 7 of 19

a9080109
New Member
New Member

I want to know more about how to do it like you. If it is convenient, I can email me and I want to give the boxes different colors according to different quantities. For example, two pieces are yellow and one piece is red.

excel.xlsx


0 Likes
Message 8 of 19

moehlmann_fe
New Member
New Member

The other code I wrote is in the "Text Display" field of the text object. If you do not yet have experience with coding in FlexSim I'd suggest you have a look at the appropriate sections of the FlexSim documentation.

https://docs.flexsim.com/en/20.0/Reference/CodingInFlexSim/WritingLogic/

I not quite sure I understand what you mean by "colors according to different quantities". Do you want to color the items depending on how many are created at a time (the quantity column in the arrival schedule)?

If so, you can duplicate the quantity column as a label column. Than use that label in a "Set Color by Case" option in the trigger.

1630584951555.png

1630585046536.png

0 Likes
Message 9 of 19

a9080109
New Member
New Member
omg thanks!!!!!!


0 Likes
Message 10 of 19

a9080109
New Member
New Member

I saw the link you gave me but I can’t find where to start typing the code.

0 Likes
Message 11 of 19

moehlmann_fe
New Member
New Member

Which code do you mean?

You open the code window of any trigger/option with the little scroll/paper icon.

1630588655154.png

0 Likes
Message 12 of 19

a9080109
New Member
New Member

uhh can u give the sample!!! i want to see carefulness

0 Likes
Message 13 of 19

a9080109
New Member
New Member

so your textcode Which window was entered

0 Likes
Message 14 of 19

moehlmann_fe
New Member
New Member

What I did to create the text object that gets added to the boxes:


- Drag a "text" into the model (Library on the left, in "Visual" tab)

- Select the text object by clicking on it (won't get highlighted like other objects because it doesn't really have a "volume")

- Click the highlighted button in my last post (scroll next to "Text Display" option

1630589267903.png

This window will open.

- Delete the last line (the return value of this code function)

- Add the following code

// Default text value
string text = "No Container";

// If inside something (that is node the model itself)...
if(current.up != model())
{
// And the current text value is not already set to the name
    if(textnode.value != current.up.name)
    {
        // Set the text-string to be equal to the item name
        Object item = current.up;
        text = current.up.name;

        // Adjust the text size depending on the name length
        double textsize = item.size.x/text.length*2;
        current.setVariable("textsize", textsize);

        // Change the size of the text object to that of the item
        current.size.x = item.size.x;
        current.size.y = item.size.y;

        // Adjust the position inside the item
        current.setLocation(item.size.x/2, -item.size.y/ 2, item.size.z, 0.5, 0.5, 0);

        // Apply the new text
        textnode.value = text;
    }
}

return 1;


Then modify the "OnCreation" trigger of the source with the marked line posted in the screenshot below. (Navigate to the trigger and click on the scroll icon to open the window)

1630589805910.png

0 Likes
Message 15 of 19

a9080109
New Member
New Member

ok !!! thanks by the way cay u give the model by the color!! tks

0 Likes
Message 16 of 19

a9080109
New Member
New Member
i cant find set an objet color .... where is it!!
0 Likes
Message 17 of 19

moehlmann_fe
New Member
New Member

I had made those screenshots in a different version. Had to re-create the changes in 20.0, which is why it took a while.

Here you go:

0826new-2-1-fm.fsm

1630591334380.png


0 Likes
Message 18 of 19

ryan_c10
Not applicable

@霈倫,

Please see this attached image. screenshot-2021-09-07-172056.pngYou can set the object color by double-clicking on the Source object to open its Properties window. Then, on the "Triggers" tab, you can add a trigger for some event and then choose "Set Object Color" under the Visual menu.

0 Likes
Message 19 of 19

jeanette_fullmer88DK3
Autodesk
Autodesk

Hi @霈倫 , was one of Felix Möhlmann's or 霈倫 's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. 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 unaccept and comment back to reopen your question.

0 Likes