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

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

kamil_ks
Not applicable
65 Views
7 Replies
Message 1 of 8

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

kamil_ks
Not applicable

[ FlexSim 19.0.2 ]

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:"

18598-curfr.png

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

Accepted solutions (1)
66 Views
7 Replies
Replies (7)
Message 2 of 8

sebastian_hemmannE3JAU
Collaborator
Collaborator

@Kamil KS,

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

Doesn´t this work?

Message 3 of 8

joerg_vogel_HsH
Mentor
Mentor

@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
Message 4 of 8

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

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.

0 Likes
Message 5 of 8

li_ze1
Not applicable

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
Message 6 of 8

jason_lightfootVL7B4
Autodesk
Autodesk

More comprehensively:

treenode obj=item;
while (objectexists(itemtype(obj)))
    obj=obj.up;
return obj; //container that is not an item
0 Likes
Message 7 of 8

jason_lightfootVL7B4
Autodesk
Autodesk
But you can iterate 'up' until you don't find an item - no need to parse strings.
0 Likes
Message 8 of 8

li_ze1
Not applicable

You are a genius!

微信截图-20221101114736.png

Fixed Resource objects don't have itemtype node.


0 Likes