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!

Switch Part tool 4

Status
Not open for further replies.

CNSZU

Mechanical
Sep 2, 2005
318
Hello all,

Switching between parts can be cumbersome and confusing with the Window menu, especially when many parts are open. Here is an alternative solution. See the attached image for a preview.

ADVANTAGES:
- the tool can be placed on a toolbar or used with mouse gestures for quick access (icon is included)
- organizes the parts into a hierarchy for better overview
- provides an image preview by moving the mouse over the parts listing

HOW TO INSTALL:
download the attached "NXSwitchPart_1_0.rar" and extract
place the dll and bmp file anywhere convenient
in NX: Customize ...> New User Command. With the new button, set Default style. Edit Action: Type: NXOpen, browse to the dll file.
Change button image > image name. browse to the bmp file.

Let me know if there are any issues.

NOTE: This tool does not alter any parts. Not tested with Teamcenter.

PREVIEW IMAGE:
DLL & ICON:
NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
Hello CNSZU.

Don't get me wrong, I very much appreciate the fact that you freely provide us with such a tool but....

What would be the benefit of this against the functionalities of the Assembly navigator?
I can see some benefit when you have a lot of parts open which are not in an assembly, but then again that's why there is the history navigator.



Ronald van den Broek
Mechanical Engineer
Cad Environment Coordinator
Wärtsilä, Propulsion Services
NX8.5.2 / TC9.1.2
HPZ420 Intel(R) Xeon(R) CPU E5-1620 0 @ 3.60GHz, 32 Gb Win7 64B
Nvidea Quadro4000 2048MB DDR5

 
It depends on how you use NX. As for the Assembly Navigator, it's fine if you keep the displayed part at the top level and only change the work part. That way, all the parts will be visible at all times in the navigator. The problem arises when you have several separate assemblies open and want to switch between them or when you change the displayed part. As for the History Navigator, it only displays a history of parts that have been opened, not the parts that are open in the current session. So, in a way, this tool fills a "gap" in the functionality in NX (actually, the Window menu takes care of this, but the tool improves on it).

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
I do not have NXOpen as an option in the button action list, I only have

Journal File
User Function
System Commands
User Tools
Macros
Grip
KF Function

????

Cheers

Si

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
A solution for those who don't have "NXOpen" in the list for button action type is as follows. Create a blank journal file and insert the code below:

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports System.IO

Module NXJournal

    Sub Main(ByVal args() As String)

        Dim s As Session = Session.GetSession()
        Dim lw As ListingWindow = s.ListingWindow


'REPLACE THIS PATH WITH THE LOCATION OF THE DLL FILE:
'--------------------------------------------------------
	   Dim fullpath As String = "C:\NXSwitchPart.dll"
'--------------------------------------------------------


        If File.Exists(fullpath) Then

            Dim inObject() As Object = {}
            s.Execute(fullpath, "cNXSwitchPart", "Main", inObject)

        Else

            lw.Open()
            lw.WriteLine("Can't find " & fullpath)

        End If
      
    End Sub

End Module

Be sure to insert the correct dll file path in the journal file. Or, download the journal file in this post (but you must still edit the dll file path). Now, you can choose "Journal" in the button action type and select the journal file. A disadvantage with this method is a slightly longer delay in the execution of the program.

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
 http://files.engineering.com/getfile.aspx?folder=a2c853b8-95c3-49c1-b3e4-4f86430fb96a&file=NXSwitchPart.vb
I'm running the journal, but it is saying there is an error in line 23 here is the code
Module NXJournal

Sub Main(ByVal args() As String)

Dim s As Session = Session.GetSession()
Dim lw As ListingWindow = s.ListingWindow


'REPLACE THIS PATH WITH THE LOCATION OF THE DLL FILE:
'--------------------------------------------------------
Dim fullpath As String = "H:\NXSwitchPart.dll"
'--------------------------------------------------------


If File.Exists(fullpath) Then

Dim inObject() As Object = {}
s.Execute(fullpath, "cNXSwitchPart", "Main", inObject)

Else

lw.Open()
lw.WriteLine("Can't find " & fullpath)

End If

End Sub

End Module

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
The code you pasted has some imports missing at the top. Can you confirm that line 23 is (click the button that says "goto line" in journal editor)

s.Execute(fullpath, "cNXSwitchPart", "Main", inObject)

What is the whole error message?


NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
This is strange, I'm not able to reproduce the error.

The only things I can think of is to make sure that the journal file has the extension .vb and that it is a vb file that you open with the button action type set to journal. This method has been tested successfully with NX 8.5 native with Windows 7 SP1 64 bit and with installed Microsoft .NET framework 4.5. Perhaps try installing this framework if you don't have it already (listed under installed programs). Otherwise, perhaps fact that you don't have the option NXopen in the button action type is related to this issue and that it prevents you from executing dll files.

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
Hi Cowski

I don't have the NX open function on menu, but I can instigate it from the command finder when I run the dll file that CNSZU has kindly provided, it returns an error which reads

------------------------------------------------

Failed to load image - see log file for details

Fail name: C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll

Function name: ufusr

