Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal to 'reset' all attributes 1

Status
Not open for further replies.

UGMENTALCASE

Aerospace
Oct 10, 2011
123
Hi there,

It's been a while since I've been on NX but back there now and trying to find ways to speed up my processes. I've been searching, but can't quite find the answer.
So sometimes we get assemblies in which we can clone and get a new tool number onto. This brings all past attributes with it.
Is there a journal or a way where you can 'reset' them all. I don't want to delete them completely, I want to keep whatever attributes are there (these come from a template files, so will all be the same) and clear all the values.

Any guidance would be great

Cheers
 
Replies continue below

Recommended for you

Is it always a known set of attributes or can it vary from file to file?

NX 12.0.1.7 Windows 10
 
Hi, thanks for the reply. It's always the same set. There is a couple like material which is locked, but the journal I have for deleting them I list which ones it picks to delete.

Cheers
 
It sounds like something similar we do from the top assembly by running a journal to set job specific attributes for the entire assembly by asking for the required information then running through the assembly and setting this attribute in all the component files. It is really a hacked up program stolen from nxjournaling.com. This is a good web site to start with, and there is an example for running through all assembly parts.

I can share the program but it is really very hacked up as I'm just learning vb having been on grip for nearly 30 years. LOL

NX 12.0.1.7 Windows 10
 
I like a bit of hacking! Ha ha, well it would need to be run on parts opened in their own window, as doing that in the assembly file, doesn't change the attributes if you opened them individually. I'll take a look on that site and see what I can find. Might be able to cobble something up, where it opens the part from the assy then does it, saves and closes, and carries on.

I'd learn it more but new info pushes old info out the grey matter at the moment!
 
This is a very early version of the journal to update attributes.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module assign_attribute_all_files

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work

        Dim myAsmInfo As New NXJ_Assembly_info
        Try
            myAsmInfo.Part = workPart
        Catch ex As NXException
            MessageBox.Show("Error: " & ex.Message & ControlChars.CrLf & "journal exiting", "Error " & ex.ErrorCode.ToString, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End Try

        '**********
        Dim attTitleMold As String = "mold_number"
		Dim attTitleWo As String = "work_order"
        '**********
        Dim attValueMold As String = ""
		Dim attValueWo As String = ""

        attValueMold = InputBox(attTitleMold & ":", "Enter Mold Number")
		attValueWo = InputBox(attTitleWo & ":", "Enter Work Order")

        workPart.SetAttribute(attTitleMold, attValueMold)
		workPart.SetAttribute(attTitleWO, attValueWo)

        For Each myPart As Part In myAsmInfo.AllUniqueParts
            myPart.SetAttribute(attTitleMold, attValueMold)
			myPart.SetAttribute(attTitleWO, attValueWo)
        Next


    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

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

    End Function

End Module






Public Class NXJ_Assembly_info

#Region "Private Variables"

    Private Const Version As String = "0.1.1"

    Private _theSession As Session = Session.GetSession()
    Private _theUfSession As UFSession = UFSession.GetUFSession

    Private _components As New List(Of Assemblies.Component)
    Private _uniqueParts As New List(Of Part)
    Private _allComponents As New List(Of Assemblies.Component)
    Private _allUniqueParts As New List(Of Part)
    Private _notLoaded As New List(Of String)

    Private lg As LogFile = _theSession.LogFile

#End Region

#Region "Properties"

    Private _isTCRunning As Boolean
    Public ReadOnly Property IsTCRunning() As Boolean
        Get
            Return _isTCRunning
        End Get
    End Property

    Private _thePart As Part = Nothing
    Public Property Part() As Part
        Get
            Return _thePart
        End Get
        Set(ByVal value As Part)
            _thePart = value
            'Me.GetInfo()
            Me.GetAllInfo()
        End Set
    End Property

    Public ReadOnly Property AllComponents() As List(Of Component)
        Get
            Return _allComponents
        End Get
    End Property

    Public ReadOnly Property AllUniqueParts() As List(Of Part)
        Get
            Return _allUniqueParts
        End Get
    End Property

    Public ReadOnly Property Components As List(Of Component)
        Get
            Return _components
        End Get
    End Property

    Public ReadOnly Property UniqueParts As List(Of Part)
        Get
            Return _uniqueParts
        End Get
    End Property

    Public ReadOnly Property NotLoaded As List(Of String)
        Get
            Return _notLoaded
        End Get
    End Property

#End Region

    Public Sub New()

        lg.WriteLine("")
        lg.WriteLine("~ NXJournaling.com: NXJ_Assembly_info object created ~")
        lg.WriteLine("  ~~ Version: " & Version & " ~~")
        lg.WriteLine("  ~~ Timestamp of run: " & DateTime.Now.ToString & " ~~")
        lg.WriteLine("NXJ_Assembly_info Sub New()")

        'determine if we are running under TC or native
        _theUfSession.UF.IsUgmanagerActive(_isTCRunning)
        lg.WriteLine("IsTcRunning: " & _isTCRunning.ToString)

        lg.WriteLine("exiting Sub New")
        lg.WriteLine("")


    End Sub

    Private Sub GetAllInfo()

        'get all component info from assembly (all levels)
        lg.WriteLine("Sub GetAllInfo()")

        Try
            Dim c As ComponentAssembly = Part.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                '*** insert code to process 'root component' (assembly file)
                lg.WriteLine("  part has components")
                '*** end of code to process root component
                lg.WriteLine("  calling GetAllComponentChildren")
                GetAllComponentChildren(c.RootComponent)
            Else
                '*** insert code to process piece part, part has no components
                lg.WriteLine("  part has no components")
            End If
        Catch ex As NXException
            lg.WriteLine("Sub GetAllInfo error: " & ex.ErrorCode)
            lg.WriteLine("  " & ex.Message)
        End Try

        lg.WriteLine("exiting Sub GetAllInfo()")

    End Sub

    Private Sub GetAllComponentChildren(ByVal comp As Component)

        For Each child As Component In comp.GetChildren()
            lg.WriteLine(child.DisplayName)
            '*** insert code to process component or subassembly

            If Me.LoadComponent(child) Then

                _allComponents.Add(child)

                Dim tempPart As Part = child.Prototype.OwningPart
                If Not _allUniqueParts.Contains(tempPart) Then
                    _allUniqueParts.Add(tempPart)
                End If

            Else
                'component could not be loaded
            End If
            '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then
                '*** this is a subassembly, add code specific to subassemblies

                '*** end of code to process subassembly
            Else
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components

            End If
            Me.GetAllComponentChildren(child)
        Next
    End Sub


    Private Sub GetInfo()

        'get top level component info from assembly (no recursion)
        lg.WriteLine("Sub GetInfo()")

        Try
            Dim c As ComponentAssembly = Part.ComponentAssembly
            If Not IsNothing(c.RootComponent) Then
                '*** insert code to process 'root component' (assembly file)
                lg.WriteLine("  part has components")
                '*** end of code to process root component
                lg.WriteLine("  calling GetComponentChildren")
                Me.GetComponentChildren(c.RootComponent)
            Else
                '*** insert code to process piece part, part has no components
                lg.WriteLine("  part has no components")
            End If
        Catch ex As NXException
            lg.WriteLine("Sub GetInfo error: " & ex.ErrorCode)
            lg.WriteLine("  " & ex.Message)
        End Try

        lg.WriteLine("exiting GetInfo()")

    End Sub

    Private Sub GetComponentChildren(ByVal comp As Component)

        For Each child As Component In comp.GetChildren()
            '*** insert code to process component or subassembly
            _components.Add(child)
            Dim tempPart As Part = child.Prototype.OwningPart
            If Not _uniqueParts.Contains(tempPart) Then
                _uniqueParts.Add(tempPart)
            End If
            '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then
                '*** this is a subassembly, add code specific to subassemblies

                '*** end of code to process subassembly
            Else
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components

            End If
        Next
    End Sub

    Private Function LoadComponent(ByVal theComponent As Component) As Boolean

        lg.WriteLine("Sub LoadComponent()")

        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
            lg.WriteLine("  component: " & theComponent.DisplayName & " is already partially or fully loaded")
            lg.WriteLine("  return: True")
            lg.WriteLine("exiting Sub LoadComponent()")
            lg.WriteLine("")
            Return True
        Catch ex As NullReferenceException
            'component is not loaded
            Try
                lg.WriteLine("  component not loaded, retrieving part information")
                _theUfSession.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)
                lg.WriteLine("  component part file: " & partName)

                Dim theLoadStatus As PartLoadStatus
                _theSession.Parts.Open(partName, theLoadStatus)

                If theLoadStatus.NumberUnloadedParts > 0 Then
                    If theLoadStatus.NumberUnloadedParts > 1 Then
                        lg.WriteLine("  problem loading " & theLoadStatus.NumberUnloadedParts.ToString & " components")
                    Else
                        lg.WriteLine("  problem loading 1 component")
                    End If

                    Dim allReadOnly As Boolean = True
                    For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1
                        lg.WriteLine("part name: " & theLoadStatus.GetPartName(i))
                        lg.WriteLine("part status: " & theLoadStatus.GetStatus(i))
                        If theLoadStatus.GetStatus(i) = 641058 Then
                            'read-only warning, file loaded ok
                        Else
                            '641044: file not found
                            allReadOnly = False
                            If Not _notLoaded.Contains(partName) Then
                                _notLoaded.Add(partName)
                            End If
                        End If
                        lg.WriteLine("status description: " & theLoadStatus.GetStatusDescription(i))
                        lg.WriteLine("")
                    Next
                    If allReadOnly Then
                        lg.WriteLine("  read-only warnings only")
                        lg.WriteLine("  return: True")
                        Return True
                    Else
                        'warnings other than read-only...
                        lg.WriteLine("  return: False")
                        lg.WriteLine("exiting Sub LoadComponent()")
                        lg.WriteLine("")
                        Return False
                    End If
                Else
                    lg.WriteLine("  component(s) loaded successfully")
                    lg.WriteLine("  return: True")
                    lg.WriteLine("exiting Sub LoadComponent()")
                    lg.WriteLine("")
                    Return True
                End If

            Catch ex2 As NXException
                lg.WriteLine("  Load error: " & ex2.Message)
                lg.WriteLine("  error code: " & ex2.ErrorCode)
                lg.WriteLine("  return: False")
                lg.WriteLine("exiting Sub LoadComponent()")
                lg.WriteLine("")
                If ex2.Message.ToLower = "file not found" Then
                    If Not _notLoaded.Contains(partName) Then
                        _notLoaded.Add(partName)
                    End If
                End If
                Return False
            End Try
        Catch ex As NXException
            lg.WriteLine("  Error in Sub LoadComponent: " & ex.Message)
            lg.WriteLine("  return: False")
            lg.WriteLine("exiting Sub LoadComponent()")
            lg.WriteLine("")
            Return False
        End Try

    End Function

End Class

NX 12.0.1.7 Windows 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor