Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
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
 
Replies continue below

Recommended for you

jmarkus said:
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
 
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
 
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor