Techomick
Mechanical
- Jun 21, 2011
- 46
Hello,
I am pretty new to nx journaling, but I have 90% of the functionality of this one that I want. I want this journal to run recursively run through an assembly and move objects to predefined layers as well as then change the child components to Model reference set. So far I have been able to do all of this, however I want to remove any sheet bodies from the Model reference set.
Here is what I have:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Windows.Forms
Imports System.Collections.Generic
Module NXJournal
Public theSession As Session = Session.GetSession()
Public lw As ListingWindow = theSession.ListingWindow
Public Dim dispPart As Part = theSession.Parts.Display
Public Dim workPart As Part = theSession.Parts.Work
Public Dim layerdatums As Int32 = 61
Public Dim layerlines As Int32 = 41
Public Dim partLoadStatus1 As PartLoadStatus
Public Dim partdatums As DisplayableObject() = theSession.Parts.Work.Datums.ToArray()
Public Dim partlines As DisplayableObject() = theSession.Parts.Work.Lines.ToArray()
Public Dim partcurves As DisplayableObject() = theSession.Parts.Work.Curves.ToArray()
Public Dim partsplines As DisplayableObject() = theSession.Parts.Work.Splines.ToArray()
Public Dim partcoordinates As DisplayableObject() = theSession.Parts.Work.CoordinateSystems.ToArray()
Public Dim partpoints As DisplayableObject() = theSession.Parts.Work.Points.ToArray()
Dim c As ComponentAssembly = dispPart.ComponentAssembly
Dim errorList1 As ErrorList
Sub Main
lw.Open
lw.WriteLine("BEGINNING TO PROCESS ASSEMBLY")
'CHECK IF ASSY
if not IsNothing(c.RootComponent) then
lw.WriteLine("Assembly: " & c.RootComponent.DisplayName & " CLEANED & REFERENCE CHANGED TO 'MODEL'
")
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
ReportComponentChildren(c.RootComponent, 0)
else
lw.WriteLine("Part has no components")
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
end if
End Sub
Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'*** PROCESS COMPONENT OR SUB-ASSY
Dim acomps(0) As Assemblies.Component
Dim acomp As Assemblies.Component = CType(child, Assemblies.Component)
acomps(0) = acomp
errorList1 = c.ReplaceReferenceSetInOwners("MODEL", acomps)
errorList1.Dispose()
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName() & " CLEANED
")
if child.GetChildren.Length <> 0 then
'*** PROCESS SUB-ASSY
'lw.WriteLine(New String(" ", indent * 2) & "* subassembly with " & child.GetChildren.Length & " components")
'lw.WriteLine(New String(" ", indent * 2) & " + Active Arrangement: " & child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
else
'PROCESS LEAF NODE
theSession.Parts.SetWorkComponent(child, partLoadStatus1)
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
Dim mySolids As List(Of Body) = New List(Of Body)
Dim myReferenceSets As ReferenceSet()
myReferenceSets = workPart.GetAllReferenceSets()
Dim theReferenceSet As ReferenceSet
Const whatRefSet As String = "MODEL"
Dim stateArray1(0) As Layer.StateInfo
Dim i As Integer
Dim refMembers(-1) As NXObject
Dim refMemberTags() As Tag
For Each myRefSet As ReferenceSet In myReferenceSets
If myRefSet.Name.ToUpper() = whatRefSet Then
theReferenceSet = myRefSet
For Each solid As Body In workPart.Bodies
If solid.IsSheetBody Then
mySolids.Add(solid)
End If
Next
End If
thereferenceSet.RemoveObjectsFromReferenceSet(mySolids.ToArray)
Next
theSession.Parts.SetWorkComponent(c.RootComponent, partLoadStatus1)
partLoadStatus1.Dispose()
end if
reportComponentChildren(child, indent + 1)
Next
End Sub
Function ReplaceReferenceSetInOwners (newReferenceSet As String, components As Component()) As ErrorList
End Function
End Module
Design Engineer, NX 7.5
I am pretty new to nx journaling, but I have 90% of the functionality of this one that I want. I want this journal to run recursively run through an assembly and move objects to predefined layers as well as then change the child components to Model reference set. So far I have been able to do all of this, however I want to remove any sheet bodies from the Model reference set.
Here is what I have:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Windows.Forms
Imports System.Collections.Generic
Module NXJournal
Public theSession As Session = Session.GetSession()
Public lw As ListingWindow = theSession.ListingWindow
Public Dim dispPart As Part = theSession.Parts.Display
Public Dim workPart As Part = theSession.Parts.Work
Public Dim layerdatums As Int32 = 61
Public Dim layerlines As Int32 = 41
Public Dim partLoadStatus1 As PartLoadStatus
Public Dim partdatums As DisplayableObject() = theSession.Parts.Work.Datums.ToArray()
Public Dim partlines As DisplayableObject() = theSession.Parts.Work.Lines.ToArray()
Public Dim partcurves As DisplayableObject() = theSession.Parts.Work.Curves.ToArray()
Public Dim partsplines As DisplayableObject() = theSession.Parts.Work.Splines.ToArray()
Public Dim partcoordinates As DisplayableObject() = theSession.Parts.Work.CoordinateSystems.ToArray()
Public Dim partpoints As DisplayableObject() = theSession.Parts.Work.Points.ToArray()
Dim c As ComponentAssembly = dispPart.ComponentAssembly
Dim errorList1 As ErrorList
Sub Main
lw.Open
lw.WriteLine("BEGINNING TO PROCESS ASSEMBLY")
'CHECK IF ASSY
if not IsNothing(c.RootComponent) then
lw.WriteLine("Assembly: " & c.RootComponent.DisplayName & " CLEANED & REFERENCE CHANGED TO 'MODEL'
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
ReportComponentChildren(c.RootComponent, 0)
else
lw.WriteLine("Part has no components")
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
end if
End Sub
Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'*** PROCESS COMPONENT OR SUB-ASSY
Dim acomps(0) As Assemblies.Component
Dim acomp As Assemblies.Component = CType(child, Assemblies.Component)
acomps(0) = acomp
errorList1 = c.ReplaceReferenceSetInOwners("MODEL", acomps)
errorList1.Dispose()
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName() & " CLEANED
if child.GetChildren.Length <> 0 then
'*** PROCESS SUB-ASSY
'lw.WriteLine(New String(" ", indent * 2) & "* subassembly with " & child.GetChildren.Length & " components")
'lw.WriteLine(New String(" ", indent * 2) & " + Active Arrangement: " & child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
else
'PROCESS LEAF NODE
theSession.Parts.SetWorkComponent(child, partLoadStatus1)
workPart.Layers.MoveDisplayableObjects(layerdatums, partdatums)
workPart.Layers.MoveDisplayableObjects(layerlines, partlines)
workPart.Layers.MoveDisplayableObjects(layerlines, partcurves)
workPart.Layers.MoveDisplayableObjects(layerlines, partsplines)
workPart.Layers.MoveDisplayableObjects(layerdatums, partcoordinates)
workPart.Layers.MoveDisplayableObjects(layerlines, partpoints)
Dim mySolids As List(Of Body) = New List(Of Body)
Dim myReferenceSets As ReferenceSet()
myReferenceSets = workPart.GetAllReferenceSets()
Dim theReferenceSet As ReferenceSet
Const whatRefSet As String = "MODEL"
Dim stateArray1(0) As Layer.StateInfo
Dim i As Integer
Dim refMembers(-1) As NXObject
Dim refMemberTags() As Tag
For Each myRefSet As ReferenceSet In myReferenceSets
If myRefSet.Name.ToUpper() = whatRefSet Then
theReferenceSet = myRefSet
For Each solid As Body In workPart.Bodies
If solid.IsSheetBody Then
mySolids.Add(solid)
End If
Next
End If
thereferenceSet.RemoveObjectsFromReferenceSet(mySolids.ToArray)
Next
theSession.Parts.SetWorkComponent(c.RootComponent, partLoadStatus1)
partLoadStatus1.Dispose()
end if
reportComponentChildren(child, indent + 1)
Next
End Sub
Function ReplaceReferenceSetInOwners (newReferenceSet As String, components As Component()) As ErrorList
End Function
End Module
Design Engineer, NX 7.5