question

Kamil KS avatar image
1 Like"
Kamil KS asked Li ze edited

How to get a string name of the object where the item is stored ?

Hello,

I want to check what is the object's name where token.FlowItem is stored using code.

I have found something like this in the tree but I don't know how to refer to ,,curFR:"

There were a similiar topic Topic but I couldn't find an answear to this specific variable there.

FlexSim 19.0.2
tree
curfr.png (9.6 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.

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Li ze edited

I don’t have a direct approach to get the data of a current fixed resource of an item.

You can try to find the fixed resource in the treenode path of the item. I would split the path string into an array, combine the array again by the method join to test every level of the path to be an object of the fixed resources class.

Array pathStr = item.getpath(0,1).split(“/“);

Delete last element of the array

Array newStr = pathStr.pop();

Build new path string

string newPath = newStr.join(“/“);

Build tree node reference

treenode testedNode = model().find(newPath);// maybe start node is main()

Test if the classobject(testedNode) belongs to the subnodes of the fixedresources directory in the library.

· 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.

Li ze avatar image Li ze commented ·

It's a brilliant idea!


Array pathStr = item.getpath(0,1).split(“/“);

should be:

Array pathStr = item.getPath(0,1).split("/");




string newPath = newStr.join(“/“);

should be:

string newPath = pathStr.join("/");

cause pop method returns the last element of the array.


20221031225001.png

get a string name of the object where the item is stored_Flexsim2022.1.fsm

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Li ze commented ·

More comprehensively:

treenode obj=item;
while (objectexists(itemtype(obj)))
    obj=obj.up;
return obj; //container that is not an item
0 Likes 0 ·
Li ze avatar image Li ze Jason Lightfoot ♦ commented ·

You are a genius!

微信截图-20221101114736.png

Fixed Resource objects don't have itemtype node.


0 Likes 0 ·
Sebastian Hemmann avatar image
3 Likes"
Sebastian Hemmann answered Jason Lightfoot commented

@Kamil KS,

What about "token.Flowitem.up.name"?

Doesn´t this work?

· 2
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·

@sebastian.hemmann, this works if the item is stored directly at the object. But if the tested item belongs to a structure of combined containers, you need to know how the structure is organized to get to the level of the fixed resource.

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Joerg Vogel commented ·
But you can iterate 'up' until you don't find an item - no need to parse strings.
0 Likes 0 ·

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.