Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal - Windows Forms - Selecting Objects

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
I have a journal which sets certain attributes displayed as notes on a drawing. The journal uses windows forms to show and allow editing of the current attributes.

In case the attributes are not actually assigned to the notes (i.e. the user typed in the drawing title as "MY PART" instead of using <W@TITLE>) there are buttons on the form to allow the user to select a note and it will replace the manual text with the correct attribute reference (e.g. <W@TITLE>.

The form works without the buttons for manually assigning text to the attributes, and I can get the code working in NX separately to select the text and assign it with the attribute value, however...

when I try to add the code to select a note so that clicking the button runs the function to select the text, I find that I cannot actually select anything (even though the NX selection dialog comes up). It is as if the focus is fixed on the Windows Form and I don't know how to surrender control back to the NX interface to be able to select objects.

I have heard that windows forms are not fully supported through VB.NET NX Journaling, so I may be up against a wall here, but if anyone has any suggestions, it would be appreciated.

Thanks,
Jeff
 
Replies continue below

Recommended for you

The winforms dialogs are by default modal, so they wont allow you to do anything in the attached application unless closed out. Instead of calling showDialog(), you should be able to call just show() which will call the winform as modeless allowing selection within the NX application. I haven't tried this but it should work, I remember reading it in the documentation a while back.
 

And also see this code

I could not do something (an example) that works from this article.

If you do please share me.

Thank you in advanced


Code:
'How to Use a Modeless WinForm and Still Immediately Unload your .DLL 
'Many programmers create WinForms for user interaction with NXOpen custom automation routines.  WinForms 
'can be displayed as either modal or modeless dialogs.  If you post your form using ShowDialog(), the resulting 
'dialog is modal, and the user cannot perform any other actions within NX while the dialog is displayed.  This is 
'often inconvenient, as the user might need to move the model around or query something with the Information  
'menu, for example.  If you post the form with Show() instead, then the dialog is modeless.  In this state, some 
'interaction with NX is allowed, but it is not possible to use the unload option “Immediately”, because doing so will
'cause the form to be dismissed as soon as it is posted.
'During the program development and testing process, it saves time if the program can be unloaded immediately,
'so that the programmer can make changes to the code, re-build, and test again without taking the steps required
'to explicitly unload the .DLL.
'Once the program has been deployed to your user community, you might want the program to unload 
'immediately for a variety of reasons, such as to release any licenses the program was reserving, or perhaps to 
'make a small change to the library, which you cannot do if a user has loaded the library and then left his session 
'running.  Whether he is still using the .DLL or not, if it remains loaded, the programmer cannot update it.
'The solution to this quandary is to create a second thread within your program that will check to see whether the 
'form has been dismissed.  In general, we do not recommend using multiple threads with NXOpen code, as 
'NXOpen is not considered to be “thread-safe”.   However this method is only making one call to NX code – the 
'one to unload the library.  The rest of the time it is just checking to see whether the form is still there, or counting 
'the clock ticks.  Note that the code shown below is actually only performing the check for the form dismissal 
'every thirty seconds.  This seems immediate enough for most occasions.  You can tinker with this delay period 
'by changing 30000 to some other value, or you can remove the call to Thread.Sleep() completely.
'This method will allow you to use modeless dialogs, so that the user can interact with NX while the form is 
'displayed, and still retain the desired behavior of unloading the .DLL when the program is finished.  (The form 
'code is omitted intentionally for brevity.)



Option Strict Off
Imports System
Imports System.Threading
Imports System.Reflection
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Module unload_modeless_winform_immediately
    Dim myform As New Form1
    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Public Sub Main()
        myform.Show()
        Dim checkThread As New Thread(New ThreadStart(AddressOf IsFormDismissed))
        checkThread.Start()
    End Sub
    Public Sub IsFormDismissed()
        Do
            If myform.IsDisposed() = True Then
                UnloadNXLibrary()
            End If
            Thread.Sleep(30000)
        Loop
    End Sub
    Sub UnloadNXLibrary()
        Dim runningProgram As Assembly = Assembly.GetExecutingAssembly()
        ufs.UF.UnloadLibrary(runningProgram.Location)
    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
    End Function
End Module
 
The "modeless" form option only works if you compile your code; if you are running a journal file, you can only use the "modal" form option. It has been a while since I experimented with winforms, but I think that you can close the form to allow for selection within NX, then re-open the form for other user input (if necessary).

www.nxjournaling.com
 
Thanks to all for the advice! It appears that Cowski is correct and as I am not compiling the code, I cannot use modeless forms.

I have rearranged my code to dispose of the form and then recreate it after the interaction with NX is complete.

Jeff

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor