Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal to reset all of the Names in an assembly to the Part number. 1

Status
Not open for further replies.

SDETERS

Agricultural
May 1, 2008
1,276
We have an assembly, that has a lot of components in it, when I highlight any of the many components in this assembly, the status bar shows a different part number than what the actual part number is. See the thread below. This is do to how our process works and how we rename stuff... We also use teamcenter which we should not be renaming in teamcenter but we do. We are trying to get away from this practice.

Is there a program floating around that would reset all of these "name" values to the appropriate part number? Instead of going through each part manually?

Thanks for any help.

 
Replies continue below

Recommended for you

The Save As method in the attached thread is the best way I've found to keep things in sync.

But we always perform a save as on every part in the assembly, assigning a part number as the file name.
It's done at the end of the design phase, prior to publishing Bom's or drafting anything.






Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures

NX1851, Win 10 Pro
 
Is the saveas done to a new revision, or a new item? Thanks for the feedback.
 
If you give a component a custom name, it will keep the name even after doing a "save-as" on the component part file. If you delete the component name, it will revert to the part name (and will update to the new part name after doing a save-as). At least this is how it works in older versions of NX; I have not tested in the latest version.

www.nxjournaling.com
 
Thanks for the feedback, when I try to delete the name, I get a message saying The Object Name Cannot be deleted. There is an X beside this field but it seems like it does nothing and greyed out. It mentions in the tool tip that it will delete names. We are running 1899 version 1919 revision. Or how ever that numbering revision version is now working. We are also running under teamcenter.
 
I have the 1911 version installed for testing (not connected to TC). When I try to delete the component name, I get the same message. I think this is just telling us that the component name cannot be blank; when you press OK on the message, the component name will revert to the component file name. The previous custom name will be cleared (but the name will not be empty), and if you do a save-as on the component file, the component name will update to the new file name.

I'm currently downloading the 1919 version for testing.

nx_rename_component_zjuq2c.png


www.nxjournaling.com
 
Thanks my system never reverts, it goes back to the old name that I had in the assembly. It seems like it is stuck with that name until we rename manually here. Once again appreciate your feedback.
Annotation_2020-09-01_130859_sebyez.png
 
I will check these out, thanks for the help and links!
 
Hi
If the issue is not solved you may try below C# journal.
I am new to Journaling. I just tried to rename each component of an assembly to "DB_PART_NO" (Teamcenter Item ID).
Below journal is renaming the top level components but it is not working for lower levels. Somebody can suggest/correct this.





using System;
using NXOpen;
using NXOpenUI;
using NXOpen.Assemblies;

public class CompNames
{
public static Session theSession = Session.GetSession();
public static UI theUi = UI.GetUI();
public static ListingWindow lw = theSession.ListingWindow;


public static void Main(string[] args)
{

Part workPart = theSession.Parts.Work;
Part displayPart = theSession.Parts.Display;
NXMessageBox msg = theUi.NXMessageBox;
try
{

//lw.Open();
if (workPart.ComponentAssembly.RootComponent != null)
{

Component wcmpp = workPart.ComponentAssembly.RootComponent;

AssyRun(workPart.ComponentAssembly.RootComponent);

}

else
{
msg.Show("Information", NXMessageBox.DialogType.Information, "Part is not having structure");
}


}
catch (NXOpen.NXException ex)
{
//theUi.NXMessageBox.Show("Cathced", NXMessageBox.DialogType.Information, ex.ToString());


}

}


public static void AssyRun(Component a)
{
BasePart temp = a.Prototype.OwningPart;

Component[] a1 = temp.ComponentAssembly.RootComponent.GetChildren();


foreach (Component a2 in a1)
{

rname(a2);


if (a2.Prototype.OwningPart.ComponentAssembly.RootComponent != null)
{

AssyRun(a2);

}

}

}

public static void rname(Component c1)
{
NXObject[] objct = new NXObject[1];
objct[0]= c1;
string nm = c1.GetStringUserAttribute("DB_PART_NO", -1);
ObjectGeneralPropertiesBuilder obj1 = theSession.Parts.Work.PropertiesManager.CreateObjectGeneralPropertiesBuilder(objct);
SelectNXObjectList selct = obj1.SelectedObjects;
obj1.Name = nm;
obj1.NameLocationSpecified = false;
obj1.Index = 1;
//obj1.AddComponents = true;
//obj1.ApplyToComponent = true;
NXObject objct1 = obj1.Commit();
//lw.WriteFullline("RENAMED : " + c1.Prototype.OwningPart.Leaf + " to " + obj1.Name);
selct.Clear();
obj1.Destroy();
}

public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }
}

 
try this:

Code:
'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012
 
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    
	
    Sub Main()
	
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display

 
    lw.Open
	
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
			ReportComponentChildren2(c.RootComponent, 0)
			
        else

            lw.WriteLine("Part has no components")

        end if
		
    Catch e As Exception
	
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
		
    End Try
	
		lw.Close
 
    End Sub
 
'*****************************************************************************************
' Empty run
'*****************************************************************************************
Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
	Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display

    For Each child As Component In comp.GetChildren()
	
	Dim MyPart As Part = child.Prototype.OwningPart

	Try

		if child.IsSuppressed = true then

			lw.writeline("   Error: " & child.DisplayName & ".prt" & " -> " & "File closed")
			Continue for
			
		end if
		
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

	end try



        If LoadComponent(child) Then

		    		        

            Else

                'component could not be loaded

            End If

            reportComponentChildren(child, indent+1)
       
     
        Next

    End Sub
	
'*****************************************************************************************
' Changing file name 
'*****************************************************************************************

Sub reportComponentChildren2( ByVal comp As Component, ByVal indent As Integer)

	Dim workPart As Part = theSession.Parts.Work
   	Dim dispPart As Part = theSession.Parts.Display
	
	For Each child As Component In comp.GetChildren()

	Dim MyPart As Part = child.Prototype.OwningPart 

	Try

		if child.IsSuppressed = true then

			lw.writeline("Error: " & child.DisplayName & ".prt" & "   " & "File closed")
			exit sub
			
		end if
		
			Catch e1 As Exception
			
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try



 	If LoadComponent(child) Then
	
		Dim File_name as string	
		Dim TextLength as Integer
		File_name = child.DisplayName()
	    TextLength = File_name.Length

 		'lw.writeline(File_name)		
		lw.writeline("component name: " & child.Name & "-> " & File_name )
		child.SetName(File_name)
		lw.writeline("new component name: " & child.Name)
		'lw.writeline("ref set name: " & child.referenceset)
		'lw.writeline("component part name: " & child.Prototype.OwningPart.fullpath)
		lw.writeline("")

	Else
	
		'component could not be loaded
				
	End If 	

            reportComponentChildren2(child, indent + 1)
			
        Next
		
    End Sub
	
'**********************************************************
' Function loading components
'**********************************************************

 Private Function LoadComponent(ByVal theComponent As Component) As Boolean
 
        Dim thePart As Part = theComponent.Prototype.OwningPart
 
        Dim partName As String = ""
        Dim refsetName As String = ""
        Dim instanceName As String = ""
        Dim origin(2) As Double
        Dim csysMatrix(8) As Double
        Dim transform(3, 3) As Double
 
        Try
            If thePart.IsFullyLoaded Then
                'component is fully loaded
				
            Else
			
                'component is partially loaded
				
            End If
			
            Return True
			
			Catch ex As NullReferenceException
            'component is not loaded
			
            Try
			
                ufs.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)
 
                Dim theLoadStatus As PartLoadStatus
                theSession.Parts.Open(partName, theLoadStatus)
 
                If theLoadStatus.NumberUnloadedParts > 0 Then
 
                    Dim allReadOnly As Boolean = True
                    For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1
                        If theLoadStatus.GetStatus(i) = 641058 Then
                            'read-only warning, file loaded ok
                        Else
                            '641044: file not found
                            lw.WriteLine("File not found")
                            allReadOnly = False
                        End If

                    Next

                    If allReadOnly Then
                        Return True
                    Else
                        'warnings other than read-only...
                        Return False
                    End If
                Else
                    Return True
                End If
 
				Catch ex2 As NXException
			
				if ex2.message = "File not found" then 
				
	                lw.WriteLine("Error: " & partname & "   " & "File not found")		
					
				else
				
	                lw.WriteLine("Error: " & partname & "   " & ex2.Message)
					
				end if
				
                Return False
				
            End Try
			
        Catch ex As NXException
		
            'unexpected error
            lw.WriteLine("error: " & ex.Message)
            Return False
			
        End Try
 
    End Function

'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************
 
End Module

With best regards
Michael
 
EDIT::

Thanks again

I see what is doing now.

I see why the list says what it does.

Shane
 
Probably You have some part closed and not present on drive?

With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor