ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 10-21-2015
Rahel Carolina
Guest
 
Posts: n/a
Downloads: 30
Uploads: 0
Default automatically get the location (x,y,z) of objects to the global table

Hi Forum,

Is there any way to automatically get the location of an object (xloc,yloc,zloc) and the rotation everytime we move the object with our mouse? And the data will be written in Global table.
I know how to create the Global Table but I just don't know how to always get the location data of an object everytime it moves.
Does anyone here know how to do it?

Thanks.
Rahel
  #2  
Old 10-21-2015
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

//PREWARNING//
Using your ondraw trigger to write logic is usually a bad thing:
1. It is not executed if you close your 3D views
2. It makes your model a lot slower because this piece of code is executed as often as the screen is refreshed.

But in this case a simple solution would be to use the ondraw trigger. Write the current locs in a label and when one of the positions are changed write them to a global table. Because you are actually using the user input to generate the data, both points are not a big issue. You could build in a global switch that, if it is off, the ondraw trigger only checks this switch and doesn't execute the code.
The Following 3 Users Say Thank You to Steven Hamoen For This Useful Post:
Sebastian Hemmann (10-21-2015)
  #3  
Old 10-22-2015
Rahel Carolina
Guest
 
Posts: n/a
Downloads: 30
Uploads: 0
Default

Quote:
Originally Posted by Steven Hamoen View Post
//PREWARNING//
Using your ondraw trigger to write logic is usually a bad thing:
1. It is not executed if you close your 3D views
2. It makes your model a lot slower because this piece of code is executed as often as the screen is refreshed.

But in this case a simple solution would be to use the ondraw trigger. Write the current locs in a label and when one of the positions are changed write them to a global table. Because you are actually using the user input to generate the data, both points are not a big issue. You could build in a global switch that, if it is off, the ondraw trigger only checks this switch and doesn't execute the code.
Hi Steven Hamoen,

Thanks for your reply. I already tried to put codes in OnDraw trigger of the object from the first time. But I didn't know what command I should use so the model know if the positions are changed. Can you tell me what kind of command I need?
I created the code below, please advise me.

treenode current = ownerobject(c);
treenode view = parnode(1);

// If this function returns a true, the default draw code of the object will not be executed.
treenode WS_Output = reftable("WS_Output");
string WS_name = getname(current);
double x_loc= xloc(current);
double y_loc= yloc(current);
double z_loc= zloc(current);
double rot_z= zrot(current);

query("SELECT x, y, z, Rotationz FROM $1 WHERE Station = $2", WS_Output, WS_name);
int total_rows = getquerymatchcount();
for (int indexRow=1; indexRow<total_rows; indexRow++){
settablenum("WS_Output",indexRow,2,x_loc);
settablenum("WS_Output",indexRow,3,y_loc);
settablenum("WS_Output",indexRow,4,z_loc);
settablenum("WS_Output",indexRow,5,rot_z);
}
  #4  
Old 10-22-2015
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Interesting to use the query. I personally would probably used something like the rank of the object. In that case not every row in the table is filled but you have a direct pointer to the correct row.

In case you want to continue with the query approach, you can use getquerymatchtablerow to get the row in the table. Then I would check if something has changed and then write the result to the table. Actually in this situation checking if it has changed takes more time then just overwrite the values. So your code could look somethink like this (I didn't test it!)
int indexRow= getquerymatchtablerow( 1, 1 );
settablenum( WS_Output, indexRow, 2, x_loc );
settablenum( WS_Output, indexRow, 3, y_loc );
settablenum( WS_Output, indexRow, 4, z_loc );
settablenum( WS_Output, indexRow, 5, rot_z );

You are already defined a treenode pointer to the table with WS_Output so use that pointer to access the table instead of the name string. In most cases strings are the slowest option to do something
The Following User Says Thank You to Steven Hamoen For This Useful Post:
Rahel Carolina (10-22-2015)
  #5  
Old 10-22-2015
Rahel Carolina
Guest
 
Posts: n/a
Downloads: 30
Uploads: 0
Default

Thank you so much Steven for the advice!
Now I know what to do.


Thread Thread Starter Forum Replies Last Post
Global Table as kanban card and automatically changed Rahel Carolina Flexsim Student Forum 4 06-17-2015 01:47 AM
Global table Rick Colemann Flexsim Student Forum 4 04-17-2014 01:51 AM
put objects in a group automatically by code wildcard Q&A 3 11-07-2012 05:02 AM
Can I make a column of a global table to type table? qin tian Q&A 0 10-01-2008 09:27 PM
Automatically generated global tables Sebastian Dransfeld Gripes and Goodies 1 09-01-2008 12:44 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.