×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Assign part attribute to assembly files - journal

Assign part attribute to assembly files - journal

Assign part attribute to assembly files - journal

(OP)
I'm using the code below to add attributes to work part. Could somebody help me modify this code to assign attributes to every part in assembly.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms

Module Module1

    Dim theSession As Session = Session.GetSession()
    Public workPart As Part = theSession.Parts.Work

    Sub Main()

        Dim myDialog As New Dialog1
        myDialog.myPart = workPart.FullPath
        myDialog.ShowDialog()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module


Public Class Dialog1
    Public myPart As String
    Private myAttributeTitle(2) As String

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK

        Try
            workPart.SetAttribute(myAttributeTitle(0), TextBox1.Text)
        Catch ex As Exception
            MsgBox(myAttributeTitle(0) & " : " & ex.Message)
        End Try

        Try
            workPart.SetAttribute(myAttributeTitle(1), TextBox2.Text)
        Catch ex As Exception
            MsgBox(myAttributeTitle(1) & " : " & ex.Message)
        End Try

     
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Dialog1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.Text = myPart
        myAttributeTitle(0) = "NAME"
        myAttributeTitle(1) = "DATE"
        Dim currentDate As String = Nothing

        currentDate = Format(Today, "dd.MM.yyyy")

  
            TextBox1.Text = ""
        Label1.Text = myAttributeTitle(0)

           TextBox2.Text = currentDate
        Label2.Text = myAttributeTitle(1)

    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Dialog1
    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.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.OK_Button = New System.Windows.Forms.Button()
        Me.Cancel_Button = New System.Windows.Forms.Button()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.TableLayoutPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'TableLayoutPanel1
        '
        Me.TableLayoutPanel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.TableLayoutPanel1.ColumnCount = 2
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Controls.Add(Me.OK_Button, 0, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.Cancel_Button, 1, 0)
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(277, 122)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 1
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(146, 29)
        Me.TableLayoutPanel1.TabIndex = 0
        '
        'OK_Button
        '
        Me.OK_Button.Anchor = System.Windows.Forms.AnchorStyles.None
        Me.OK_Button.Location = New System.Drawing.Point(3, 3)
        Me.OK_Button.Name = "OK_Button"
        Me.OK_Button.Size = New System.Drawing.Size(67, 23)
        Me.OK_Button.TabIndex = 0
        Me.OK_Button.Text = "OK"
        '
        'Cancel_Button
        '
        Me.Cancel_Button.Anchor = System.Windows.Forms.AnchorStyles.None
        Me.Cancel_Button.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Cancel_Button.Location = New System.Drawing.Point(76, 3)
        Me.Cancel_Button.Name = "Cancel_Button"
        Me.Cancel_Button.Size = New System.Drawing.Size(67, 23)
        Me.Cancel_Button.TabIndex = 1
        Me.Cancel_Button.Text = "Cancel"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(9, 19)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(134, 26)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Attribute:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(149, 23)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(234, 20)
        Me.TextBox1.TabIndex = 2
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(149, 49)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(234, 20)
        Me.TextBox2.TabIndex = 4
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(9, 45)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(134, 26)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Attribute:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight

        'Dialog1
        '
        Me.AcceptButton = Me.OK_Button
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.CancelButton = Me.Cancel_Button
        Me.ClientSize = New System.Drawing.Size(435, 163)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.TableLayoutPanel1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Dialog1"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Dialog1"
        Me.TableLayoutPanel1.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
    Friend WithEvents OK_Button As System.Windows.Forms.Button
    Friend WithEvents Cancel_Button As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label

End Class 

RE: Assign part attribute to assembly files - journal

Hi,
What version of NX you are on? I guess you can do it OOTB starting NX8.5 (sorry may be NX8 also but my memory is a bit weak).
Select all the components in the ANT and specify the attributes in the Properties tab.
Best Regards
Kapil Sharma

RE: Assign part attribute to assembly files - journal

(OP)
I'm on NX6. Does anybody know how to do it (or have an example) using journal?

RE: Assign part attribute to assembly files - journal

Hi,
Could you please search some old posts on this forum. I think I have seen similar query last year.And there was a vb code furnished for the same.
Regards
Kapil

RE: Assign part attribute to assembly files - journal

(OP)
I found this code. What do I need to change if I want it to ask me only once for the attribute value and assign it in every component?

CODE

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module assign_attributes_to_component_parts

    Public s As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = s.ListingWindow

    Sub Main()
        Dim dispPart As Part = s.Parts.Display
        Try
            Dim part1 As Part
            part1 = s.Parts.Work
            'LabelPart(part1)
            Dim c As ComponentAssembly = part1.ComponentAssembly
            Walk(c.RootComponent, 0)
        Catch e As Exception
            s.ListingWindow.WriteLine("Failed: " & e.ToString)
        End Try
    End Sub
    Sub Walk(ByVal c As Component, ByVal 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 fileName As String = ""
            Dim value1 As String = ""
            Dim title1 As String = "NAME"
            value1 = InputBox("NAME: ", value1)
            prototype.SetAttribute(title1, value1)
            For Each child In children
                Walk(child, level + 1)
            Next
        End If
    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
End Module 

Once again I would like to ask for your help in editing the code I posted earlier. I'm not skilled enough to do it myself.

RE: Assign part attribute to assembly files - journal

Are you looking to add this attribute to the component or the underlying part file?

www.nxjournaling.com

RE: Assign part attribute to assembly files - journal

(OP)
I want to add this attribute to every part file in assembly.

RE: Assign part attribute to assembly files - journal

Try this code. I don't have NX6 to test with, but it seems to work in 7.5.

www.nxjournaling.com

RE: Assign part attribute to assembly files - journal

(OP)
Thanks. It works as expected.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources