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 08-05-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default Image Swap Based on Position Logic

Hello,
I'm hoping someone might be able to help me with some logic statements. I'd like to do an image swap on one object based on the position of another object within the model I'm building.

I'd like to be able to manipulate the image attributes of at least one of the objects by using Global Variables created from the Tree Node Object List and then calling for an image swap when the second object is within the specified X,Y position parameters within the model.

Has anyone accomplished anything like this? Thank you in advance for any help you might be able to offer!

William.
  #2  
Old 08-05-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

William,

Since the image swap you are doing sounds like it will only effect the visualization of the model and not its behavior I recommend that you put the code for this on the OnDraw trigger of one of the objects. In the trigger you can get the x, y, and z locations of the two objects with the xloc, yloc, and zloc commands.

To make the shape change easier I would recommend using frames. The documentation combined with some prior posts on the forum should be more than enough to help you make a framed shape for your model. Frames are basically multiple 3D shapes that are all loaded under the same name (The operator works this way). This allows you to set the shape of an object to one shape and then change it later by calling setframe() on the object and setting the shape to another frame. To reference one object from the other I would recommend a global variable or a center point connection.

If you follow these steps it should make it possible for you to do this whole thing without having to get too complex.

Good Luck,
Brandon
__________________
thats not normal.
The Following User Says Thank You to Brandon Peterson For This Useful Post:
William Clausen (08-05-2008)
  #3  
Old 08-05-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default

Brandon,
Thank you! I’ll give that a try, from what you are describing it is actually easier to manipulate the image using the provided Flexsim controls. This should give me a good start. I’ll let you know how it works out!
Thank you again for your kind assistance!
Bill
  #4  
Old 08-06-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default


Brian,
I'm completely stumped! I don't get any errors when the code compliles. But I never do see a frame swap in the model. I've named them px5c.3ds for the base 0 image and then i've named the images px5cFRAME1.3ds etc for the other images, any thoughts? Thanks again for any help or advise you can offer here..
Bill,
/**Custom Code*/
treenodecurrent = ownerobject(c);
treenode view = parnode(1);

// If this function returns a true, the default draw code of the object will not be executed.
// If then with frameswap for animation.
// Variables are Op17 for the Operator17
// and Proc12 for the Processor12.
// As defined in the Global Variable options.
// by selecting Treenode/Operator17 etc.
// Logic to examine if Operator17 is at
// specified X loccation should trigger
// Frame swap on Processor12.
// Code placed in Operator17, Properties: Custom Draw Code.
// ex: if(getframe(current) == 3)) setframe(current, 5);

if (xloc(Op17)== 42.11 )
{
setframe (Proc12,1);
}

else if (xloc(Op17)== 19.39 )
{
setframe (Proc12,2);
}

else if (xloc(Op17)== 14.00 )
{
setframe (Proc12,3);
}

else if (xloc(Op17)== 9.26 )
{
setframe (Proc12,4);
}
else
{
setframe (Proc12,0);
}
  #5  
Old 08-06-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Bill,

My bet is that you are not seeing frame changes because you are using absolute comparisons and it is highly unlikely that a distance will be 9.26 and not 9.2600001. I would recommend using >= or <= in your comparisons. That should solve your problem.

Brandon
__________________
thats not normal.
The Following User Says Thank You to Brandon Peterson For This Useful Post:
William Clausen (08-06-2008)
  #6  
Old 08-06-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

xloc() returns a double with significantly high precision.

Doing a == operation on a double with high precision isn't the best idea.

try this:

int myxloc = xloc(current);// putting int instead of double rounds it down to the nearest integer
if(myxloc == 42)
{
setframe(Proc12,1);
}
else
{
setframe(Proc12,0);
}

...etc

You can also put print statements into your code to see what is firing using pt(), pd(), pf(), and pr(). They will display output to the Output Console (View > Output Console). This can be helpful for debugging.

Last edited by Alex Christensen; 08-06-2008 at 09:26 AM. Reason: adding comment to code
The Following User Says Thank You to Phil BoBo For This Useful Post:
William Clausen (08-06-2008)
  #7  
Old 08-06-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default

B,

You da man! I'll have to buy you some dark sunglasses!
  #8  
Old 08-06-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default

Phil,
I think you hit the nail on the proverbial head. Thank you!
  #9  
Old 08-06-2008
William Clausen's Avatar
William Clausen William Clausen is offline
W. Clausen
 
Join Date: Mar 2008
Posts: 12
Downloads: 1
Uploads: 0
Thanks: 9
Thanked 1 Time in 1 Post
Rep Power: 148
William Clausen is on a distinguished road
Default

Phil, Brandon...
Your suggestion worked flawlessly! Kudos...^5*2 :] Find code below..
/**Custom Code*/
treenodecurrent = ownerobject(c);
treenode view =
parnode(1);
// If this function returns a true, the default draw code of the object will not be executed.
// If then with frameswap for animation.
// Variables are Op17 for the Operator17
// and Proc12 for the Processor12.
// As defined in the Global Variable options.
// by selecting Treenode/Operator17 etc.
// Logic to examine if Operator17 is within
// specified X,Y loccation should trigger
// Frame swap on Processor12.
// Code placed in Operator17, Properties: Custom Draw Code.
// ex if(getframe(current) == 3)) setframe(current, 5);
if(xloc(Op17)>= 40.0)
{
setframe (Proc12,0);
}

else if (
xloc(Op17)>= 22.0 && zloc(Op17) >0)
{
setframe (Proc12,5);
}

else if (
xloc(Op17)>= 15.0 && zloc(Op17) >0 )
{
setframe (Proc12,4);
}

else if (
xloc(Op17)>= 9.0 && zloc(Op17) >0)
{
setframe (Proc12,3);
}

else if (
xloc(Op17)>= 5.00 && zloc(Op17) >0)
{
setframe (Proc12,2);
}
else
{
setframe (Proc12,0);
}


Thread Thread Starter Forum Replies Last Post
Working Logic of Dispatcher AlanZhang Q&A 6 02-09-2009 10:38 AM
Make sure you stop model with the stop button before collecting state based statistics Paul Dowling Tips and Tricks 2 06-10-2008 08:10 AM
Set reset position Martijn van Oostenbrugge Q&A 1 02-25-2008 11:48 AM
Pull Logic Dillema William Proctor Q&A 2 09-14-2007 12:46 PM
How to display 3D text/shapes in a static position regardless of the view angle. Regan Blackett Tips and Tricks 0 08-03-2007 10:51 AM


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.