Brian1321
Mechanical
- Jul 6, 2021
- 1
Trying to pull Multiple attributes all from my workpart and bring it into Excel.
I can get it to pull one attribute but seem to be struggling to get anything more than one.
Code below. This only writes to Info window not excel:
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 CB_CUSTOMER As String = "CUSTOMER"
Dim attributeInfo As NXObject.AttributeInformation
If workPart.HasUserAttribute(CB_CUSTOMER, NXObject.AttributeType.String, -1) Then
attributeInfo = workPart.GetUserAttribute(CB_CUSTOMER, NXObject.AttributeType.String, -1)
lw.WriteLine("Job #: " & attributeInfo.StringValue)
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
I can get it to pull one attribute but seem to be struggling to get anything more than one.
Code below. This only writes to Info window not excel:
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 CB_CUSTOMER As String = "CUSTOMER"
Dim attributeInfo As NXObject.AttributeInformation
If workPart.HasUserAttribute(CB_CUSTOMER, NXObject.AttributeType.String, -1) Then
attributeInfo = workPart.GetUserAttribute(CB_CUSTOMER, NXObject.AttributeType.String, -1)
lw.WriteLine("Job #: " & attributeInfo.StringValue)
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