ATTENTIONThis 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 |
#1
|
||||
|
||||
Button in model view
Hi,
i want to have some buttons on my objects. If they are pressed (double LM would be ok) then some functionality gets executed.... simple so far.. My plan was replacing the gui for those button objects with an empty gui which is executing something or at least can send a message to the objectfocus object and then closes it self.... I am experiencing two problems: 1. I can´t get the reference to the objectfocus object. I tried this on the onOpen of the GUI : treenode focus = node("@>objectfocus+",c); pt getname(focus); pr(); This does not work here, but it is working if I put a button to the gui and enter the code to the onPress attribute. 2. I get a lot of open guis in the active view treenode, which I can´t see. I tried to close the gui on the onOpen attribute with closeview(c); destroyobject(c); So the gui disapears, but the node is still there, and there are many more nodes than there should be... Well, all I need is a button in the modell view or in a visual tool....
__________________
kind regards Nico. |
#2
|
||||
|
||||
Nico,
1. If the code is entered in the OnOpen, then the reference c points to the main gui. Therefore, the path should be node(">objectfocus+",c). Remove the @. 2. You might try using the OnPreOpen to destroy the gui, instead of the OnOpen. There might be some weird implications of trying to destroy the gui from within its own code, but the OnPreOpen kind of has some custom logic in the engine that takes that into account and lets the user do that if needed. If you just want to execute some logic when the object is double-clicked, you might just try adding an OnClick event to the object. Go into its object tree. I usually put the node in >behaviour/eventfunctions. Add a node and give it the name OnClick, then right click on the main object in the tree and choose Edit|Rebind Object Attributes. Then add flexscript code, toggle the node flexscript, etc. Here's some sample code: Code:
int code = clickcode(); switch(code) { case LEFT_PRESS: pt("left press");pr(); break; case LEFT_RELEASE: pt("left release");pr(); break; case RIGHT_PRESS: pt("right press");pr(); break; case RIGHT_RELEASE: pt("right release");pr(); break; case DOUBLE_CLICK: pt("double click");pr(); break; } |
The Following 9 Users Say Thank You to Anthony Johnson For This Useful Post: | ||
Tom David (11-30-2008) |
#3
|
||||
|
||||
Hi Anthony,
I used the onClick code.. So I can have a trigger for every event in the attribute list.. but if you change this trigger, you have to compile... This works great .. thank you..
__________________
kind regards Nico. |
#4
|
||||
|
||||
Nico,
If the trigger is flexscript, you shouldn't have to compile. You can either build flexscript from the main menu, or right-click on the OnClick attribute and select Build|Build Node Flexscript. Yes, you can have an event associated with every On... attribute in the attribute list. However, by adding that event to the object, you override any functionality that is done by the object in the library, so you may not want to do that for all attributes. We still need to add a command like executeinheritedcode() that lets you call the standard functionality from within your own attribute's code. |
The Following 4 Users Say Thank You to Anthony Johnson For This Useful Post: | ||
RalfGruber (12-03-2008) |
#5
|
|||
|
|||
Quote:
Is there any way to keep the standard functionality in case I am overriding an existing eventfunction or do we have to wait for the executeinheritedcode() function ? For example, I want to use a flexscript 'OnSend' eventfunction in a 'Source' object. This overrides the 'OnSend' eventfunction of the 'FixedResource' object. If I do this, the 'Source' sends one item and it stops. Can I use flexscript to keep or implement the original 'OnSend' functionality of the 'FixedResource' object ? Kurt |
#7
|
|||
|
|||
Because I want to create a custom object, i.e. a batching/combiner machine. I already created this machine and also the functionality I need using the 'entrytrigger' and the 'exittrigger'. But now I want to place the flexscript of those triggers in the 'OnReceive' and 'OnSend' eventfunctions. I managed to override these eventfunctions in c++ but I'm not really a c++ coder and compiling every time you reopen the model is not an option.
|
#8
|
||||
|
||||
Kurt,
Unfortunately there's not a way right now to do this in flexscript. We've worked on extending this type of functionality for C++/DLLs, but that hasn't been extended yet to flexscript. |
The Following User Says Thank You to Anthony Johnson For This Useful Post: | ||
Kurt De Cock (04-02-2009) |
#9
|
||||
|
||||
Kurt,
You could also copy all of the code of the OnReceive and OnSend functions of the mother on eventtrigger and then add your own code there as well. Other point, have you thought about writing your code in the triggers like you have and then call as last function in that trigger a different node that acts as user trigger? Then in the GUI you can point to that new trigger (usually a node under labels) So that way you have your code nicely tucked away and still give somebody the possibility to add it's own exit and entry triggers. Steven |
The Following 2 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Phil BoBo (04-02-2009) |
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
New view setting | KelvinHo | Q&A | 2 | 05-29-2008 01:44 AM |
Get view reference | AlanZhang | Q&A | 3 | 03-13-2008 08:51 AM |
adding a button on the tool bar | Pablo Concha | Q&A | 4 | 09-13-2007 10:46 AM |
Controlling the camera view to be focused on a moving object in your model. | Regan Blackett | Tips and Tricks | 0 | 08-03-2007 10:12 AM |