Click on a prop in 3D and have it trigger something.

Click on a prop in 3D and have it trigger something.

mike_mayer
Advocate Advocate
460 Views
2 Replies
Message 1 of 3

Click on a prop in 3D and have it trigger something.

mike_mayer
Advocate
Advocate

This is more of an event handler question. 

 

I'm looking for a way to simply click on a 3D prop (like a cube or a sphere or plane or cylinder) in a 3D view, and have it fire a trigger that will run a chunk of FlexScript.   

 

I'm not referring to the GUI tools already available in FlexSim.  Just simply clicking on a FlexSim 3D object.   It would be as if there were an object trigger called OnClickMouse or something like it, which would fire the FlexScript like any other simulation event-driven trigger.  Except that the mouse click of course, would be considered an external event to the running of the simulation engine, injected into the running Event List at the moment the mouse is clicked. 

 

Almost like the OnDraw trigger, but it would be proactive, not reactive.

 

ProcessFlow almost has something like it, but not quite.  There is essentially a "listener" Event Triggered Source that causes a token to be released when something (like On[something]) happens to a 3D object.  However, that "something" doesn't include a mouse button click.  

 

I do have FlexScript that when run, will toggle the visibility of conveyor legs.  Currently I can easily turn conveyor legs on and off with a simple binary 1 or 0 (or check/un-check) via the standard Parameters table (or a Parameters Dashboard).  That works well, but to toggle back and forth you have to go to the Parameters dashboard, then back to the 3D view.

 

It would be clever if there was a way to simply click on an object in 3D, essentially using it as a GUI trigger, to run my same "conveyor legs on/off" FlexScript.  The benefit being that you remain in the 3D view.  

 

This could also lead to a future suggestion for FlexSim to create a simple set of 3D GUI objects that simply fire a FlexScript trigger to do something when clicked on.

 

By the way, removing all conveyor legs simply makes it a lot easier to see the routing of conveyors when building them, as well as demonstrating them to people.  Sometimes there's so many multiple-level conveyors in our models going every which way, that the 3D view becomes a thick forest of vertical gray Unistrut legs.  Removing the legs (setting all their lengths to 0 in a group loop) works really well, and also seems to improve animation - things seem to move more smoothly when the graphics subsystem does not have to render all those legs every frame.

 

Thank you for any hints.

0 Likes
Accepted solutions (1)
461 Views
2 Replies
Replies (2)
Message 2 of 3

FelixMoehlmann
Collaborator
Collaborator

You can do this by adding a node called "OnClick" to the eventfunctions node in an object's tree. If any of the parent nodes does not exist for that object create them as well. Add text data to the OnClick node and toggle it as FlexScript (rightclick menu). The code you write in the node will get executed when you click on the object. With the "clickcode()" function you can distinguish between different click types (Left/Right Mouse Button Down/Up and Double Click). Another potentially useful command is "iskeydown()" that let's you check if some keyboard button is pressed. For example to only execute certain code when you click on the object and a specific key is held down at the same time. Attached is an example model with a queue that changes color randomly when double-clicked.

0 Likes
Message 3 of 3

mike_mayer
Advocate
Advocate
Accepted solution

Hello,

 

Hey that is really cool - and surprisingly simple - and very useful.

 

I will use that for my conveyor leg on/off visibility code (see below).  

 

Thank you for your quick and very informative reply! 

 

I hope others find this useful, as do I. 

 

And in the interest of reciprocity, here's my FlexScript code for making all conveyor legs disappear/appear (I have it in the OnSet trigger in the Parameters table Value code).  This took me quite a bit of digging and trial-and-error but it works well now:

 

/**Make conveyor legs disappear/reappear*/
treenode reference = param(1);
Variant newValue = param(2);
Variant oldValue = param(3);
int isReset = param(4);
 
// Get # of Conveyor System visualizations in model (see them listed in Toolbox panel).
int numConvSysVisualizations = getvarnode(Model.find("ConveyorSystem"), "visualizations").subnodes.length;
 
int desiredLegRepeatDist; // Repeat distance of conveyor legs.
 
if (newValue == 0) desiredLegRepeatDist = 0;    // Conveyor legs disappear (thank you FlexSim Answers forum).
if (newValue == 1) desiredLegRepeatDist = 4000; // Conveyor legs appear (FlexSim's default leg repeat distance value).
 
for (int i = 1; i <= numConvSysVisualizations; i++) { // Loop thru all conveyor visualizations.
// Set the desired leg repeat distance in each conveyor visualization.
getvarnode(Model.find("ConveyorSystem"), "visualizations").subnodes[i].subnodes[10].value = desiredLegRepeatDist;
}

 

--------

Mike