×
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

NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

(OP)
I have an NX Journal which I wanted to include in an NX Open application I am working on. The journal starts with:

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Annotations
Imports NXOpen.Utilities


Module NXJournal

Sub Main()

        Dim thesession As Session = Session.GetSession
        Dim ufsession As UFSession = UFSession.GetUFSession()
        Dim dp As Part = thesession.Parts.Display
        Dim nc As NoteCollection = dp.Notes 

When I add the declarations from Main into my NXOpen file which is then compiled and run, it doesn't like the line:

CODE

Dim dp As Part = thesession.Parts.Display 

Is it possible the displayed part isn't accessible this way from a compiled (.dll) NXOpen file?

Thanks,
Jeff

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

Quote (jmarkus)

Is it possible the displayed part isn't accessible this way from a compiled (.dll) NXOpen file?

No.
Are you sure that you have an open part when the code is run? If there is a CAE or FEM part open, you will get a type mismatch error. If there is no part open, dp will probably just be a null reference.

www.nxjournaling.com

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

(OP)
Yes, I definitely have an open part. I'm getting the error in the syslog referring to that line as:

CODE

System.NullReferenceException: Object reference not set to an instance of an object. 

What would make NX think I don't have a part open when I do?

Jeff

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

Can you post any of the source code that you compiled? I'd guess there is something else going on in the code.

Are you using remoting? or running in batch mode?

www.nxjournaling.com

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

(OP)
This is the basic code I am having trouble with. At this point all it is supposed to do is step through all the text on a drawing sheet displaying one line at a time in a message box. It works when run as a journal, but it doesn't work as a DLL.

CODE

Public Class NXTextSelect

    'Description: Select Case notes And labels



    Public Shared Sub Main()
        Dim thesession As Session = Session.GetSession
        Dim ufsession As UFSession = UFSession.GetUFSession()
        Dim dp As Part = thesession.Parts.Display
        Dim nc As NoteCollection = dp.Notes

        'MsgBox("Selecting all text")

        Try
            For Each sda As Annotations.SimpleDraftingAid In nc
                Try
                    Dim nxText() As String
                    Dim line As String
                    Dim undoText As String = "Update Note"
                    Dim undoMark As Session.UndoMarkId
                    Dim i As Integer = 0

                    'Get the text from the note or label in NX
                    nxText = sda.GetText

                    For Each line In nxText

                        MsgBox(line)
                        i += 1
                    Next

                    'Set the text for the note or label in NX
                    sda.SetText(nxText)


                    'Update so the text changes are applied to the system
                    undoMark = thesession.SetUndoMark(Session.MarkVisibility.Visible, undoText)
                    thesession.UpdateManager.DoUpdate(undoMark)
                Catch ex As Exception
                    MsgBox(ex.Message & " Couldn't execute")
                End Try
            Next

        Catch e As Exception
            MsgBox(e.Message & " Couldn't execute")
            System.Diagnostics.Trace.WriteLine("Problem with traversing selected objects array")
            System.Diagnostics.Trace.WriteLine(e.ToString)

        End Try


    End Sub



    'Unloads the image immediately after execution within NX
    Public Shared Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Class 

Jeff

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

Why are there no "Imports" statements?

www.nxjournaling.com

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

(OP)
Sorry, I didn't copy those lines, they come before the Public Class:

CODE

Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Annotations

Public Class NXTextSelect 

Jeff

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

Does your project reference the correct NX dll files?
Did you use the NX author "signing" tool to sign your resulting dll file?

www.nxjournaling.com

RE: NX Journal vs NX Open - .vb vs compiled - Access Displayed Part

(OP)
That's why I needed a second set of eyes! Thanks cowski! I was jumping between NX9 and NX10 and used the wrong NX DLLs!

Jeff

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