Smart questions
Smart answers
Smart people
Join Eng-Tips Forums
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips now!
  • 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!

Join Eng-Tips
*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.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Zoes (Mechanical) (OP)
21 Aug 12 8:38
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()

'MeesageWindow
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
Helpful Member!(2)  cowski (Mechanical)
22 Aug 12 16:46
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".

CODE

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'   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  
        lw.Open()  

        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  
 'lw.WriteLine(myExp.Name)
            If myExp.Name = "Breadth" Then  
                breadthExp = myExp  
            End If  
            If myExp.Name = "Thickness" Then  
                thicknessExp = myExp  
            End If  
        Next  

        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  
        f1.ShowDialog()  

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

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

        theSession.UpdateManager.DoUpdate(markId1)  
        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)  
        Me.Close()  
    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)  
        Try  
            If disposing AndAlso components IsNot Nothing Then  
                components.Dispose()  
            End If  
        Finally  
            MyBase.Dispose(disposing)  
        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.SuspendLayout()  
 '
 'Label1
 '
        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"  
 '
 'TextBox1
 '
        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  
 '
 'Label2
 '
        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"  
 '
 'TextBox2
 '
        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  
 '
 'btnAccept
 '
        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  
 '
 'btnCancel
 '
        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  
 '
 'Form1
 '
        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.Controls.Add(Me.btnCancel)  
        Me.Controls.Add(Me.btnAccept)  
        Me.Controls.Add(Me.TextBox2)  
        Me.Controls.Add(Me.Label2)  
        Me.Controls.Add(Me.TextBox1)  
        Me.Controls.Add(Me.Label1)  
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle  
        Me.Name = "Form1"  
        Me.Text = "Form1"  
        Me.ResumeLayout(False)  
        Me.PerformLayout()  

    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
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

www.nxjournaling.com

Zoes (Mechanical) (OP)
28 Aug 12 5:58
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)
{
this.Close();
}

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("");
}
else
{
//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);
}

}
}
cowski (Mechanical)
28 Aug 12 8:30
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.

www.nxjournaling.com

Zoes (Mechanical) (OP)
28 Sep 12 6:34
Hi,

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
Z.

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!

Back To Forum

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