allanareque
Industrial
- Jun 29, 2020
- 2
Hello everybody.
I started a Journal that allows you to enter six attributes at once for all components of an assembly.
This Journal is the result of the union of several works by colleagues from the forum who always collaborate with the development of our work with UGNX.
However, this Journal has a problem: It collects the input information of the attributes from the Windows Form and writes them as attributes to each Part File through NXJ_Assembly_info 0.1.1 but, when closing the assembly and opening it again, everything is loses. Each File part does not write the attributes that were written.
This occurs even using the "Save All" command.
I noticed that the same Journals that use NXJ_Assembly_info have the same problem.
Has anyone encountered this same problem and already has a solution for it? If anyone knows what is happening, please share the solution to this problem.
I'll leave the code I'm working on here so you can check what might be wrong and ask you to change it in order to make it save the attributes in each Part file.
I believe that this Journal can also help other people in their activities, so I make it available here.
Thank you very much.
I started a Journal that allows you to enter six attributes at once for all components of an assembly.
This Journal is the result of the union of several works by colleagues from the forum who always collaborate with the development of our work with UGNX.
However, this Journal has a problem: It collects the input information of the attributes from the Windows Form and writes them as attributes to each Part File through NXJ_Assembly_info 0.1.1 but, when closing the assembly and opening it again, everything is loses. Each File part does not write the attributes that were written.
This occurs even using the "Save All" command.
I noticed that the same Journals that use NXJ_Assembly_info have the same problem.
Has anyone encountered this same problem and already has a solution for it? If anyone knows what is happening, please share the solution to this problem.
I'll leave the code I'm working on here so you can check what might be wrong and ask you to change it in order to make it save the attributes in each Part file.
I believe that this Journal can also help other people in their activities, so I make it available here.
Thank you very much.
Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Module Module1
Private _formTitle As String = ""
Public ReadOnly Property FormTitle() As String
Get
Return _formTitle
End Get
End Property
Private _attributeTitle As String = ""
Public ReadOnly Property AttributeTitle() As String
Get
Return _attributeTitle
End Get
End Property
Private _attributeBO As String = ""
Public Property AttributeBO() As String
Get
Return _attributeBO
End Get
Set(ByVal value As String)
_attributeBO = value
End Set
End Property
Private _attributeCodigoProduto As String = ""
Public Property AttributeCodigoProduto() As String
Get
Return _attributeCodigoProduto
End Get
Set(ByVal value As String)
_attributeCodigoProduto = value
End Set
End Property
Private _attributeFerramenta As String = ""
Public Property AttributeFerramenta() As String
Get
Return _attributeFerramenta
End Get
Set(ByVal value As String)
_attributeFerramenta = value
End Set
End Property
Private _attributeNomeProduto As String = ""
Public Property AttributeNomeProduto() As String
Get
Return _attributeNomeProduto
End Get
Set(ByVal value As String)
_attributeNomeProduto = value
End Set
End Property
Private _attributeProjectDate As String = ""
Public Property AttributeProjectDate() As String
Get
Return _attributeProjectDate
End Get
Set(ByVal value As String)
_attributeProjectDate = value
End Set
End Property
Private _attributeProjectName As String = ""
Public Property AttributeProjectName() As String
Get
Return _attributeProjectName
End Get
Set(ByVal value As String)
_attributeProjectName = value
End Set
End Property
Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Dim blnCancel As Boolean = False
Sub Main()
Dim myAsmInfo As New NXJ_Assembly_info
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim lg As LogFile = theSession.LogFile
Const undoMarkName As String = "NXJ form journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
'-------------------------------------------------------------------------------------------------------------
Dim myAttributeInfo As NXObject.AttributeInformation
_attributeTitle = "BO"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1) 'recolhe a informacao ja existente de um atributo
_attributeBO = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
_attributeTitle = "Codigo_Produto"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1)
_attributeCodigoProduto = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
_attributeTitle = "Ferramenta"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1)
_attributeFerramenta = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
_attributeTitle = "Nome_Produto"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1)
_attributeNomeProduto = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
_attributeTitle = "Project_Date"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1)
_attributeProjectDate = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
_attributeTitle = "Project_Name"
Try
myAttributeInfo = workPart.GetUserAttribute(_attributeTitle, NXObject.AttributeType.String, -1)
_attributeProjectName = myAttributeInfo.StringValue
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
Else
'unexpected error: show error message, undo, and exit journal
MsgBox(ex.ErrorCode & ": " & ex.Message)
theSession.UndoToMark(markId1, undoMarkName)
Return
End If
Finally
End Try
'--------------------------------------------------------------------------------------------
_formTitle = "Preenchimento Carimbo 2D"
'--------------------------------------------------------------------------------------------
Dim myForm As New Form1
'set form object properties (current part attribute title and value)
myForm.AttributeBO = _attributeBO
myForm.AttributeCodigoProduto = _attributeCodigoProduto
myForm.AttributeFerramenta = _attributeFerramenta
myForm.AttributeNomeProduto = _attributeNomeProduto
myForm.AttributeProjectDate = _attributeProjectDate
myForm.AttributeProjectName = _attributeProjectName
myForm.FormTitle = _formTitle
'display our form
ufs.Abort.DisableAbort()
myForm.ShowDialog()
'----------------------------ACAO APOS INPUTS--------------------------------------------------
'----------------------------------------------------------------------------------------------
Try
myAsmInfo.Part = workPart
Catch ex As NXException
MessageBox.Show("Error: " & ex.Message & ControlChars.CrLf & "journal exiting", "Error " & ex.ErrorCode.ToString, MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'----Adicione aqui-----------------
Dim attTitleBO As String = "BO"
Dim attTitleCodigoProduto As String = "Codigo_Produto"
Dim attTitleFerramenta As String = "Ferramenta"
Dim attTitleNomeProduto As String = "Nome_Produto"
Dim attTitleProjectDate As String = "Project_Date"
Dim attTitleProjectName As String = "Project_BO"
Dim attValueBO As String = ""
Dim attValueCodigoProduto As String = ""
Dim attValueFerramenta As String = ""
Dim attValueNomeProduto As String = ""
Dim attValueProjectDate As String = ""
Dim attValueProjectName As String = ""
attValueBO = _attributeBO
attValueCodigoProduto = _attributeCodigoProduto
attValueFerramenta = _attributeFerramenta
attValueNomeProduto = _attributeNomeProduto
attValueProjectDate = _attributeProjectDate
attValueProjectName = _attributeProjectName
workPart.SetAttribute(attTitleBO, attValueBO)
workPart.SetAttribute(attTitleCodigoProduto, attValueCodigoProduto)
workPart.SetAttribute(attTitleFerramenta, attValueFerramenta)
workPart.SetAttribute(attTitleNomeProduto, attValueNomeProduto)
workPart.SetAttribute(attTitleProjectDate, attValueProjectDate)
workPart.SetAttribute(attTitleProjectName, attValueProjectName)
workPart.SetUserAttribute("BO", -1, myForm.AttributeBO, Update.Option.Later)
workPart.SetUserAttribute("Codigo_Produto", -1, myForm.AttributeCodigoProduto, Update.Option.Later)
workPart.SetUserAttribute("Ferramenta", -1, myForm.AttributeFerramenta, Update.Option.Later)
workPart.SetUserAttribute("Nome_Produto", -1, myForm.AttributeNomeProduto, Update.Option.Later)
workPart.SetUserAttribute("Project_Date", -1, myForm.AttributeProjectDate, Update.Option.Later)
workPart.SetUserAttribute("Project_Name", -1, myForm.AttributeProjectName, Update.Option.Later)
For Each myPart As Part In myAsmInfo.AllUniqueParts
myPart.SetAttribute("BO", myForm.AttributeBO)
myPart.SetAttribute("Codigo_Produto", myForm.AttributeCodigoProduto)
myPart.SetAttribute("Ferramenta", myForm.AttributeFerramenta)
myPart.SetAttribute("Nome_Produto", myForm.AttributeNomeProduto)
myPart.SetAttribute("Project_Date", myForm.AttributeProjectDate)
myPart.SetAttribute("Project_Name", myForm.AttributeProjectName)
Next
End Sub
End Module
'-----------------------------------------------------------------------------------------------
'--------------------FINAL DO MODULO PRINCIPAL--------------------------------------------------
Public Class Form1
Private _frmTitle As String
Public Property FormTitle() As String
Get
Return _frmTitle
End Get
Set(ByVal value As String)
_frmTitle = value
End Set
End Property
Private _frmAttributeTitle As String
Public Property AttributeTitle() As String
Get
Return _frmAttributeTitle
End Get
Set(ByVal value As String)
_frmAttributeTitle = value
End Set
End Property
Private _frmAttributeBO As String
Public Property AttributeBO() As String
Get
Return _frmAttributeBO
End Get
Set(ByVal value As String)
_frmAttributeBO = value
End Set
End Property
Private _frmAttributeCodigoProduto As String
Public Property AttributeCodigoProduto() As String
Get
Return _frmAttributeCodigoProduto
End Get
Set(ByVal value As String)
_frmAttributeCodigoProduto = value
End Set
End Property
Private _frmAttributeFerramenta As String
Public Property AttributeFerramenta() As String
Get
Return _frmAttributeFerramenta
End Get
Set(ByVal value As String)
_frmAttributeFerramenta = value
End Set
End Property
Private _frmAttributeNomeProduto As String
Public Property AttributeNomeProduto() As String
Get
Return _frmAttributeNomeProduto
End Get
Set(ByVal value As String)
_frmAttributeNomeProduto = value
End Set
End Property
Private _frmAttributeProjectDate As String
Public Property AttributeProjectDate() As String
Get
Return _frmAttributeProjectDate
End Get
Set(ByVal value As String)
_frmAttributeProjectDate = value
End Set
End Property
Private _frmAttributeProjectName As String
Public Property AttributeProjectName() As String
Get
Return _frmAttributeProjectName
End Get
Set(ByVal value As String)
_frmAttributeProjectName = value
End Set
End Property
'------------------------------------------------------------------------------------------------------------
Private _canceled As Boolean = False
Public ReadOnly Property Canceled() As Boolean
Get
Return _canceled
End Get
End Property
'-----------------------------------------------------------------------------------------------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = _frmTitle
TextBox_BO.Text = _frmAttributeBO
TextBox_CodigoProduto.Text = _frmAttributeCodigoProduto
TextBox_Ferramenta.Text = _frmAttributeFerramenta
TextBox_NomeProduto.Text = _frmAttributeNomeProduto
TextBox_ProjectDate.Text = _frmAttributeProjectDate
TextBox_ProjectName.Text = _frmAttributeProjectName
End Sub
'-------------------------------------------------------------------------------------------------------------------
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
_canceled = True
Me.Close()
End Sub
'---------------------------------------------------------------------------------------------------------------
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
_frmAttributeBO = TextBox_BO.Text.ToUpper
_frmAttributeCodigoProduto = TextBox_CodigoProduto.Text.ToUpper
_frmAttributeFerramenta = TextBox_Ferramenta.Text.ToUpper
_frmAttributeNomeProduto = TextBox_NomeProduto.Text.ToUpper
_frmAttributeProjectDate = TextBox_ProjectDate.Text.ToUpper
_frmAttributeProjectName = TextBox_ProjectName.Text.ToUpper
Me.Close()
End Sub
End Class
'----------windows form------------------------------------------------------
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label5 = New System.Windows.Forms.Label()
Me.Label6 = New System.Windows.Forms.Label()
Me.TextBox_BO = New System.Windows.Forms.TextBox()
Me.TextBox_Ferramenta = New System.Windows.Forms.TextBox()
Me.TextBox_NomeProduto = New System.Windows.Forms.TextBox()
Me.TextBox_CodigoProduto = New System.Windows.Forms.TextBox()
Me.TextBox_ProjectName = New System.Windows.Forms.TextBox()
Me.TextBox_ProjectDate = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'btnOK
'
Me.btnOK.Location = New System.Drawing.Point(82, 200)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(75, 23)
Me.btnOK.TabIndex = 7
Me.btnOK.Text = "OK"
Me.btnOK.UseVisualStyleBackColor = True
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(177, 200)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(75, 23)
Me.btnCancel.TabIndex = 8
Me.btnCancel.Text = "Cancel"
Me.btnCancel.UseVisualStyleBackColor = True
'
'Label1 'Textos de identificacao
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 22)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(38, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "BO"
Me.Label1.UseMnemonic = False
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(12, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(58, 13)
Me.Label2.TabIndex = 0
Me.Label2.Text = "Ferramenta"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(12, 74)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(43, 13)
Me.Label3.TabIndex = 0
Me.Label3.Text = "Nome do produto"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(12, 99)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(51, 13)
Me.Label4.TabIndex = 0
Me.Label4.Text = "Codigo do produto"
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(12, 125)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(37, 13)
Me.Label5.TabIndex = 0
Me.Label5.Text = "Projetista"
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(12, 151)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(37, 13)
Me.Label6.TabIndex = 0
Me.Label6.Text = "Data do projeto"
'
'TextBox_BO
'
Me.TextBox_BO.Location = New System.Drawing.Point(112, 22)
Me.TextBox_BO.Name = "TextBox_BO"
Me.TextBox_BO.Size = New System.Drawing.Size(149, 20)
Me.TextBox_BO.TabIndex = 1
'
'TextBox_Ferramenta
'
Me.TextBox_Ferramenta.Location = New System.Drawing.Point(112, 48) 'posicao xy caixa texto entrada
Me.TextBox_Ferramenta.Name = "TextBox_Ferramenta"
Me.TextBox_Ferramenta.Size = New System.Drawing.Size(149, 20)
Me.TextBox_Ferramenta.TabIndex = 2
'
'TextBox_NomeProduto
'
Me.TextBox_NomeProduto.Location = New System.Drawing.Point(112, 74)
Me.TextBox_NomeProduto.Name = "TextBox_NomeProduto"
Me.TextBox_NomeProduto.Size = New System.Drawing.Size(149, 20)
Me.TextBox_NomeProduto.TabIndex = 3
'
'TextBox_CodigoProduto
'
Me.TextBox_CodigoProduto.Location = New System.Drawing.Point(112, 99)
Me.TextBox_CodigoProduto.Name = "TextBox_CodigoProduto"
Me.TextBox_CodigoProduto.Size = New System.Drawing.Size(149, 20)
Me.TextBox_CodigoProduto.TabIndex = 4
'
'TextBox_ProjectName
'
Me.TextBox_ProjectName.Location = New System.Drawing.Point(112, 125)
Me.TextBox_ProjectName.Name = "TextBox_ProjectName"
Me.TextBox_ProjectName.Size = New System.Drawing.Size(149, 20)
Me.TextBox_ProjectName.TabIndex = 5
'
'TextBox_ProjectDate
'
Me.TextBox_ProjectDate.Location = New System.Drawing.Point(112, 151)
Me.TextBox_ProjectDate.Name = "TextBox_ProjectDate"
Me.TextBox_ProjectDate.Size = New System.Drawing.Size(149, 20)
Me.TextBox_ProjectDate.TabIndex = 6
'
'Form1 Formato caixa de dialogo
'
Me.AcceptButton = Me.btnOK
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) 'escala xy da janela (quanto mior o valor, menor a jnela)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(337, 231) 'tamanho XY da janela
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.TextBox_BO)
Me.Controls.Add(Me.TextBox_Ferramenta)
Me.Controls.Add(Me.TextBox_NomeProduto)
Me.Controls.Add(Me.TextBox_CodigoProduto)
Me.Controls.Add(Me.TextBox_ProjectName)
Me.Controls.Add(Me.TextBox_ProjectDate)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
Me.Text = "Menu"
Me.ResumeLayout(False)
Me.PerformLayout()
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
End Sub
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents TextBox_BO As System.Windows.Forms.TextBox
Friend WithEvents TextBox_Ferramenta As System.Windows.Forms.TextBox
Friend WithEvents TextBox_NomeProduto As System.Windows.Forms.TextBox
Friend WithEvents TextBox_CodigoProduto As System.Windows.Forms.TextBox
Friend WithEvents TextBox_ProjectName As System.Windows.Forms.TextBox
Friend WithEvents TextBox_ProjectDate As System.Windows.Forms.TextBox
End Class
'------------------------------------Programa de leitor de informacoes--------------------------------
Public Class NXJ_Assembly_info
#Region "Private Variables"
Private Const Version As String = "0.1.1"
Private _theSession As Session = Session.GetSession()
Private _theUfSession As UFSession = UFSession.GetUFSession
Private _components As New List(Of Assemblies.Component)
Private _uniqueParts As New List(Of Part)
Private _allComponents As New List(Of Assemblies.Component)
Private _allUniqueParts As New List(Of Part)
Private _notLoaded As New List(Of String)
Private lg As LogFile = _theSession.LogFile
#End Region
#Region "Properties"
Private _isTCRunning As Boolean
Public ReadOnly Property IsTCRunning() As Boolean
Get
Return _isTCRunning
End Get
End Property
Private _thePart As Part = Nothing
Public Property Part() As Part
Get
Return _thePart
End Get
Set(ByVal value As Part)
_thePart = value
'Me.GetInfo()
Me.GetAllInfo()
End Set
End Property
Public ReadOnly Property AllComponents() As List(Of Component)
Get
Return _allComponents
End Get
End Property
Public ReadOnly Property AllUniqueParts() As List(Of Part)
Get
Return _allUniqueParts
End Get
End Property
Public ReadOnly Property Components As List(Of Component)
Get
Return _components
End Get
End Property
Public ReadOnly Property UniqueParts As List(Of Part)
Get
Return _uniqueParts
End Get
End Property
Public ReadOnly Property NotLoaded As List(Of String)
Get
Return _notLoaded
End Get
End Property
#End Region
Public Sub New()
lg.WriteLine("")
lg.WriteLine("~ NXJournaling.com: NXJ_Assembly_info object created ~")
lg.WriteLine(" ~~ Version: " & Version & " ~~")
lg.WriteLine(" ~~ Timestamp of run: " & DateTime.Now.ToString & " ~~")
lg.WriteLine("NXJ_Assembly_info Sub New()")
'determine if we are running under TC or native
_theUfSession.UF.IsUgmanagerActive(_isTCRunning)
lg.WriteLine("IsTcRunning: " & _isTCRunning.ToString)
lg.WriteLine("exiting Sub New")
lg.WriteLine("")
End Sub
Private Sub GetAllInfo()
'get all component info from assembly (all levels)
lg.WriteLine("Sub GetAllInfo()")
Try
Dim c As ComponentAssembly = Part.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)
lg.WriteLine(" part has components")
'*** end of code to process root component
lg.WriteLine(" calling GetAllComponentChildren")
GetAllComponentChildren(c.RootComponent)
Else
'*** insert code to process piece part, part has no components
lg.WriteLine(" part has no components")
End If
Catch ex As NXException
lg.WriteLine("Sub GetAllInfo error: " & ex.ErrorCode)
lg.WriteLine(" " & ex.Message)
End Try
lg.WriteLine("exiting Sub GetAllInfo()")
End Sub
Private Sub GetAllComponentChildren(ByVal comp As Component)
For Each child As Component In comp.GetChildren()
lg.WriteLine(child.DisplayName)
'*** insert code to process component or subassembly
If Me.LoadComponent(child) Then
_allComponents.Add(child)
Dim tempPart As Part = child.Prototype.OwningPart
If Not _allUniqueParts.Contains(tempPart) Then
_allUniqueParts.Add(tempPart)
End If
Else
'component could not be loaded
End If
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies
'*** 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
Me.GetAllComponentChildren(child)
Next
End Sub
Private Sub GetInfo()
'get top level component info from assembly (no recursion)
lg.WriteLine("Sub GetInfo()")
Try
Dim c As ComponentAssembly = Part.ComponentAssembly
If Not IsNothing(c.RootComponent) Then
'*** insert code to process 'root component' (assembly file)
lg.WriteLine(" part has components")
'*** end of code to process root component
lg.WriteLine(" calling GetComponentChildren")
Me.GetComponentChildren(c.RootComponent)
Else
'*** insert code to process piece part, part has no components
lg.WriteLine(" part has no components")
End If
Catch ex As NXException
lg.WriteLine("Sub GetInfo error: " & ex.ErrorCode)
lg.WriteLine(" " & ex.Message)
End Try
lg.WriteLine("exiting GetInfo()")
End Sub
Private Sub GetComponentChildren(ByVal comp As Component)
For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
_components.Add(child)
Dim tempPart As Part = child.Prototype.OwningPart
If Not _uniqueParts.Contains(tempPart) Then
_uniqueParts.Add(tempPart)
End If
'*** end of code to process component or subassembly
If child.GetChildren.Length <> 0 Then
'*** this is a subassembly, add code specific to subassemblies
'*** 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
Next
End Sub
Private Function LoadComponent(ByVal theComponent As Component) As Boolean
lg.WriteLine("Sub LoadComponent()")
Dim thePart As Part = theComponent.Prototype.OwningPart
Dim partName As String = ""
Dim refsetName As String = ""
Dim instanceName As String = ""
Dim origin(2) As Double
Dim csysMatrix(8) As Double
Dim transform(3, 3) As Double
Try
If thePart.IsFullyLoaded Then
'component is fully loaded
Else
'component is partially loaded
End If
lg.WriteLine(" component: " & theComponent.DisplayName & " is already partially or fully loaded")
lg.WriteLine(" return: True")
lg.WriteLine("exiting Sub LoadComponent()")
lg.WriteLine("")
Return True
Catch ex As NullReferenceException
'component is not loaded
Try
lg.WriteLine(" component not loaded, retrieving part information")
_theUfSession.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)
lg.WriteLine(" component part file: " & partName)
Dim theLoadStatus As PartLoadStatus
_theSession.Parts.Open(partName, theLoadStatus)
If theLoadStatus.NumberUnloadedParts > 0 Then
If theLoadStatus.NumberUnloadedParts > 1 Then
lg.WriteLine(" problem loading " & theLoadStatus.NumberUnloadedParts.ToString & " components")
Else
lg.WriteLine(" problem loading 1 component")
End If
Dim allReadOnly As Boolean = True
For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1
lg.WriteLine("part name: " & theLoadStatus.GetPartName(i))
lg.WriteLine("part status: " & theLoadStatus.GetStatus(i))
If theLoadStatus.GetStatus(i) = 641058 Then
'read-only warning, file loaded ok
Else
'641044: file not found
allReadOnly = False
If Not _notLoaded.Contains(partName) Then
_notLoaded.Add(partName)
End If
End If
lg.WriteLine("status description: " & theLoadStatus.GetStatusDescription(i))
lg.WriteLine("")
Next
If allReadOnly Then
lg.WriteLine(" read-only warnings only")
lg.WriteLine(" return: True")
Return True
Else
'warnings other than read-only...
lg.WriteLine(" return: False")
lg.WriteLine("exiting Sub LoadComponent()")
lg.WriteLine("")
Return False
End If
Else
lg.WriteLine(" component(s) loaded successfully")
lg.WriteLine(" return: True")
lg.WriteLine("exiting Sub LoadComponent()")
lg.WriteLine("")
Return True
End If
Catch ex2 As NXException
lg.WriteLine(" Load error: " & ex2.Message)
lg.WriteLine(" error code: " & ex2.ErrorCode)
lg.WriteLine(" return: False")
lg.WriteLine("exiting Sub LoadComponent()")
lg.WriteLine("")
If ex2.Message.ToLower = "file not found" Then
If Not _notLoaded.Contains(partName) Then
_notLoaded.Add(partName)
End If
End If
Return False
End Try
Catch ex As NXException
lg.WriteLine(" Error in Sub LoadComponent: " & ex.Message)
lg.WriteLine(" return: False")
lg.WriteLine("exiting Sub LoadComponent()")
lg.WriteLine("")
Return False
End Try
End Function
End Class]