kr7530
Automotive
- Aug 9, 2011
- 130
I am trying to get a journal to cycle through an assembly with no luck.
I get the error: "Failed: NXOpen.NXException: This operation can only be done on the display part
at NXOpen.Layer.LayerManager.GetAllObjectsOnLayer(Int32 layer)"
I am assuming I need to make the prototype part the displayed part but am unsure as to how.
Any help would be greatly appreciated!!!!
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
Imports NXOpen.UI
Imports NXOpenUI
Imports NXOpen.Utilities
Imports System.Windows.Forms
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
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
ReportComponentChildren(c.RootComponent, 0)
else
'*** insert code to process piece part
lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close
End Sub
'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'_____________________________________________________________________________________________
Dim workPart As Part = child.Prototype.OwningPart
Dim lw As ListingWindow = theSession.ListingWindow()
Dim layerObjects2() As NXObject
lw.Open
lw.WriteLine(child.Name)
'checking to see if refereset exists--------------------------------------------------------
Dim BODYRefSetCount As Integer
Dim ModelRefSetCount As Integer
For Each myRefSet As ReferenceSet In workPart.GetAllReferenceSets()
If myRefSet.Name = "BODY" Then
layerObjects2 = workPart.Layers.GetAllObjectsOnLayer(150)
If layerObjects2.Length > 0 Then
myRefSet.RemoveObjectsFromReferenceSet(layerObjects2)
Else If layerObjects2.Length = 0 Then
'MessageBox.Show("No geometry on layer 150")
End If
BODYRefSetCount = 1
Else If myRefSet.Name = "MODEL" Then
myRefSet.RemoveObjectsFromReferenceSet(myRefSet.AskAllDirectMembers())
Dim refsetMembers() As NXObject = myRefSet.AskMembersInReferenceSet()
ModelRefSetCount = 1
End If
Next
'populating reference set--------------------------------------------------------------------
layerObjects2 = workPart.Layers.GetAllObjectsOnLayer(1)
If layerObjects2.Length > 0 Then
For Each myRefSet4 As ReferenceSet In workPart.GetAllReferenceSets()
If myRefSet4.Name = "MODEL" Then
Try
Dim body1 As Body = CType(workPart.Bodies.FindObject("BLOCK(0)"), Body)
Dim components1(0) As NXObject
components1(0) = body1
myRefSet4.AddObjectsToReferenceSet(components1)
Catch ex As NXException
'MessageBox.Show("Block(0) does not exist, add detail to reference set manually")
End Try
End If
Next
Else If layerObjects2.Length = 0 Then
'MessageBox.Show("No entities exist on layer 1")
End If
'_____________________________________________________________________________________________
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
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)
'*** 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
reportComponentChildren(child, indent + 1)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************
End Module
I get the error: "Failed: NXOpen.NXException: This operation can only be done on the display part
at NXOpen.Layer.LayerManager.GetAllObjectsOnLayer(Int32 layer)"
I am assuming I need to make the prototype part the displayed part but am unsure as to how.
Any help would be greatly appreciated!!!!
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
Imports NXOpen.UI
Imports NXOpenUI
Imports NXOpen.Utilities
Imports System.Windows.Forms
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
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'*** end of code to process root component
ReportComponentChildren(c.RootComponent, 0)
else
'*** insert code to process piece part
lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
lw.Close
End Sub
'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'_____________________________________________________________________________________________
Dim workPart As Part = child.Prototype.OwningPart
Dim lw As ListingWindow = theSession.ListingWindow()
Dim layerObjects2() As NXObject
lw.Open
lw.WriteLine(child.Name)
'checking to see if refereset exists--------------------------------------------------------
Dim BODYRefSetCount As Integer
Dim ModelRefSetCount As Integer
For Each myRefSet As ReferenceSet In workPart.GetAllReferenceSets()
If myRefSet.Name = "BODY" Then
layerObjects2 = workPart.Layers.GetAllObjectsOnLayer(150)
If layerObjects2.Length > 0 Then
myRefSet.RemoveObjectsFromReferenceSet(layerObjects2)
Else If layerObjects2.Length = 0 Then
'MessageBox.Show("No geometry on layer 150")
End If
BODYRefSetCount = 1
Else If myRefSet.Name = "MODEL" Then
myRefSet.RemoveObjectsFromReferenceSet(myRefSet.AskAllDirectMembers())
Dim refsetMembers() As NXObject = myRefSet.AskMembersInReferenceSet()
ModelRefSetCount = 1
End If
Next
'populating reference set--------------------------------------------------------------------
layerObjects2 = workPart.Layers.GetAllObjectsOnLayer(1)
If layerObjects2.Length > 0 Then
For Each myRefSet4 As ReferenceSet In workPart.GetAllReferenceSets()
If myRefSet4.Name = "MODEL" Then
Try
Dim body1 As Body = CType(workPart.Bodies.FindObject("BLOCK(0)"), Body)
Dim components1(0) As NXObject
components1(0) = body1
myRefSet4.AddObjectsToReferenceSet(components1)
Catch ex As NXException
'MessageBox.Show("Block(0) does not exist, add detail to reference set manually")
End Try
End If
Next
Else If layerObjects2.Length = 0 Then
'MessageBox.Show("No entities exist on layer 1")
End If
'_____________________________________________________________________________________________
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
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)
'*** 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
reportComponentChildren(child, indent + 1)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************
End Module