---------------------------------------------

This is what is in the syslog.

&MACRO DYN_POP_BUTTON 2 ! Start
&MACRO MENU, 0, UG_FILE_RUN_UFUN UG_GATEWAY_MAIN_MENUBAR ! <CommandFinder>
&MACRO FILE_BOX -3, 0 ! Execute User Function
&MACRO MENU, 0, UG_FILE_RUN_UFUN UG_GATEWAY_MAIN_MENUBAR ! <CommandFinder>
&MACRO FILE_BOX -2, C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\*.DLL 0 ! Execute User Function
Using C:\Program Files\UGS\NX 7.5\ugii\managed\ManagedLoader.dll to load managed DLL
Trying to load C:\Program Files\UGS\NX 7.5\ugii\managed\ManagedLoader.dll
ManagedLoader.Load: C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll Name:NXSwitchPart.dll
There are no context policies.

AppBase: C:\Users\simon.wright\Desktop\NXSwitchPart_1_0System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at ManagedLoader.Load(String assemblyName)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


The reason C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll failed to load was:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at ManagedLoader.Load(String assemblyName)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance pe
&MACRO FOCUS CHANGE OUT 1
&MACRO FOCUS CHANGE OUT 1
&MACRO FOCUS CHANGE IN 1
&MACRO MESSAGE_BOX -2 Failed to load image - see log file for details
&MACRO MESSAGE_TEXT
&MACRO MESSAGE_TEXT File name: C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.dll
&MACRO MESSAGE_TEXT
&MACRO MESSAGE_TEXT Function name: ufusr
&MACRO MESSAGE_TEXT
&MACRO MENU, 0, UG_HELP_SYSTEM_LOG UG_GATEWAY_MAIN_MENUBAR ! <MB/Toolbar>

CHeers Si

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
Hi Simon, in your syslog it says "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded." I suspect this means that you have on your computer a .NET framework version lower than 4.5 which causes the dll to fail to load. One solution is to download and install the 4.5 .NET framework from Microsoft. Another solution, if you have .NET framework 4.0 on your computer, to download the "NXSwitchPart.dll" file in this post which has been modified to run on the 4.0 framework. If that fails, the reason might be that you are running NX 7.5, while this tool is compiled with NX Open 8.5.



NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
 http://files.engineering.com/getfile.aspx?folder=20730512-43db-4c7b-8195-08300c60e9c0&file=NXSwitchPart.dll
@CNSZU,
thank you for this program, something should offer OOTB
the problem is taken from the syslog:
Resolve failed: NXOpen.Utilities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
Loaded: : NXOpen.Utilities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
Verifying C:\Downloads\NXSwitchPart.dll for NXOpen signature.
NXOpen.Utilities.MissingResourceException: Assembly has not been compiled with an NX resource bundle
bei NXOpen.Utilities.ResourceUtilities..ctor(Byte[] assemblyData)
bei NXOpen.Utilities.BaseSession.verifyAssembly(String filename, Boolean& alliance_mode, SignatureType signTypeNeeded)
Validation failed

this dll has no signature - the sign resource are also not included.
It will only run with license offer an ufunc_runtime. Newer NX Licenses don't have this option. Was a change between Nx3/4 +5.
The developer must include the signing resource into the source code and use nx_sign from the ugii folder to sign the dll after compilation.
- as developer you need a dotnet author license from siemens.
Or you would be so kind to offer the code as journal.
regards
uwam2ie
 
Thanks for trying, I still can't get to to run, the last journal you posted was as close as I got, but it errored at line 183 or something.

It's shame as this would be really usefull for us as our parts only display as part numbers in the window list so it's impossible to know what is what when we have many parts loaded.

Thanks for your effort anyway, much appreciated.

Si

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
Simon, could you give the exact error message or an image of the error?

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
Hi

The error that appears reads (and it was line 185 not 183):-

Line 185: Expression expected.
Line 185: Name 'y' is not declared.
Line 185: End of statement expected.

Here is the end of my syslog.

