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


Window Forms in NXOpen

Window Forms in NXOpen

Window Forms in NXOpen

Hi all,

I have written the code bellow but while trying to execute it gives me an error message: "Error in the external library. See syslog for details ... Function name ufusr".
The form is supposed to load the existing expressions of breadth and thickness and assign them to two textboxes expression0 and experssion01.

Does anybody knows how to fix this?

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Windows.Forms

Public Class Form1
Private Shared theSession As Session
Private Shared theUI As UI
Public nErrs1 As Integer
Public id1 As Session.UndoMarkId
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Dim nxopenSession As NXOpen.UF.UFSession

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
nxopenSession = NXOpen.UF.UFSession.GetUFSession()

Dim MessageBoxTitle As String = "Track Expression"

'Find Expressions
Dim breadthExp As Expression = CType(theSession.Parts.Work.Expressions.FindObject("Breadth"), Expression)
Dim thicknessExp As Expression = CType(theSession.Parts.Work.Expressions.FindObject("thickness"), Expression)

'Convert Expressions' Values to Strings
Dim breadth As String = breadthExp.Value.ToString
Dim thickness As String = thicknessExp.Value.ToString

If breadthExp IsNot Nothing Then

expression0.Text = breadth
expression01.Text = thickness

If (breadth = 25 And thickness = 6) Then
theUI.NXMessageBox.Show(MessageBoxTitle, NXMessageBox.DialogType.Information, "yeah")

End If

'Force Update and redraw part
nErrs1 = theSession.UpdateManager.DoUpdate(id1)

End If
End Sub

Private Sub Apply_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply_btn.Click

'Force Update and redraw part
nErrs1 = theSession.UpdateManager.DoUpdate(id1)

End Sub
End Class

RE: Window Forms in NXOpen

Here's some example code (be aware it does no error checking) for one way to do it. Copy and paste it into a text file, change the extension to .vb and run it as a journal. It looks for expressions named "Breadth" and "Thickness".


'   start of module code

Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

    Public breadthValue As Double = 0  
    Public thicknessValue As Double = 0  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim lw As ListingWindow = theSession.ListingWindow  

        Dim markId1 As Session.UndoMarkId  
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "journal")  

        Dim myExpressions() As Expression = workPart.Expressions.ToArray  

        Dim breadthExp As Expression = Nothing  
        Dim thicknessExp As Expression = Nothing  

        For Each myExp As Expression In myExpressions  
            If myExp.Name = "Breadth" Then  
                breadthExp = myExp  
            End If  
            If myExp.Name = "Thickness" Then  
                thicknessExp = myExp  
            End If  

        Dim f1 As New Form1  
        f1.Label1.Text = breadthExp.Name.ToString  
        f1.TextBox1.Text = breadthExp.Value.ToString  

        f1.Label2.Text = thicknessExp.Name.ToString  
        f1.TextBox2.Text = thicknessExp.Value.ToString  

        If breadthValue <> 0 Then  
            breadthExp.Value = breadthValue  
        End If  

        If thicknessValue <> 0 Then  
            thicknessExp.Value = thicknessValue  
        End If  

        theSession.DeleteUndoMark(markId1, Nothing)  

    End Sub  

    Public Function GetUnloadOption(ByVal dummy As String) As Integer  

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

    End Function  

End Module  
'   end of module code

'   start of form class code

Public Class Form1  

    Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click  
        Module1.breadthValue = Double.Parse(TextBox1.Text)  
        Module1.thicknessValue = Double.Parse(TextBox2.Text)  
    End Sub  
End Class  

'   end form class code

'   form designer code

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _  
Partial Class Form1  
    Inherits System.Windows.Forms.Form  

 'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _  
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)  
            If disposing AndAlso components IsNot Nothing Then  
            End If  
        End Try  
    End Sub  

 'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer  

 'NOTE: The following procedure is required by the Windows Form Designer
 'It can be modified using the Windows Form Designer.  
 'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _  
    Private Sub InitializeComponent()  
        Me.Label1 = New System.Windows.Forms.Label()  
        Me.TextBox1 = New System.Windows.Forms.TextBox()  
        Me.Label2 = New System.Windows.Forms.Label()  
        Me.TextBox2 = New System.Windows.Forms.TextBox()  
        Me.btnAccept = New System.Windows.Forms.Button()  
        Me.btnCancel = New System.Windows.Forms.Button()  
        Me.Label1.AutoSize = True  
        Me.Label1.Location = New System.Drawing.Point(32, 43)  
        Me.Label1.Name = "Label1"  
        Me.Label1.Size = New System.Drawing.Size(39, 13)  
        Me.Label1.TabIndex = 0  
        Me.Label1.Text = "Label1"  
        Me.TextBox1.Location = New System.Drawing.Point(102, 40)  
        Me.TextBox1.Name = "TextBox1"  
        Me.TextBox1.Size = New System.Drawing.Size(154, 20)  
        Me.TextBox1.TabIndex = 1  
        Me.Label2.AutoSize = True  
        Me.Label2.Location = New System.Drawing.Point(32, 89)  
        Me.Label2.Name = "Label2"  
        Me.Label2.Size = New System.Drawing.Size(39, 13)  
        Me.Label2.TabIndex = 2  
        Me.Label2.Text = "Label2"  
        Me.TextBox2.Location = New System.Drawing.Point(102, 86)  
        Me.TextBox2.Name = "TextBox2"  
        Me.TextBox2.Size = New System.Drawing.Size(154, 20)  
        Me.TextBox2.TabIndex = 3  
        Me.btnAccept.Location = New System.Drawing.Point(35, 191)  
        Me.btnAccept.Name = "btnAccept"  
        Me.btnAccept.Size = New System.Drawing.Size(96, 50)  
        Me.btnAccept.TabIndex = 4  
        Me.btnAccept.Text = "Accept"  
        Me.btnAccept.UseVisualStyleBackColor = True  
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel  
        Me.btnCancel.Location = New System.Drawing.Point(160, 191)  
        Me.btnCancel.Name = "btnCancel"  
        Me.btnCancel.Size = New System.Drawing.Size(96, 50)  
        Me.btnCancel.TabIndex = 5  
        Me.btnCancel.Text = "Cancel"  
        Me.btnCancel.UseVisualStyleBackColor = True  
        Me.AcceptButton = Me.btnAccept  
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)  
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font  
        Me.CancelButton = Me.btnCancel  
        Me.ClientSize = New System.Drawing.Size(292, 266)  
        Me.ControlBox = False  
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle  
        Me.Name = "Form1"  
        Me.Text = "Form1"  

    End Sub  
    Friend WithEvents Label1 As System.Windows.Forms.Label  
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox  
    Friend WithEvents Label2 As System.Windows.Forms.Label  
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox  
    Friend WithEvents btnAccept As System.Windows.Forms.Button  
    Friend WithEvents btnCancel As System.Windows.Forms.Button  
End Class  
'   end of form designer code


RE: Window Forms in NXOpen

Thank you for the reply.
Do you have any idea how we use the debugger of Visual Studio for Nx Open applications?
Also do you know anything about threads in NXOpen? I have the windows forms .exe (instead of using the journal) running and the moment when I change an expression the part changes and a window comes up saying "Work in progress".. Have you come up with a similar proplem before?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NXOpen;
using NXOpen.UF;
using NXOpen.UIStyler;

namespace LoadDLL_20082012

public partial class Form1 : Form
public Form1()

//Load expression
breadthExp = (Expression)theSession.Parts.Work.Expressions.FindObject("Breadth");
thicknessExp = (Expression)theSession.Parts.Work.Expressions.FindObject("thickness");

//Convert Expressions' Values to Strings
String breadth = breadthExp.Value.ToString();
String thickness = thicknessExp.Value.ToString();
this.breadth_box.Text = breadth;
this.thickness_box.Text = thickness;


public NXOpen.UI theUI = NXOpen.UI.GetUI();
public Session theSession = Session.GetSession();
public UFSession theUfSession = UFSession.GetUFSession();
public NXOpen.Session.UndoMarkId Id2;
public int nErrs1;
public Expression breadthExp;
public Expression thicknessExp;

private void level1_btn_Click(object sender, EventArgs e)
//theUfSession.UF.PrintSyslog("HELLO_Zoe!!", false);
// Load level
level1_groupbox.Visible = true;

private void close_btn_Click(object sender, EventArgs e)

private void Apply_btn_Click(object sender, EventArgs e)
// Get values
int br = Convert.ToInt32(breadth_box.Text.Trim());
int th = Convert.ToInt32(thickness_box.Text.Trim());

// Update part
nErrs1 = theSession.UpdateManager.DoUpdate(Id2);

// Load Bitmap Images
if (br == 25 && th == 6)

//Change Image Message
MessageBox.Image = Image.FromFile("");
MessageBox2.Image = Image.FromFile("");
//Change Image Message
MessageBox.Image = Image.FromFile("");
MessageBox2.Image = Image.FromFile("");


private void breadth_box_TextChanged(object sender, EventArgs e)
theSession.Parts.Work.Expressions.Edit(breadthExp, this.breadth_box.Text);

private void thickness_box_TextChanged(object sender, EventArgs e)
theSession.Parts.Work.Expressions.Edit(thicknessExp, this.thickness_box.Text);


RE: Window Forms in NXOpen

Regarding debugging, I have seen a post in PLMWorld by Aaron Elliott giving instructions, http://www.plmworld.org/p/fo/st/thread=1987
You may have to sign up for a free account to view it.

I've not (yet) had a need to create new threads, so I won't be of much help there. However, I know there are a few members here that might be able to help; hopefully they will jump in the discussion and teach us something.


RE: Window Forms in NXOpen


I was wondering if any of the members have load two window forms in NX at the same time.
My code loads and shows both forms but then produces and error ufsr. The log file is not very helpful for identifying and fixing the problem.

Thanks in advance

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!


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close