question

Robin Brunner avatar image
0 Likes"
Robin Brunner asked Jacob Gillespie commented

Read exact object-location in FlexSim by code?

Hello Community,

I'm working with a SQL Database which collects nearly all information from a FlexSim model. I want to write all spatial data from the treenode of an object to the database. The problem now is that the suggested command by the "sample-tool" in FlexSim just delivers an integer. So a x-location like 3.25 is saved as just 3. Is there any other method of reading the spatial data from FlexSim as maybe a float?

The command I used is:

pd(current.as(Object).location.x);

Regards Robin

FlexSim 17.2.2
codelocationspatial
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
3 Likes"
Joerg Vogel answered Robin Brunner edited
pf(current.as(Object).location.x);

pd( ) prints into the output only discrete values. That is obviously an integer value.

pf( ) prints floating values.

And if you use print( ), it is the actual command to print values of different types into the output.

· 1
5 |100000

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

Robin Brunner avatar image Robin Brunner commented ·

Oh sorry, you are right. pf(current.as(Object).location.x) prints out the exact location value. My fault.

Well then there is a problem with converting this number to a string.

EDIT: Okay, forgot to set the numtostring precision! Now everything works. Thanks

0 Likes 0 ·
Matt Long avatar image
1 Like"
Matt Long answered Jacob Gillespie commented

If you're print the locations of fixed resources, the print() command is sufficient:

print(current.location.x);

Or to get the center location of the object

print(current.getLocation(0.5, 0.5, 0));

If you're trying to print the locations of flowitems or task executers that are moving around in your model, you'll need to call updatelocations() first.

updatelocations(item);
print(item.location.x);
//or
print(item.getLocation(0.5, 0.5, 0));
· 6
5 |100000

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

Robin Brunner avatar image Robin Brunner commented ·

Okay I got a new problem now! The exact location of the spatial treenode can be read and written into a SQL database now. I figured out that the spatial treenode gives information about the measuring point coordinates in a lower corner of the bounding box. When there is no rotation added to the object, the measuring point coordinates and the ones of the spatial treenode match. But if I add some rotation to the object, the coordinates begin to differ. I added two screenshots, so you can see what I mean.

I need the corrected coordinates now (which are shown in the "Quick Properties" tab). When there is no way to get these coordinates read by code, then someone has a code snippet for a general rotation matrix to calculate the new coordinates?

no rotation - no problem

rotation - problem

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Robin Brunner commented ·

Matt answered this question above. Use the Object.getLocation() command to get a location relative to any point along the object instead of its direct spatial location.

For example,

current.getLocation(0.5, 0.5, 0)

gets the location of the bottom-center point on the object (50% along the x-axis, 50% along the y-axis, and 0% along the z-axis).

To get the bottom-corner position of the object, use:

current.getLocation(0, 0, 0)
0 Likes 0 ·
Robin Brunner avatar image Robin Brunner Phil BoBo ♦♦ commented ·

Sorry, didn't mentioned that with this command you can get those values. So SQL can't store Vector3 data. How can I convert the Vector3 to three floats?

By the way, print( ... ) doesn't work in FlexSim 2017 Update 2. "Command unknown". : /

0 Likes 0 ·
Show more comments