How to set the value of a label based on the position of an object?

How to set the value of a label based on the position of an object?

filippo_c5
Not applicable
96 Views
7 Replies
Message 1 of 8

How to set the value of a label based on the position of an object?

filippo_c5
Not applicable

[ FlexSim 22.0.0 ]

Hello,

I am creating a model using GIS Navigation and I have a token (token.truck) that acquires a Truck type task executer. I want to assign a label to this token (token.truck.dest_tab_row) based on where the truck is.

I tried to write the code like this, but it doesn't work, can you tell me where am I wrong please?

Object locTO = Model.find("GISNavigator/BSS Torino");
Object locTruck = Model.find(token.truck);

if(locTruck.location == locTO.location)
{
token.truck.dest_tab_row = 1;    
}
else
{
token.truck.dest_tab_row = 3;
}
0 Likes
Accepted solutions (1)
97 Views
7 Replies
Replies (7)
Message 2 of 8

ryan_c10
Not applicable

Hi @Filippo C5,

It's hard to know how to help without looking at your model. To receive a more accurate solution, please post your model or a sample model that demonstrates your question.

Proprietary models can be posted as a private question visible only to FlexSim U.S. support staff. You can also contact your local FlexSim distributor for phone or email help.

0 Likes
Message 3 of 8

moehlmann_fe
Explorer
Explorer
Accepted solution

What your code is doing is comparing the 3d-coordinates of the GIS point with the coordinates of the task executer that's stationary somewhere in the model, not the minitiature version that gets drawn on the map.

What you want to do instead is check if the current location (object not coordinates) of the task executer stored in the navigator is equal to the point.

Since the feature is pretty new I don't know if there are any commands for this and I couldn't find any in a quick search of the manual, but the data can also be read directly from the tree.

getsdtvalue(TaskExecuter.find(">variables/navigator/1+"), "currentPoint");

This code follows the link node in the task executers tree that links it to the navigator and then reads the current location from the respective travelmember node in the navigator's tree.

Note1: "currentPoint" only returns a valid path if the task executer is currently at a GIS point. If it is traveling this will return a null/<no path> value. In that case you can use "destPoint" to get the point it is currently traveling to.

Note2: There is no guarantee for forward compatibility because the data format/location in the navigator's nodes might change in future versions.

In the attached model I use the above code in the "On Finish Task" trigger of the task executer to update a label on it that shows the last visited location when a travel task finished.

GetGISLocation.fsm

Message 4 of 8

filippo_c5
Not applicable

Hi, thank you very much for your reply! Unfortunately not knowing the function it is not clear to me how to apply it to my case. I posted the model to you. Truck example.fsm

I should model the operation of the dest_tab_row label in the first decide of the process flow. Can you give me a hand?

Thank you in advance

0 Likes
Message 5 of 8

filippo_c5
Not applicable

Hi, I have attached the model I am making. I should model the operation of the "dest_tab_row" label in the first assign label of the process flow as I explained in the question. In particular, if the truck is in the "BSS Torino" GIS point, the label must return 1, if it is in the "BSS Roma" GIS point, it must return 3 as a value.

Truck example.fsm

0 Likes
Message 6 of 8

jason_lightfootVL7B4
Autodesk
Autodesk

You should correct the label 'dest_tab_row' according to the following:

1644180502895.png

Message 7 of 8

moehlmann_fe
Explorer
Explorer

And since the code is written in an "Assign Labels" activity you have to return the wanted value. Otherwise a default value of 0 will be returned and overwrite the previous label value.

Object locTO = Model.find("GISNavigator/BSS Torino");
Object locTruck = token.truck;
Object truckPoint = getsdtvalue(locTruck.find(">variables/navigator/1+"), "currentPoint");

if(truckPoint == locTO)
{
return 1;
}

else
{
return 3;
}

Finally, the travel activity from the other process flow (the issue in your other question) has to be removed or the command will not work since the truck is already traveling when the "currentPoint" is evaluated.

truck-example_1.fsm

0 Likes
Message 8 of 8

filippo_c5
Not applicable

Thank you so much for your help, you have been very helpful! 🙂

0 Likes