Submitted by roger on Fri, 03/17/2017 - 09:26
Forums:
Good morning I need help with one Journal because I work in NX 9.0 and need to select one component in one assy and obtained the name, thickness of the attributes, some one could you help me
re: select component
The following code shows how to interactively select a component. I'm not sure what you mean by "thickness of the attributes"; if you can explain in detail what you need, we may be able to expand on this code.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module69
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim theComponent As Assemblies.Component = Nothing
If SelectComponent("select a component", theComponent) = Selection.Response.Cancel Then
Return
End If
lw.WriteLine("component display name: " & theComponent.DisplayName)
lw.WriteLine("component part path: " & theComponent.Prototype.OwningPart.FullPath)
lw.Close()
End Sub
Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) 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_component_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(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
End Module
Select Object And Obtain Information
Many thanks for the code, what I mean is that of the component we select I need to get some attributes of it, for example the name, thickness, material among other attributes
re: get attribute
Here's some code that gets an attribute named "thickness". You can use the same principle to get other attributes from the component.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module Module69
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim theComponent As Assemblies.Component = Nothing
If SelectComponent("select a component", theComponent) = Selection.Response.Cancel Then
Return
End If
lw.WriteLine("component display name: " & theComponent.DisplayName)
lw.WriteLine("component part path: " & theComponent.Prototype.OwningPart.FullPath)
Const testAttribute As String = "thickness"
Dim thicknessAtt As NXObject.AttributeInformation = Nothing
If theComponent.HasUserAttribute(testAttribute, NXObject.AttributeType.Any, -1) Then
thicknessAtt = theComponent.GetUserAttribute(testAttribute, NXObject.AttributeType.Any, -1)
lw.WriteLine("""" & testAttribute & """" & " attribute found")
lw.WriteLine(" attribute value: " & thicknessAtt.StringValue)
Else
lw.WriteLine("component does NOT have an attribute named: " & testAttribute)
End If
lw.Close()
End Sub
Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) 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_component_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(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
End Module
Thank you very much for the
Thank you very much for the journal