Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NXOpen.BlockStyler.UIBlock 2

Status
Not open for further replies.

Zoes

Mechanical
Sep 30, 2011
46
GB
Hi all,

I'm new to NXopen and I have a quite silly question; how I add items in a listbox and bitmaps in a dialog created by the blockstyler?
I thought the obvious answer will be something like this:
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try
If block Is list_box0 Then
Dim list_box0Props As PropertyList = list_box0.GetProperties()
list_box0Props.AddItem("value")
End If

But I’m getting the error that “AddItem” is not a member NXOpen.Blockstyler.Property. What I’m doing wrong?

Thanks,
Zoes
 
Replies continue below

Recommended for you

Hi Zoes,

You are close to your goal. After calling GetProperties() you will need to call SetStrings(), e.g.

PropertyList.SetStrings("ListItems", <your list here>)

where <your list here> is of type String(), e.g. an array of strings you wish to fill the list with. "ListItems" is the property keyword used by the ListBox to get/set the items in that list.

Therefore your example should look something like (untested!):

Code:
If block Is list_box0 Then
Dim list_box0Props As PropertyList = list_box0.GetProperties()
Dim listbox0Values() as String = {"value"}
list_box0Props.SetStrings("ListItems", list_box0Values)
End If



Marc
NX Software Developer
 
Thank you Marc. That was quick!

The error now is that listbox0Values needs to be declared.
That's confusing. I can see that the listbox0Values is String, what more does it need?
 
Whoops! It's supposed to be

Code:
Dim list_box0Values() as String = {"value"}

Marc
NX Software Developer
 
It does display an empty box now. The idea was to display the string "value" in there, was it not?
 
Yes, that's the idea. Why it's not showing I can't say for sure. If you give me your code, I can take a look at it for you.

Marc
NX Software Developer
 
Ah, I see the problem now. The issue is the callback you selected to place the code in - update_cb(). This is called by ok_cb(), which is only triggered when you click on the "OK" button. The dialog will close before you can actually see value in the list box.

You will need to place the code in initialize_cb(), which will fill your list box as soon as your dialog appears:

Code:
Public Sub initialize_cb()
Try

group0 = CType(theDialog.TopBlock.FindBlock("group0"), NXOpen.BlockStyler.UIBlock)
label0 = CType(theDialog.TopBlock.FindBlock("label0"), NXOpen.BlockStyler.UIBlock)
list_box0 = CType(theDialog.TopBlock.FindBlock("list_box0"), NXOpen.BlockStyler.ListBox)

[b]
Dim list_box0Props As PropertyList = list_box0.GetProperties()
Dim list_box0Values() As String = {"value"}
list_box0Props.SetStrings("ListItems", list_box0Values)
[/b]

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Subx

Marc
NX Software Developer
 
It worked! Thank you very much for your help!

Ps: to upload an image in the "label0", will follow similar code?
 
Place the following in initialize_cb():

Code:
label0.GetProperties.SetString("Bitmap", <path to bitmap>"

e.g.

Code:
label0.GetProperties.SetString("Bitmap", "C:\temp\mybmp.bmp")

Marc
NX Software Developer
 
Thanks! I do this for a living... ;)

I would appreciate it if you thanked me for my valuable post(s) by clicking on "Thank MarkyMON for this valuable post!" :)

Marc
NX Software Developer
 
Can I ask further, how we load specifc named expressions to be edited through a UI dialog?
 
Should be possible, but I need more information. What particular expressions do you want to edit? Where are the expressions coming from (work part, display part, any part)? If I remember correctly, there should be a block that does what you need.

Marc
NX Software Developer
 
Existed expressions on the work part. For example on the work part there are expressions for "thickness", "height" etc. I would like to know if you choose to load an expression on UI dialog with the command below

expression0 = CType(theDialog.TopBlock.FindBlock("expression0"), NXOpen.BlockStyler.UIBlock)

Can you configure it to load the "thickness" expression for the user to edit from there instead for opening it from Tools -> Expressions?
 
Code:
expression0.GetProperties.SetString("Forumla", "thickness")

Marc
NX Software Developer
 
that's a read only box? Is there another reference to make "thickness" editable?
 
Unfortunately some more code is required. I assumed that you can set the expression block's formula and still can edit the expression; this is not the case.

This is what needs to happen:

1. Find the work part's thickness expression. This will be a NXOpen.Expression object.
2. In the initialize_cb(), the expression's ExpressionObject needs to be set the to the work part's thickness expression.

According to the NX help:

Block UI Styler said:
ExpressionObject


Specifies the Expression object that is tied to the block. User inputs to the block are written to the Expression object.


IG


TaggedObject


Object of type NXOpen.Expression.

This means that any changes to the block (e.g. change of value) will also change the value of the expression (in your case, thickness).

Please send me the code so I can implement the changes.

Marc
NX Software Developer
 
Thank you Mark

Tried to call the expression like this and attribute its value to a string variable:
Dim expression0 As Expression = CType(workPart.Expressions.FindObject("thickness"), Expression)
Dim thickness As String = expression1.Value.ToString

Still I'm not sure if I'm in the right track.
Here is the code.
 
 http://files.engineering.com/getfile.aspx?folder=c6bab0ee-0481-4a01-a643-7c97ef425aab&file=letsplay.zip
Code:
    Public Sub initialize_cb()
        Try


            group0 = CType(theDialog.TopBlock.FindBlock("group0"), NXOpen.BlockStyler.UIBlock)
            expression0 = CType(theDialog.TopBlock.FindBlock("expression0"), NXOpen.BlockStyler.UIBlock)
		
		[b]Dim thicknessExp as Expression = CType(theSession.Parts.Work.Expressions.FindObject("thickness"), Expression)
		If thicknessExp IsNot Nothing Then
			expression0.GetProperties.SetTaggedObject("ExpressionObject", thicknessExp)
		End If[/b]

        Catch ex As Exception
        
            '---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        End Try
    End Sub

From GTAC:

GTAC said:
Subject: [PR-01864668] PRO: Expression block deletes an unused expression on OK/APPLY

Description of Problem:
EX 6461147:

Problem Description:


If you tie an expression to the block in the initialize callback then unless it is in use (referenced by a feature or another expression) it gets deleted from the part when the dialog comes down (OK or Cancel) regardless of whether the application created it or it was already in the part. Since an expression was not automatically created, it is surprising that it is automatically deleted.

PR Number : 1864668
Date Opened: 12-sep-2011
Status : O
Priority : 1
Family : NX
Application: SYSENG
Function : NXOPEN
Category : DOCUMENTATION
Release : V7.5.2
Platform : INTEL
OS : WINDOW
OS Version : XP32_SP3
Terminal : OTHER
Platform specific: Undetermined

It basically means that if you have a standalone expression and it is not referenced by another expression, then that standalone expression is deleted when clicking OK or Apply in the dialog.

Marc
NX Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top