How to find flow item from string?

How to find flow item from string?

shanice_c
Not applicable
131 Views
12 Replies
Message 1 of 13

How to find flow item from string?

shanice_c
Not applicable

[ FlexSim 22.0.0 ]

Hello, I have an external database, and I would change flow item also get some information from database. There problem in find flow item. I have printed out the "/Product1", next step is to assign token.producttake by using "model().find()".

1651571794659.png


1651571863054.png

0 Likes
Accepted solutions (1)
132 Views
12 Replies
Replies (12)
Message 2 of 13

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

You don’t need the slash. The product need a unique name to find it successfully.
Alternatively you can store an item by its number inside FlexSim.
Command is tonum( a thing). A thing can be a node. Later you can convert this number back to a node by command tonode( from thing number).

0 Likes
Message 3 of 13

jason_lightfootVL7B4
Autodesk
Autodesk

It's better to push items to a list and then pull from that list using a WHERE clause or by partition than using find each time. That way you get a direct pointer (or array of pointers) to the item(s).

Message 4 of 13

shanice_c
Not applicable

@Joerg Vogel Thank you for the response. I have tried not putting a slash, but still return no path. I found "?" could return the node reference. "token.producttake" could be assigned.

1651628665956.png

1651628643249.png

0 Likes
Message 5 of 13

joerg_vogel_HsH
Mentor
Mentor

@shanice.c , any search by method find will only work successfully, if you have a unique name for each item or object your are looking for! Typically products have equal names like “Product”. Such a Name won’t work, because it isn’t unique. I think you should go with Jason’s suggestion.

0 Likes
Message 6 of 13

joerg_vogel_HsH
Mentor
Mentor
Structal remark. A query result is always a table and not an array. This means you have to check a table cell by its row and column value. So far you check or assign values only by a column name for a row value.
0 Likes
Message 7 of 13

shanice_c
Not applicable

@Joerg Vogel Thank you for your reminds, I might encounter these problems soon.

I could understand 2 things you said. My organization is trying to control Flexsim object by only give agv information it needs(such as fromstation, tostation, whatproduct), and is not going to use process flow to handle any logic in flexsim.

We try to write our logic using external codes, and put information into database. Objects in flexsim are not doing any logic, only query a table recording tasks to check if any tasks to do. If no, just stay there.

0 Likes
Message 8 of 13

joerg_vogel_HsH
Mentor
Mentor

Then you have a unique key identifying each object in your data base. Now you need a reference to this object in FlexSim. Each Objects reference can be converted to an number by command tonum(thing). This is an absolute unique reference inside FlexSim.

A name can only be resolved to a reference, if each object has got an unique name in the scope of your model.

A relative path description by a string won't work in your case sufficiently, because you would have to be absolutely sure your object is still there when you evaluate the path again.

Because you control FlexSim externally, you have to store in your data base a key which stores the converted objects reference as a number. Or you will translate your own key from an external database inside FlexSim by a List. A List is not a Process Flow structure. It is a structure of the command environment of FlexSim.

0 Likes
Message 9 of 13

shanice_c
Not applicable

@Joerg Vogel May I ask how to use tonode()? I follow the example below to use tonum().
1651645955844.png

and the result on token are same, both "1558663349728"?

but when I look for "uniqueid" from tree, they are 94, 95.

1651646283358.png

1651646213328.png


0 Likes
Message 10 of 13

joerg_vogel_HsH
Mentor
Mentor

unique-item-id.jpg

unique_item_id.fsm

Item must be present in model. Item must be at different location.

Former versions of Flexsim have got an option to keep once created items in memory.

0 Likes
Message 11 of 13

shanice_c
Not applicable
@Joerg Vogel Sorry, I couldn't download attached model.
0 Likes
Message 12 of 13

joerg_vogel_HsH
Mentor
Mentor
@shanice.c, file updated!
0 Likes
Message 13 of 13

shanice_c
Not applicable

@Joerg Vogel Thanks for the provided method. Since we create Source data for simulation, our products have unique name. I've tried the tonum() to get unique id and used tonode() method to returned this double type data to pointer. I would try to use these methods in the future.

unique-item-id_s.fsm

0 Likes