Read exact object-location in FlexSim by code?

Read exact object-location in FlexSim by code?

robin_brunner
Not applicable
107 Views
9 Replies
Message 1 of 10

Read exact object-location in FlexSim by code?

robin_brunner
Not applicable

[ FlexSim 17.2.2 ]

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

0 Likes
Accepted solutions (1)
108 Views
9 Replies
Replies (9)
Message 2 of 10

joerg_vogel_HsH
Mentor
Mentor
Accepted solution
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.

Message 3 of 10

robin_brunner
Not applicable

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
Message 4 of 10

matt_long
Not applicable

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));
Message 5 of 10

robin_brunner
Not applicable

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

8908-norotating-noproblem.jpg

rotation - problem

8909-rotating-problem.jpg

0 Likes
Message 6 of 10

philboboADSK
Autodesk
Autodesk

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)


Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 7 of 10

robin_brunner
Not applicable

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

philboboADSK
Autodesk
Autodesk

Cast it to an Array and use [] syntax:

Array loc = current.getLocation(0,0,0);
return loc[1];

Or use the x, y, and z properties of the Vec3:

var loc = current.getLocation(0,0,0);
return loc.x;


Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 9 of 10

robin_brunner
Not applicable

Wonderful now everything works. Thank you so much for your instant help.

Here is the code snippet to print the correct coordinates into the output console:

Array loc = current.getLocation(0,0,0);
double x; 
double y;
double z;

x = loc[1];
y = loc[2];
z = loc[3];

pf(x);
pt("\n");
pf(y);
pt("\n");
pf(z);
pt("\n");
0 Likes
Message 10 of 10

Jacob_Gillespie
Autodesk
Autodesk

@Robin Brunner The print( ... ) command does work in FlexSim 2017 Update 2. Could you give an example where it doesn't work?

0 Likes