Initialise a GUI does not work

To all

I have created a GUI with UI builder and it works fine
There is a call back function initialize_cb() which I used to set the deault value in the GUI.
One of the boxes on the GUI is for a scale factor and I want it to de defaulted to 1.0 when the GUI is displayed. I have the following line in the function

Dim propertyList As BlockStyler.PropertyList
propertyList = BlkScaleValue.GetProperties()
propertyList.SetDouble("Value", 1.0)

However it seems that the GUI remembers the previous input and not does re-set itself to 1.0 when I re-display it (after closing it). This is valid for the other option/boxes on the GUI.

Why is that?

Thanks

Regards

JXB

First of all, I'd recommend that you use the properties of the block to get/set values, rather than the goofy old "GetProperties" approach.

So, your code would just be:

BlkScaleValue.Value = 1.0

One line, instead of three, and you don't have to remember any magic strings.

The value you set in the initialize callback is probably getting wiped out by dialog memory. Put your initilaization code in the "show" callback, instead. The precedence of various default values is a bit complicated. The best description of the situation that I have seen is in the "Getting Started with SNAP" guide. here is what it says:

Precedence of Values, Again
It's sometimes important to understand what happens before a BlockDialog gets displayed, so that you can control its contents. The situation is a little more complex with BlockDialog objects, because the dlx file is involved, and there are more callbacks. Here is what happens:
(1) Values and options from the corresponding dlx file are used, then …
(2) Values and options specified in the InitializeCallback function are applied, and then …
(3) Values from dialog memory are applied, and then next…
(4) Values and options specified in the DialogShownCallback function are applied, and then finally …
(5) The dialog is displayed
So, you can see that values and options you set in the Initialize callback might get overwritten by values from dialog memory. Since the DialogShown callback is executed later, it does not suffer from this drawback. On the other hand, the Initialize callback can set values that the DialogShown callback cannot. So, in short, the Initialize callback gives you broader powers, but the DialogShown callback gives you stronger ones.

Thanks very much for the input ciao. Much appreciated. As I am still in the testing phase I "lifted " the GetProperties from one the examples. I vaguely remember trying a more direct approach but it didn't work. I got an error message "value is not a member of UI block". While most of the code seems to work I have not managed to find in the doc where the "magic string" are defined.
Will spend some time looking at putting the code in the dialogShown_cb() call back but a very quick test throws up some errors. for example one cannot have (it seems) lines like
ListBox1FileNameList.Height = 6
but the GUI is displayed and the code works! Just a matter of moving some if the lines I guess.

Thanks
Regards
JXB

Thanks
Regards

The "value is not a member" error is what you get when you pass an illegal magic string to the GetProperties function. And you won't find anyplace where the legal magic strings are documented. That's why I advise against using the GetProperties function.

You can't move all of your code to the dialogShown_cb callback, because, as the notes above point out, some modifications are not allowed there (like modifying a ListBox height). So leave things like that in the Initialize callback.

Thanks for that.
I just tried again the suggested "direct" option: BlkScaleValue.Value = 1.0. Where 'BlkScaleValue' is a input box accepting number (double). I am getting the error message: " 'Value' is not a member of UI block".

Thanks
Regards

Well "Value" is certainly a property of an NXOpen.BlockStyler.DoubleBlock object, and it works for me. Please show us your code.

Well "Value" is certainly a property of an NXOpen.BlockStyler.DoubleBlock object, and it works for me. Please show us your code.

from the code generated by NX when creating the GUI
BlkScaleValue = CType(theDialog.TopBlock.FindBlock("BlkScaleValue"), NXOpen.BlockStyler.UIBlock)
and in function: Public Sub dialogShown_cb()
I have tried the following line
BlkScaleValue.Value = 1.0

Thanks
Regards

Because of the cast you performed (with CTYpe), BlkScaleValue is an object of type NXOpen.BlockStyler.UIBlock.
Objects of this type do not have a "Value" property, as the error message told you.

Use this code instead:

BlkScaleValue = CType(theDialog.TopBlock.FindBlock("BlkScaleValue"), NXOpen.BlockStyler.DoubleBlock)

Thanks for that ciao. The doc is starting to (very slowly) make sense with your pointer(s). It seems that the NX.CAE examples are a mix bag of programming technique as I read the lines,

loadcase = CType(theDialog.TopBlock.FindBlock("loadcase"), NXOpen.BlockStyler.ListBox)
iteration = CType(theDialog.TopBlock.FindBlock("iteration"), NXOpen.BlockStyler.ListBox)
scaleValue = theDialog.TopBlock.FindBlock("scaleValue")
where scalevalue is defined as follows
Private scaleValue As NXOpen.BlockStyler.UIBlock

Anyway I modified the code as suggested and it works.
I am defining the blocks as follows however
Private BlkScaleValue As NXOpen.BlockStyler.DoubleBlock

I am now playing with the 'Show' option. I have added a filter (string block) for future use and it's currently hidden

Thanks
Regards