Part Attribute

Hello,

I am trying to write a journal that will read an attribute "A" and input the value into attribute "B". I am stuck right now though can anyone give me a snippet of code that will read the attribute "A" Value? I am able to do everything but that right now.

Thank you

What version of NX are you using?

What type of attribute is "A"; string, integer, other? Will "A" always be of the same type, or will it differ?

I am using NX9.0.3 The attribute will always be a string and it will never differ

The code below looks for an attribute named "TEST" on the workpart. If it is found, it will report the attribute value.

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const attributeName As String = "TEST"
Dim attributeInfo As NXObject.AttributeInformation

If workPart.HasUserAttribute(attributeName, NXObject.AttributeType.String, -1) Then
attributeInfo = workPart.GetUserAttribute(attributeName, NXObject.AttributeType.String, -1)
lw.WriteLine("attribute value: " & attributeInfo.StringValue)
Else
lw.WriteLine("the work part does not have an attribute named: " & attributeName)
End If

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module