Extending Unigraphics NX using C# (I) Manual approach

27 Jan

  • Create a library project in C#;
  • Add a class with 2 methods like below:
  class TestAtt
        public static void Main()
            Session theSession = Session.GetSession();
            theSession.ListingWindow.WriteLine("Running the Sample Application");

        public static int UnloadLibrary()
            return (int)Session.LibraryUnloadOption.Explicitly;


  • Add reference dll in UGDir\UGII\managed\ to the project
  • Add “using NXOpen; using NXOpen.UF;” in the class file
  • Add the NXSigningResource.res to the project, configure the Build Action as “Embedded Resource”


  • In the post-build event, type “SignLibrary -verify $(TargetPath)” to sign the dll.


Note that the last 2 steps are not necessary if you only run the extension plugin/addin on your local computer, however they are required if you want to run on other computers. For more details, refer to NX Open Programmer’s Guide  at UGDir/UGDOC/html_files/nxopen_prog_guide/index.html

  • Compile and build, a dll will be generated.
  • Open UGNx, press Ctrl +U, browse to the folder where the DLL resides, click the DLL, and the DLL will be loaded.

That is it. Happy coding!


Posted by on January 27, 2010 in CAD, Dotnet/C#


2 responses to “Extending Unigraphics NX using C# (I) Manual approach

  1. xinyustudio

    October 27, 2010 at 12:42 pm

    After loading the assembly into UGNX, if you get some error, such as “Failed to load image- see log for details”, you should open the log file by “Help->NX Log file”, then hover around the tail of the file, you will see some detailed information such as

  2. “System.BadImageFormatException: Could not load file or assembly ‘file:///X:\ ….”, this is mostly due to different build platform such as x86, x64 issues, change in Visual Studio accordingly to address this.
  3. “This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.”, this is possibly because you are using a higher version of DotNet framework, for instance 4.0 to compile the project, while the UG Open assembly was built using an earlier version, e.g. 2.0
  4. Also check if your main method signature is correct or not;
  5. Check if you class if public

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: