Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
'REVISÃO
'22/12/14 - REVISADA FUNÇÃO
'
Module Aplicar_Qnt_Montagem
Dim theSession As Session = Session.GetSession()
Dim session As Session = theSession
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displaypart As Part = theSession.Parts.Display
Dim prototype As Part
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
Sub Main()
session.ListingWindow.Open()
Echo("-------------------------------------------------------------------------------------------------------")
Echo("OBSERVAÇÕES")
Echo("Para o correto funcionamento do comando todos os componentes da montagem devem estar abertos.")
Echo("Itens abertos, montados em sub-assemblies não abertos, podem ter a sua quantidade alterada incorretamente.")
Echo("Preferencialmente utilizar este comando com ""Make Work"" na Lista de Materiais.")
Echo("-------------------------------------------------------------------------------------------------------")
If workPart Is Nothing Then Return
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(session.MarkVisibility.Visible, "Quantidade")
Echo("")
Echo("ITENS COM A QUANTIDADE ATUALIZADOS:")
Echo("")
Try
Dim part1 As Part
part1 = session.Parts.Work
Dim c As ComponentAssembly = part1.ComponentAssembly
Walk(c.RootComponent, 0)
Catch e As Exception
session.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
End Sub
Sub Walk(c As Component, level As Integer)
Dim children As Component() = c.GetChildren()
Dim child As Component
Dim prototype As Part
If TypeOf c.Prototype Is Part Then
prototype = CType(c.Prototype, Part)
Dim q As String
'----------------------------------------------------------------
Dim reqatt As String = ""
Try
reqatt = prototype.GetStringAttribute("CODG")
Catch ex As Exception
'session.ListingWindow.WriteLine("Erro" & prototype.Leaf)
End Try
If IsNumeric(reqatt) = False Then
' status = "item não é biblioteca"
q = quantidade(prototype)
atributos(q, prototype)
' Else
' Echo("Item não processado: " & prototype.Leaf)
End If
'----------------------------------------------------------------
For Each child In children
Walk(child, level + 1)
Next
Else
session.ListingWindow.WriteLine(New String(" "c, level) & c.Name & " is not loaded")
End If
End Sub
Function atributos(qnt As String, peca As Part)
' ----------------------------------------------
' CAMPO ATRIBUTOS
' ----------------------------------------------
Dim qntatual As String = ""
Try
qntatual = peca.GetStringAttribute("QNT")
Catch ex As Exception
End Try
If Not qntatual = qnt Then
Try
peca.SetAttribute("QNT", qnt)
peca.SetAttribute("QNT_RESP", System.Environment.UserName)
' ----------------------------------------------
' CAMPO DATA
' ----------------------------------------------
Dim DateString(0) As String
Dim TimeNote As DateTime
TimeNote = System.DateTime.Now()
DateString = TimeNote.GetDateTimeFormats()
peca.SetAttribute("QNT_DATA", DateString(0))
Echo("Qnt: " & qnt & " - Item: " & peca.Leaf)
Catch ex As Exception
MsgBox("Command Error 1", MsgBoxStyle.OkOnly, "Error")
End Try
End If
End Function
Function quantidade(peca As Part)
' Dim peca As Part
Dim contagem() As Tag = Nothing
ufs.Assem.AskOccsOfPart(workPart.Tag, peca.Tag, contagem)
Return contagem.Length
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module