Message 1 of 19
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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").
Where should I put your textcode
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.
"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.
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.
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.
I saw the link you gave me but I can’t find where to start typing the code.
Which code do you mean?
You open the code window of any trigger/option with the little scroll/paper icon.
uhh can u give the sample!!! i want to see carefulness
so your textcode Which window was entered
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
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)
ok !!! thanks by the way cay u give the model by the color!! tks
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:
@霈倫,
Please see this attached image. You 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.
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.