!!!&MACRO CUSTOM 25 CATEGORIES * TL_SELECT * (1) * 0 * 0 ! Selection Bar
!!!&MACRO CUSTOM 25 CATEGORIES * TL_SELECT * (45) * 0 * 1 ! New Button
!!!&MACRO FILE_BOX -2, C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\open_component.bmp C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\*.bmp 0 ! Open Image File
!!!&MACRO FOCUS CHANGE IN 1
!!!&MACRO FILE_BOX -2, C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.vb C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\*.VB 0 ! Open Action File
!!!&MACRO FOCUS CHANGE IN 1
!!!&MACRO EVENT ACTIVATE -50 0, 53, 1, 0, 0! Close
!!!&MACRO ASK_ITEM 53 (1 BLO 0) = 1 ! Close
!!!&MACRO DIALOG_END -3, -1 ! Customize: CANCEL
!!!&MACRO ASK_ITEM 0 (1 BTAB 0) = 8 !
!!!&MACRO ASK_ITEM 3 (1 BLO 0) = 0 ! New...
!!!&MACRO ASK_ITEM 4 (0 BOOL 0) = 0 ! Text Below Icon
!!!&MACRO ASK_ITEM 17 (1 BOOL 0) = 1 ! Always Show Full Menus
!!!&MACRO ASK_ITEM 18 (0 BOOL 0) = 1 ! Show Full Menus After a Short Delay
!!!&MACRO ASK_ITEM 22 (1 BOOL 0) = 1 ! Show ScreenMessages on Menus and Toolbars
!!!&MACRO ASK_ITEM 24 (0 BOOL 0) = 1 ! Show ScreenTips
!!!&MACRO ASK_ITEM 25 (1 BOOL 0) = 1 ! Show Shortcut Keys
!!!&MACRO ASK_ITEM 28 (1 RADI 0) = 1 ! Small (24)
!!!&MACRO ASK_ITEM 29 (1 RADI 0) = 0 ! Extra Small (16)
!!!&MACRO ASK_ITEM 30 (1 BOOL 0) = 0 ! Show Single Toolbar in Toolbar Options
!!!&MACRO ASK_ITEM 38 (1 RADI 0) = 0 ! ##01Top
!!!&MACRO ASK_ITEM 39 (1 RADI 0) = 0 ! Horizontal
!!!&MACRO ASK_ITEM 40 (1 RADI 0) = 0 ! ##01Top
!!!&MACRO ASK_ITEM 41 (1 BOOL 0) = 1 ! Show Selection MiniBar
!!!&MACRO ASK_ITEM 0 (1 BTAB 0) = 8 !
!!!&MACRO ASK_ITEM 53 (1 BLO 0) = 1 ! Close
!!!&MACRO FOCUS CHANGE IN 1
Using C:\Program Files\UGS\NX 7.5\ugii\managed\ManagedLoader.dll to load managed DLL
Trying to load C:\Program Files\UGS\NX 7.5\ugii\managed\ManagedLoader.dll
ManagedLoader.Load: C:\Program Files\UGS\NX 7.5\ugii\managed\NXOpen.Utilities.dll Name:ctx://Journal5fbc9459
There are no context policies.

AppBase: C:\Program Files\UGS\NX 7.5\ugii\managedLoaded assembly: NXOpen.Utilities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null from C:\Users\simon.wright\AppData\Local\assembly\dl3\D7EM5Z0G.OER\692853JK.VY0\0bd04c7c\00311fc4_9b0ecc01\NXOpen.Utilities.DLL
Loaded assembly: System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 from C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll
Loaded assembly: System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a from C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll
Adding C:\Program Files\UGS\NX 7.5\ugii\managed\\NXOpen.Utilities.dll as a reference item
Adding C:\Program Files\UGS\NX 7.5\ugii\managed\\NXOpen.dll as a reference item
Adding C:\Program Files\UGS\NX 7.5\ugii\managed\\NXOpen.UF.dll as a reference item
Adding C:\Program Files\UGS\NX 7.5\ugii\managed\\NXOpenUI.dll as a reference item


Journal execution results for C:\Users\simon.wright\Desktop\NXSwitchPart_1_0\NXSwitchPart.vb...
Syntax errors:
Line 185: Expression expected.
Line 185: Name 'y' is not declared.
Line 185: End of statement expected.

&MACRO FOCUS CHANGE OUT 1
&MACRO FOCUS CHANGE OUT 1
&MACRO FOCUS CHANGE IN 1
&MACRO MESSAGE_BOX -2 Line 185: Expression expected.
&MACRO MESSAGE_TEXT Line 185: Name 'y' is not declared.
&MACRO MESSAGE_TEXT Line 185: End of statement expected.
&MACRO MESSAGE_TEXT
&MACRO CUSTOM 24 XFORM_SEQUENCE 0 0.670759 0.740193 -0.046867 -0.296769 0.325769 0.897665 0.679713 -0.588209 0.438179 -1572.68 -43.5643 1836.97 0.10173 !
&MACRO MENU, 0, UG_HELP_SYSTEM_LOG UG_GATEWAY_MAIN_MENUBAR ! <MB/Toolbar>

Many thanks

Si

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
I think you get that error because the code on that line only works with .NET framework 4.5. I'm using visual studio and target the framework to 4.0, but still this code slips through, I don't know why. What is the .NET framework on your computer? I strongly urge you to update to the latest version from the microsoft website. Otherwise you might get more errors. If not, simply in the journal file add a " ' " to comment out the lines 183, 185 and 187 (the same way 182 is commented out). However this will prevent alphabetical ordering of the part list.

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
OK, so progress!

I have commented out those lines and the journal will now run and open the switch part window and display the list!

However, I'm not getting any component preview in the little window when I move my cursor over a part. This is the same in TC and native NX.

Any ideas?

Cheers

Si

Best regards

Simon NX 7.5.4.4 MP8 and NX 8.5 (native) - TC 8
 
Congratulations! The reason you're not getting the previews could be that the parts themselves don't have any preview images saved with them. Check the History navigator or the File open dialog, the preview images you see there should be the same as you see in the Switch Part tool. If they are the same then the tool is working correctly.

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor