question

Sebastian Lang avatar image
0 Likes"
Sebastian Lang asked Sebastian Lang commented

Creating links between GUI and model via script

Hello,

I am trying to give a value of an edit field in my GUI as equation value of a constraint in OptQuest by using a script. The following script did not work:

assertattribute(node("MODEL:/Tools/GUIs/IPK Optimizer/Input DC"), "coldlink", DATATYPE_STRING);
node("MODEL:/Tools/GUIs/IPK Optimizer/Input DC>coldlink").value = "@>objectfocus+/Tools/OptQuest/constraints/Constraint 1/Equation";
coldlink(node("MODEL:/Tools/GUIs/IPK Optimizer/Input DC>coldlink"));
applylinks(node("MODEL:/Tools/GUIs/IPK Optimizer"));

The value of objectfocus is: "MAIN:/project/model".

I also tried it without the third line:

coldlink(node("MODEL:/Tools/GUIs/IPK Optimizer/Input DC>coldlink"));

To be honest: I have no clue what the coldlink() command do. It was only a guess, that this function could convert a node into a coldlink.

Secondly: Is there also the possibility to use the value of an edit field directly in a script? Somehow like this:

OptQuestDesign.last.value = "[Sink Statistic]>" + numtostring(Value of edit field)

Thanks!

Sebastian

Choose One
guiscriptingcoldlinkhotlink
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matt Long avatar image
0 Likes"
Matt Long answered Sebastian Lang commented

I'm a little confused as to what you're trying to do, but here are some tidbits that will hopefully help.

The coldlink() command returns the object attribute node named 'coldlink'. An object attribute node is drawn blue in the tree. Other examples would be spatialx(), tooltip(), eventfunctions() etc.

The coldlink node that you are asserting in the view is only being asserted to the data in the Model. Once the view is opened, a copy of the data defined in the model is created. This means calling applylinks() on a node in the model will have no affect. Instead you would have to get a reference to the node in the open view and call applylinks on that. This would be something like:

VIEW:/active/IPK Optimizer59812348741/Input DC>coldlink

If you're just looking to get the text value of a field, you can use the getviewtext() command. This of course will require you to have a reference to the actual text field, similar to the above path. If this is a view not made by you, you may want to look at the GUI code and see where the value of the text field is being stored in the tree. If you have created the view, then you can use the coldlink to create a reference to a node in the tree where the data will be stored. You can then reference that data from other locations.

To answer your second question, yes you can. I'm not exactly sure what your Sink Statistic is supposed to be or what the value of your edit field looks like, but the code would look something like this:

OptQuestDesign.last.value = "[Sink Statistic]>" + getviewtext(view().find("active/PathToTextField"));
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sebastian Lang avatar image Sebastian Lang commented ·

Thanks for the information in terms of the coldlink() command and my second question. When I created this topic, I didn't noticed that I only assert links to my original GUI object and not also to the instance, which I have called to run my script. With this knowledge it was pretty easy to solve my problem.

0 Likes 0 ·
Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Sebastian Lang commented

You should add a coldlink node to your GUI and set its value to the path of the node the edit field represents:

I also added an OnKillFocus node that calls applylinks(c) so that changes made to the edit field are applied. Your edit field will now load the correct value from the model node when the GUI is opened and will apply any values you set in the edit field back to the model node.

coldlink(object) gets you a reference to the object's coldlink attribute if it has one.

You can get the text in the edit field using the getviewtext() command. However, you are using the edit field to set a node in the model so I would just read the value off the model node:

OptQuestDesign.last.value = "[Sink Statistic]>" + node("MODEL:/Tools/OptQuest/constraints/Constraint 1/Equation").value;

coldlink.png (7.3 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Sebastian Lang avatar image Sebastian Lang commented ·

Thanks for your answer. The problem is, that I have a script, which I execute with a button in my GUI and that this script creates at first the node in OptQuest and after that a link from the current GUI instance to the OptQuest Node. So it is not feasible for me to give the coldlink an adress before opening a GUI instance. But your answer brought me to the idea to create the coldlink attribute manually and to define only the address by script in the currently opened GUI instance. The following code lines work pretty well

    coldlink(node("@/Input DC", c)).value = "@>objectfocus+/Tools/OptQuest/constraints/Constraint 1/Equation/DC";
    applylinks(ownerview(c));
0 Likes 0 ·