Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myComponent As Assemblies.Component
Dim myCompAttr As String
Do Until SelectComponent("select a component", myComponent) = Selection.Response.Cancel
Try
'assign attribute to string variable, change "attribute_title" as needed
myCompAttr = myComponent.GetStringAttribute("attribute_title")
'write string variable to listing window
lw.WriteLine("Attribute Value: " & myCompAttr)
lw.WriteLine("")
Catch ex As NXException
If ex.ErrorCode = 512008 Then
MsgBox("Attribute not found")
Else
MsgBox(ex.ErrorCode.ToString & " : " & ex.Message)
End If
End Try
Loop
lw.Close()
End Sub
Function SelectComponent(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a component"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module