AnswerHub Upload Issue
Our AnswerHub community currently has a bug that prevents you from attaching your model or other files to your questions. AnswerHub is aware of this issue and they are working on a fix. Until we receive their patch, you can upload your models and other files to FlexSim's file share site. Include the file name in your question so that we know which upload to reference.


Filippo C5 avatar image
Filippo C5 asked Filippo C5 commented

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


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;    
token.truck.dest_tab_row = 3;
FlexSim 22.0.0
locationpositiongisnavigationobject position
· 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.

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

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 0 ·
truck-example.fsm (1.2 MiB)

1 Answer

Felix Möhlmann avatar image
Felix Möhlmann answered Filippo C5 commented

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 (125.5 KiB)
· 4
5 |100000

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

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 0 ·
truck-example.fsm (1.2 MiB)

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


1 Like 1 ·
1644180502895.png (10.7 KiB)
Felix Möhlmann avatar image Felix Möhlmann Jason Lightfoot ♦ ·

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;

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.


0 Likes 0 ·
Show more comments

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.