How to compile dll

Hello all,

I want to make a custom shortcut to run my journal in NX7.5, please guide me how to go through compilation of dll and running it from UG. I want to share this dll with other systems through means of local server, so that the custom shortcut can be used in all other systems too. Any help is appreciated, thanks in advance.

Do you have an Author license for NX? If not, don't bother trying to compile your code. You need to "sign" the code you compile (using the Author license) or else NX won't execute the compiled code.

Ok, so let's assume you have an author license and are using MS Visual Studio. The basic steps to compile your code are as follows:

  • add the NX resource file to your project
  • compile your code
  • sign your code with the NX utility

The resource file can be found at: [NX install directory]\UGOPEN\NXSigningResource.res
Add the resource file by opening the solution explorer, double click on "My Project", open the "Resources" tab, click "Add Resource" -> "Add Existing File" and navigate to the resource file mentioned above.

Set your compile options as desired and "Build" your code.

Finally, sign your code with the provided utility found at: [NX install directory]\UGII\SignLibrary. At a command line run: "SignLibrary myApplication.dll". There is also a "-verify" switch you can use to ensure your code (or other code) has been properly signed.

All that is left to do is distribute your application and wait for the bug reports and feature requests to roll in!

A more thorough explanation can be found in the NX help file at: NXOpen programmer's guide -> License checking.

I cannot compile my code. I'm following your directions, but when I try to compile, I got next error:

"A project with an Output Type of Class Library cannot be started directly.

In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project."

I'm pretty novice with VB... Any idea of what's going on?

Aaron Elliott over at PLM World has a good write up on how to attach the ugraf.exe so that you can use the debugger with your project.
http://www.plmworld.org/p/fo/st/thread=1987

Currently I'm not a member of PLM world, so I haven't had the chance to take a look in that thread that you posted. I requested for an account, but I haven't got response yet... Anyway, I did some research about attaching processes in VB, and the problem is that I'm using the express edition, and seems that it doesn't have that specific command. I have some code that works fine from a journal in NX, I'm just trying to compile it to dll; my question here is:

Is debuging the code in this way (by attaching the process and adding breakpoints) strictly necessary to get the signed dll or exe file?? Is there a workaround for express editions?... I'm sorry if there's an obvious answer, but I have virtually no experience with VB, this is my first approach hehe...

Thanks in advance!

Nevermind! I found a workaround, It can be done adding some code to the csproj.user file, and apparently I'm able to sign my file by using the SignLibrary from the Command Prompt. Now the only problem is that anyway I'm not able to execute the dll in NX by File > Execute > NX open ... it throws an error about failing to load the image.

Where are you storing your .dll file? Try saving it in your NX startup folder. Look in your environment variables for the "UGII_SITE_DIR". Within this folder path there should be a folder named "starup" that contains your site customizations.

Hello Dafralo,

Could you please tell me where you found the csproj.user file (it's not in my VB project folder) and how you edited it please? I am also using Visual Studio Express.

Thanks,
Kai

It seems that I don't have set up an environment variable "UGII_SITE_DIR". I tried to run it from C:\splm\nx75\UGOPEN\Release\file.dll, but it doesn't work either. On the log file of NX it says something like:

System.BadImageFormatException: Could not load file or assembly 'file:///C:\splm\nx75\UGOPEN\Release\[!output PROJECT_NAME].dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

My environment is:
-Windows XP Professional x64 Edition SP2;
-Visual Studio Express 2010
-Microsoft .NET Framework 4
-NX 7.5.3.3

I'm guessing that maybe it has something to do with the .NET Framework 4... what do you think?

For testing, try putting it in your UGII folder.

Same result running them from UGII folder...

I'd suggest contacting GTAC; they are better equipped to track down these issues.

Ok, I'll do it, thanks!

If you wouldn't mind reporting what you find out, it would be greatly appreciated... I am stuck with the same issue.

DHuskic
Nx 9 VB

Just had another thought...
Did you sign the .dll after you compiled it?

Yes, I signed it by using the SignLibrary in a command prompt and it shows the message "Signed assembly file"... Also I added the NXSignResource as embedded item...

DHuskic: Sure, if I get a solution I'll post it...

DHuskic, I found what was my problem:

I was compiling using .NET framework 4.0 as Target framework. After navigating on some VB.net forums I found out that according to the error that I got in the NX Log File, I needed to change my Target Framework to .NET framework 3.5. And that's it! just like that my application runs perfectly in NX. Also I was succesfull signing it and it runs in NX unlicensed for .NET author.

I hope this helps!.
Regards!

Hi
Before I start editing, does anyone have a journal that exports a selected drawing sheet to dxf? The current journal on this site exports all sheets.
Thanks
Martyn

Hello,
I compiled and signed on NX8.0 and it works fine.
But it does not work on another computer with update NX8.0.3.4.
I tried to re-sign on the computer with NX8.0.3.4 but it still doesnt work.
Do I have to re-compile with resource file and ...\UGII\managed\NXOpen.dll from NX8.0.3.4 install ?
Thanks

---------------------------LOG FILE ---------------------------
&MACRO MESSAGE_BOX -2 Error in external library. See system log for details
&MACRO MESSAGE_TEXT
&MACRO MESSAGE_TEXT File name: C:\Users\cdaristotile\Desktop\carlo\SplineSegment-LENGTH-2014-06-10-version-006-NX8.0-local-sign.dll
&MACRO MESSAGE_TEXT
&MACRO MESSAGE_TEXT Function name: ufusr
&MACRO MESSAGE_TEXT
&MACRO MENU, 0, UG_HELP_SYSTEM_LOG UG_GATEWAY_MAIN_MENUBAR !
Successfully loaded dynamic module C:\eng_apps\ugnx80\UGII\libhelpint.dll
Loaded module C:\eng_apps\ugnx80\UGII\libflat.dll 7fed3120000 75000 1051e24c-4ecae087-643ae794-9a26700a-1=libflat___137353587264 version = 8.0.3.4
Loaded module C:\eng_apps\ugnx80\UGII\libsmdint.dll 7fecf580000 1e3000 f5b466af-433db960-51d22786-435d8d4f-1=libsmdint___137353202464 version = 8.0.3.4
Loaded module C:\eng_apps\ugnx80\UGII\libhelpint.dll 7fed02b0000 124000 f5a5303d-4efc36fb-3b4b8fb8-7ed331bd-1=libhelpint___137584237964 version = 8.0.3.4

Carlo Tony Daristotile

I suggest trying to compile with the updated .dll files. It is possible that you might need to tweak your source code due to changes in the API, though I doubt there were any changes that significant between NX 8 and 8.0.3.4.

If recompiling doesn't fix it, you should contact GTAC so that they can diagnose what is happening.

does not compile vb_journal in dll..=(
I have the working journal file
I have NX 10
I have MVS Express 2012

So, what i did:
1. File->new project->class library or windows forms..or console application.. i tested them all
2. step ONE add the NX resource file to your project (NXSigningResource.res)
3. Add the existing component (my journal file) in solution browser
4. Building solution

and i have many and many mistakes in mistakes list...

What is a general mistake in my steps?

http://cccp3d.ru/uploads/monthly_03_2016/post-26187-0-13952600-145928018...
Add this, and ok
UGII\managed\

NXOpen.dll NXOpen.UF.dll NXOpen.Utilities.dll NXOpenUI.dll