Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

How to automatically run a vb program at the time of opening the part

[ Edited ]

Is it possible to automatically run a VB program when the user wants to open a part or assembly?

Sina shojaee
9 REPLIES

Re: How to automatically run a vb program at the time of opening the part

Yes. It is done with so called "callback" functions.
you can have a look in your NX installation path:
%UGII_BASE_DIR%\UGOPEN\SampleNXOpenApplications\PartCallbacks

Re: How to automatically run a vb program at the time of opening the part

Use the Open Part user exit (USER_RETREIVE).

 

Documentation for User Exits can be found at:

 

https://docs.plm.automation.siemens.com/tdoc/nx/10/nx_api/#uid:index_nxopen_prog_guide:id1142076:use...

Re: How to automatically run a vb program at the time of opening the part

You can also use "MenuScript" to fire custom code when the user selects a menu item.

Re: How to automatically run a vb program at the time of opening the part

Thank you Josch
I found PartCallbacks and I read it. I set UGII_USER_DIR enviornment variable and made startup folder but I don't know how to compiling and linking that VB file and how to put my code in that folder.
Sina shojaee

Re: How to automatically run a vb program at the time of opening the part

Thank you JimB
I tried to do exactly what you mentioned but when I click Open I get an error: failed to load image. Please see log file
Sina shojaee
Solution
Solution
Accepted by topic author sina
‎10-12-2015 09:34 AM

Re: How to automatically run a vb program at the time of opening the part

 

Sina,

 

You mentioned VB - I assume that you are using NXOpen VB .Net - if not, let me know.

 

Did you build the code into a .DLL for the callback, or are you trying to launch the .VB file as the callback?  I think you will need to build the .dll.  Once you have built it, you can set the environment variable USER_RETRIEVE to point to the .DLL, using the full path and filename, wherever the .DLL is on your system.

 

I tested this with the simple code shown below, and I have verified that it works.  Note that the "ufget" function name is important.

 

Regards,

 

Steve

 


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    '  Open Part
    '      This user exit is invoked after the following menu item is activated:
    '      "File->Open"  

    'Will work when complete path of the dll is provided to Environment Variable
    'USER_RETRIEVE or USER_DEFAULT

    Function ufget(ByVal args As String()) As Integer

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim theUfSession As UFSession = UFSession.GetUFSession()

        Echo("The Open Part callback program is running.")

        Return 0

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

    Sub Echo(ByVal output As String)
        Dim theSession As Session = Session.GetSession()
        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

End Module

 

 

Re: How to automatically run a vb program at the time of opening the part

Thank you all and thank you Steve
It works well but NX runs my dll file before opening a part. I want to write a program to do something with the part which the user selects in open window
Does anybody know what should I do?
Sina shojaee

Re: How to automatically run a vb program at the time of opening the part

maybe it is easier for you to just use MenuScript and ACTIONS/PRE or ACTIONS/POST?

Re: How to automatically run a vb program at the time of opening the part

[ Edited ]

If he wants it to run after the part is open, then ACTIONS/POST is what is needed

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled