Journal Layer Name
Journal Layer Name
(OP)
So I have a simple journal to give me a name attribute for each component. The reason I do not want to use the one that comes standard in the navigator is because it gives me the Original layer instead of a number. However, this journal does not give me numbers either. Any ideas how to get around the Original layer settings?
CODE --> vb
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.Utilities
Imports NXOpen.Assemblies
Module LayerName
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Sub Main()
Dim displaypart As Part = theSession.Parts.Display
Dim c As Component = displaypart.ComponentAssembly.RootComponent
Dim children As Component() = c.GetChildren()
For Each comp As Component In children
Comp.SetAttribute("LayerName", comp.layer)
Next
End Sub
End Module Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17





RE: Journal Layer Name
Short answer: Change the component layer option to "specified layer" rather than "original".
The "original" option will map your component part layers to the assembly part layers. The component is no longer on a single layer that NX can report. Usually, the component is only a single solid body that you are interested in. If this is the case, you can create a unique reference set for this solid and use it in the assembly. In your journal file, you can get the body from this ref set and query it to see what layer it is on.
www.nxjournaling.com
RE: Journal Layer Name
How would I go about attempting this? These bodies are already on the "TRUE" reference set. Each component has 1 body on that reference set, I need to grab that layer and make it a new attribute called LayerName. I am stuck on transitioning between finding the reference set and the body.
Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Layer Name
I posted some code there that will remove sheet bodies from a reference set. As you are iterating through the objects in the reference set you can query the object's layer.
www.nxjournaling.com
RE: Journal Layer Name
Any ideas as to why I might be receiving this error? Here is my code:
CODE --> vb
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Assemblies Module Module1 Dim theSession As Session = Session.GetSession() Dim displaypart As Part = theSession.Parts.Display Sub Main() Dim c As Component = displaypart.ComponentAssembly.RootComponent ProcessAssemblyTree(c) End Sub Sub ProcessAssemblyTree(ByVal c As Component) Dim workpart As Part = theSession.Parts.Work Dim theReferenceSet As ReferenceSet Dim refMembers(-1) As NXObject Const whatRefSet As String = "TRUE" Dim children As Component() = c.GetChildren() For each comp As Component in children 'Dim component1 As Assemblies.Component = comp 'Dim partLoadStatus1 As PartLoadStatus 'theSession.Parts.SetWorkComponent(component1, partLoadStatus1) 'workPart = theSession.Parts.Work Dim MyCompPart As Part = Comp.Prototype For Each myRefSet As ReferenceSet In MyCompPart.GetAllReferenceSets() If myRefSet.Name = whatRefSet Then theReferenceSet = myRefSet refMembers = myRefSet.AskAllDirectMembers() For Each myObject As DisplayableObject In refMembers If TypeOf myObject Is Body Then Dim myBody As Body = myObject Dim temp As String temp = myObject.Layer Comp.SetAttribute("LayerNumber", temp) End If Next End If Next ProcessAssemblyTree(Comp) 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 End Function End ModuleDenis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Layer Name
CODE
Dim MyCompPart As Part = Comp.PrototypeA prototype is not a part.
Instead try:
CODE
www.nxjournaling.com
RE: Journal Layer Name
That gave me a new error at the following line:
CODE --> vb
The error was NullReferenceException: Object reference not set to an instance of an object.
Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Layer Name
CODE
We might need to tweak the code a bit to get all the way up the chain to the owning part.
www.nxjournaling.com
RE: Journal Layer Name
CODE --> VB
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Assemblies Module Module1 Dim theSession As Session = Session.GetSession() Dim displaypart As Part = theSession.Parts.Display Sub Main() Dim c As Component = displaypart.ComponentAssembly.RootComponent ProcessAssemblyTree(c) End Sub Sub ProcessAssemblyTree(ByVal c As Component) Dim workpart As Part = theSession.Parts.Work Dim theReferenceSet As ReferenceSet Dim refMembers(-1) As NXObject Const whatRefSet As String = "TRUE" Dim children As Component() = c.GetChildren() For each comp As Component in children Try Dim MyCompPart As Part = Comp.Prototype.OwningPart For Each myRefSet As ReferenceSet In MyCompPart.GetAllReferenceSets() If myRefSet.Name = whatRefSet Then theReferenceSet = myRefSet refMembers = myRefSet.AskAllDirectMembers() For Each myObject As DisplayableObject In refMembers If TypeOf myObject Is Body Then Dim myBody As Body = myObject Dim temp As String temp = myObject.Layer Comp.SetAttribute("LayerNumber", temp) End If Next End If Next Catch ex As Exception 'Do Nothing End Try ProcessAssemblyTree(Comp) 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 End Function End ModuleDenis Huskic
Data Prep NX7.5
Kettering University
Class of '17
RE: Journal Layer Name
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Assemblies Module Module2 Dim theSession As Session = Session.GetSession() Dim displaypart As Part = theSession.Parts.Display Dim lw As ListingWindow = theSession.ListingWindow Sub Main() lw.Open() Dim c As Component = displaypart.ComponentAssembly.RootComponent ProcessAssemblyTree(c) lw.Close() End Sub Sub ProcessAssemblyTree(ByVal c As Component) 'Dim workpart As Part = theSession.Parts.Work 'Dim theReferenceSet As ReferenceSet Dim refMembers() As NXObject Const whatRefSet As String = "MODEL" Dim children As Component() = c.GetChildren() For Each comp As Component In children Dim MyCompPart As Part Dim firstBody As Body Dim firstTimeStamp As Integer Dim featureName As String Try MyCompPart = comp.Prototype.OwningPart lw.WriteLine("") lw.WriteLine("MyCompPart: " & MyCompPart.FullPath) For Each myRefSet As ReferenceSet In MyCompPart.GetAllReferenceSets() lw.WriteLine("ref set name: " & myRefSet.Name) Dim found As Boolean = False If myRefSet.Name = whatRefSet Then firstTimeStamp = MyCompPart.Features.ToArray.Length 'lw.WriteLine("'first' time stamp: " & firstTimeStamp.ToString) 'lw.WriteLine("num features in part: " & MyCompPart.Features.ToArray.Length.ToString) 'theReferenceSet = myRefSet refMembers = myRefSet.AskAllDirectMembers() 'lw.WriteLine("num ref set members: " & myRefSet.AskAllDirectMembers.Length.ToString) For Each myObject As DisplayableObject In refMembers If TypeOf myObject Is Body Then Dim myBody As Body = myObject Dim temp As String = myObject.Layer.ToString 'comp.SetAttribute("LayerNumber", temp) For Each bodFeature As Features.Feature In myBody.GetFeatures 'lw.WriteLine("num features of body: " & myBody.GetFeatures.Length.ToString) If bodFeature.Timestamp < firstTimeStamp Then found = True 'lw.WriteLine("firstTimeStamp: " & firstTimeStamp.ToString) 'lw.WriteLine("bodFeature.Timestamp: " & bodFeature.Timestamp.ToString) firstTimeStamp = bodFeature.Timestamp firstBody = myBody featureName = bodFeature.GetFeatureName 'lw.WriteLine("featureName: " & featureName) End If Next End If Next End If If found Then lw.WriteLine("first body in feature tree is child of feature: " & featureName) lw.WriteLine("this body is on layer: " & firstBody.Layer.ToString) End If Next Catch ex As NullReferenceException lw.WriteLine("") lw.WriteLine("## " & comp.DisplayName & " not loaded") Catch ex As NXException 'Do Nothing If ex.ErrorCode = 720074 Then lw.WriteLine("** component not fully loaded") Else lw.WriteLine("Error: " & "(" & ex.ErrorCode & ") " & ex.Message) End If End Try ProcessAssemblyTree(comp) 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 End Function End Modulewww.nxjournaling.com