×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NXOpen.BlockStyler.UIBlock
2

NXOpen.BlockStyler.UIBlock

NXOpen.BlockStyler.UIBlock

(OP)
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
 

RE: NXOpen.BlockStyler.UIBlock

2
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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
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?
 

RE: NXOpen.BlockStyler.UIBlock

Whoops! It's supposed to be

CODE

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

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
It does display an empty box now. The idea was to display the string "value" in there, was it not?

RE: NXOpen.BlockStyler.UIBlock

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
 

RE: NXOpen.BlockStyler.UIBlock

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)


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


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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
It worked! Thank you very much for your help!

Ps: to upload an image in the "label0", will follow similar code?

RE: NXOpen.BlockStyler.UIBlock

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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
You made my day.

Thanks Marc

RE: NXOpen.BlockStyler.UIBlock

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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Can I ask further, how we load specifc named expressions to be edited through a UI dialog?

RE: NXOpen.BlockStyler.UIBlock

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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
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?

RE: NXOpen.BlockStyler.UIBlock

CODE

expression0.GetProperties.SetString("Forumla", "thickness")

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
that's a read only box? Is there another reference to make "thickness" editable?  

RE: NXOpen.BlockStyler.UIBlock

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:

Quote (Block UI Styler):


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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
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.

RE: NXOpen.BlockStyler.UIBlock

CODE

    Public Sub initialize_cb()
        Try


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


        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:

Quote (GTAC):


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
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
So the expression updates if it exists (Tools-> Expression; I can see that "thickness" has been updated), but is not being applied to the work part. Is that correct?  

RE: NXOpen.BlockStyler.UIBlock

Quote (Zoes):


...but is not being applied to the work part.

I'm not exactly sure what you mean. It should depend on how the expression is being used in the (work) part...

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Well, when you use the UI dialog box to update the "thickness, for e.g to 20mm, the actual value in the expression list indeed updates to 20mm  but I can not see the work part "thicken" by 20mm. Does that make sense?
In order for the new value to be applied to the work part you need to go Tools-> Expressions -> Apply, then you can see the workpart increase size.

Is there any code line to update the workpart based on the current expressions's values? Update (regenerate) the display?

RE: NXOpen.BlockStyler.UIBlock

Interesting... perhaps a forced interpart update is necessary, or the behavior is due to your NX settings. I will take a look and let you know.

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Thank you Mark.

I wonder if it has to do with something like that:

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Update Expression Data")

RE: NXOpen.BlockStyler.UIBlock

If that were the case, then your expression would have its old value. Undo marks are usually used to rollback any changes in case of an error (as an example).

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Any ideas for re-drawing the object based on the user input on a dialog box?

RE: NXOpen.BlockStyler.UIBlock

I just tried it. It works perfectly for me. Are you sure your expression is used with your model?

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Yes. The value thickness is an expression in use in the model.   

RE: NXOpen.BlockStyler.UIBlock

Which NX version are you using? I think it would also be a good idea if you sent me your model. I have a strong feeling that the issue has to do with some NX settings...

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

Worked for me. The issue is either the code or some NX setting I am unaware of.

Marc
NX Software Developer
 

RE: NXOpen.BlockStyler.UIBlock

(OP)
Thank you Mark. Will look into it.

RE: NXOpen.BlockStyler.UIBlock

(OP)
Very curious why it worked for you. Tried a different machine today and didn't work either.  

RE: NXOpen.BlockStyler.UIBlock

(OP)
Can you perhaps send a screenshot of your Custom Settings?

RE: NXOpen.BlockStyler.UIBlock

(OP)
Got it. Just needed an update of the id Session;

nErrs1 = theSession.UpdateManager.DoUpdate(id1)
         
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources