Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Programming Pure VB 2012 with forms and dialog boxes together with NX 7.5 1

Status
Not open for further replies.

NXProf

Mechanical
Nov 28, 2012
45
Hello all,

Can anyone please help me? I am working with NX 7.5 - mostly the drafting side as well as some modeling. And I just had the full Visual Studio with Visual Basic (VB) 2012 loaded.

I've been able to generate simple VB code to run inside of NX 7.5. But I would like to write code as well as developing forms with buttons, scroll bars, etc. that allows the user to have multiple options to run the programs.

Subsequently, can you please provide me with sample code(s) including how to set the entire code to speak to NX and/or direct me to websites containing examples of the full VB package with example codes containing connections to NX?

Thank you very much for your response(s) ahead of time!
 
Replies continue below

Recommended for you

In the NX help, Automation -> programmer's guide, there is a section called "wizard setup" that explains how to make VS aware of NX. It is fairly simple, involving copying a few files from the NX folders to the VS template folders. I don't think VS 2012 was out when NX7.5 released, you may have to tweak the instructions a bit to get your setup to work (folder locations may be different).

www.nxjournaling.com
 
Thank you very much cowski for responding to my post.

Currently, the following softwares and installations are on my machine:
Teamcenter (TC) -> NX7.5 – not loaded on individual machines, but running off of a server
Native NX7.5 (rarely used, less than 0.1%) – also not loaded on individual machines, but running off of a server
Visual Studio 2012 – installed last week directly on my machine

I located both the “NX Open Visual Basic (VB) Wizard” and the “Visual Studio (VS) Application Wizard Setup,” in which I copied the directions in the attached file (NX Open VB & VS App Wizards.docx). Which wizard should I run first once I locate them?

From the NX Open Visual Basic (VB) Wizard, it reads “You can start Visual Studio by typing ‘devenv.exe’ from an NX command prompt window.” Do you know where the “NX command prompt window” is located? I’ve searched all over NX as well as going through numerous Help files and still cannot find it.
Also, as indicated in this same directions file (NX Open Visual Basic (VB) Wizard) under the “Using the NX Open VB wizard” section, Step 1 says “Select the File→New→Project menu item to activate the New dialog box.” I found this to be within VS according to directions from another web page ( But I’m having difficulties getting to Step 2 – “Under Project Types, expand Other languages and select Visual Basic.” Is this because NX 7.5 is not loaded directly on my machine, but instead is running off a server and running through TC?

Within the “Visual Studio Application Wizard Setup,” how can you determine if the “appropriate version Microsoft Visual Studio has been installed”? Also, with my license of TC→NX7.5 running off a server, should the “%UGII_BASE_DIR%\UGOPEN\vs_files\VB\VBWizards\” and “%UGII_BASE_DIR%\UGOPEN\vs_files\VB\vbprojects\” folders have the same folder structure as licenses loaded in individual machines? (I only ask this because our Helpdesk IT support staff will want to know once I put in a Helpdesk ticket).

Thank you again for your help, which I greatly appreciate!

NXProf
 
NXProf said:
From the NX Open Visual Basic (VB) Wizard, it reads “You can start Visual Studio by typing ‘devenv.exe’ from an NX command prompt window.” Do you know where the “NX command prompt window” is located?

The NX command prompt window can be started from Start -> NX 7.5 -> NX Tools -> Command Prompt.
But I never start VS this way. Once the wizards are setup you can just start VS the normal way, start a new project and select the NX template.


NXProf said:
Also, with my license of TC→NX7.5 running off a server, should the “%UGII_BASE_DIR%\UGOPEN\vs_files\VB\VBWizards\” and “%UGII_BASE_DIR%\UGOPEN\vs_files\VB\vbprojects\” folders have the same folder structure as licenses loaded in individual machines?

I imagine the folder structure will be the same, but you will have to look on the server to find the %UGII_BASE_DIR%.

www.nxjournaling.com
 
Hello cowski,

I have been able to do the following 4 steps with no issues:
1) Copied all NX files/folders from the network drive … \vs_files\VB\VBWizardsto D:\Microsoft Visual Studio 11.0\VB\VBWizardsand copied all NX files/folders from the network drive
…\vs_files\VB\VBprojectsto D:\Microsoft Visual Studio 11.0\VB\VBprojects
2) Within the D:\Microsoft Visual Studio 11.0\VB\VBprojects\NX7_VB.vsz file, I changed the 2nd line from “Wizard=VsWizard.VsWizardEngine.9.0” to “…VsWizardEngine.11.0” since my VS version is 11.0.

3) I found the NX command prompt via Start -> All Programs -> Technical Applications -> Teamcenter -> NX command prompt and changed the current folder as D:\Microsoft Visual Studio 11.0\Common7\IDE\, then typed devenv.exe, which started Visual Studio 2012, but appeared to be a normal startup session without establishing any Wizard settings. But I can’t tell.

4) I followed the directions to “Creating a Visual Basic project using the NX Open VB wizard” up to the point where is says “Step 1 Select the File→New→Project menu item to activate the New dialog box.”
When I get to VS, the actual starting of a project is File→NewProject (and not File→New→Project), which I start. Then when expanding the “Installed” tree for a New Project to go to Step 2 “Under Project Types, expand Other languages and select Visual Basic,” Visual Basic is listed under the Templates tree limb, but not under Other Languages. (Please see attached, which shows all expanded). Then Step 3 says “Select NX#_VB from the list of Templates (where # is the NX version).”

But at this point, I do not see “NX#_VB from the list of Templates.” Is there something I might be missing to properly get the NX Open VB wizard started?

Thank you again for your help!
 
 http://files.engineering.com/getfile.aspx?folder=eacdea50-ccbe-4170-8b56-5e8fb62a3a7d&file=VisualStudio-NewProject.jpg
I recently downloaded the VS2012 version to try it out. I could not get the wizards to work with it. I suggest downloading the VS2010 version, I know you can get the wizards to work with that version.

www.nxjournaling.com
 
Thank you cowski!

I'll see if I can get VS2010. Do you know what version of NX works with VS2010? Currently I'm running NX 7.5.

Thank you again for your outstanding help!
 
I should also note that the 2012 version would also work if you add the references yourself. I wasn't able to get the NX code wizard to work with 2012, but that doesn't mean you can't write journals for NX with it.

www.nxjournaling.com
 
Thank you again cowski!

I'll have to see if I can downgrade my VS from 2012 to 2010 and then see if the wizard will work. But before downgrading, I might attempt to "add the references." Do you know how I can get started?

Best regards.


 
Start a class library project, go to project -> add reference; browse to your <NX install folder>\UGII\managed and add references to NXOpen.dll, NXOpen.Utilities.dll, NXOpen.UF.dll, and NXOpenUI.dll.

Now replace the existing code in the .vb file with this:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

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

        ' TODO: Add your application code here 

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

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

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor