javaxp
Automotive
- Jul 14, 2014
- 43
Hi,
I'm writing a journal that indexes an assembly. The journal gets the levels of indexation and writes the results on the information window, but I can't write the level of each component into component attribute ("NIVEL_ESTRUCTURA") .
Can anyone help me? Thanks in advance...
Here is the code:
I'm writing a journal that indexes an assembly. The journal gets the levels of indexation and writes the results on the information window, but I can't write the level of each component into component attribute ("NIVEL_ESTRUCTURA") .
Can anyone help me? Thanks in advance...
Here is the code:
Code:
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Features
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim nivel As String = "1"
Dim longString As Integer = 0
Dim longFinalString As Integer = 0
Dim caracterNivel As String = "."
Public Sub Main(ByVal args As String())
Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(
NXOpen.Session.MarkVisibility.Visible, "Reorder Components")
Dim theOrders As Assemblies.ComponentOrder() = Nothing
displayPart.ComponentAssembly.GetComponentOrders(theOrders)
' GetActiveOrder is new in NX10.0.3
Dim theCurrentOrder As Assemblies.Order =
displayPart.ComponentAssembly.GetActiveOrder()
Echo("El orden de ensamble actual es " & theCurrentOrder.Name)
theCurrentOrder.Activate()
theSession.UpdateManager.DoUpdate(markId1)
Echo(theCurrentOrder.Name & ":")
displayPart.SetAttribute("NIVEL_ESTRUCTURA", nivel)
WalkAssemblyTree(displayPart.ComponentAssembly.RootComponent, theCurrentOrder, 0)
theSession.UndoToMark(markId1, "")
theSession.DeleteUndoMarksUpToMark(markId1, "", False)
End Sub
Sub WalkAssemblyTree(ByVal theComponent As NXOpen.Assemblies.Component,
ByVal theOrder As NXOpen.Assemblies.ComponentOrder,
Indice As Int32)
Dim kids As Assemblies.Component() = theComponent.GetChildren()
Try
If kids.Length = 0 Then
longString = Len(nivel)
longFinalString = InStrRev(nivel, caracterNivel)
nivel = Left(nivel, longFinalString - 1)
Return ' Not an assembly or sub-assembly
Else
kids = theOrder.AskChildrenOrder(theComponent)
For ii As Integer = 0 To kids.Length - 1
nivel = nivel & "." & ii + 1
lw.WriteLine(nivel & " " & kids(ii).DisplayName)
kids(ii).SetUserAttribute("NIVEL_ESTRUCTURA", -1, nivel, Update.Option.Now)
WalkAssemblyTree(kids(ii), theOrder, Indice)
Next
longString = Len(nivel)
longFinalString = InStrRev(nivel, caracterNivel)
nivel = Left(nivel, longFinalString - 1)
End If
Catch
End Try
End Sub
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module