NX Journal-Removing sheet bodies from Model Ref Set
NX Journal-Removing sheet bodies from Model Ref Set
(OP)
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
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





RE: NX Journal-Removing sheet bodies from Model Ref Set
www.nxjournaling.com
RE: NX Journal-Removing sheet bodies from Model Ref Set
Cowski,
I do not get any errors, but the sheet bodies from the child parts are not removed from the 'Model' reference set. Any input would be appreciated.
Thanks!
Design Engineer, NX 7.5
RE: NX Journal-Removing sheet bodies from Model Ref Set
CODE
Option Strict Off Imports System Imports System.Collections.Generic Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim theReferenceSet As ReferenceSet Dim refMembers(-1) As NXObject Dim refSetSheets As New List(Of Body) '%%%%%%%%%% Change the following line to point to the name of your reference set %%%%%%%%%% Const whatRefSet As String = "MODEL" '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% For Each myRefSet As ReferenceSet In workPart.GetAllReferenceSets() If myRefSet.Name.ToUpper() = whatRefSet.ToUpper Then theReferenceSet = myRefSet refMembers = myRefSet.AskAllDirectMembers() For Each myObject As DisplayableObject In refMembers If TypeOf myObject Is Body Then Dim myBody As Body = myObject If myBody.IsSheetBody Then refSetSheets.Add(myBody) End If End If Next End If Next 'remove sheet bodies from reference set theReferenceSet.RemoveObjectsFromReferenceSet(refSetSheets.ToArray) lw.Close() 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
RE: NX Journal-Removing sheet bodies from Model Ref Set
Thanks!
Design Engineer, NX 7.5