Altojoe
New member
- Mar 16, 2013
- 23
TO copy a attribute of a Part (For Example say callout) to a clipboard in following format <W!xxxxx@CALLOUT>
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'NXJournaling.com
'October 29, 2014
'
'select component, copy attribute reference string to clipboard
'NX 7.5 and below only!
Option Strict Off
Imports System
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, undoMarkName)
Dim myComponent As Assemblies.Component
If SelectComponent("Select component", myComponent) = Selection.Response.Cancel Then
Return
End If
'$$$ specify attribute title to get from component
Const myAttrTitle As String = "CALLOUT"
Dim myAttrValue As String
Dim output As String
Try
myAttrValue = myComponent.GetStringAttribute(myAttrTitle)
output = "<W!" & myComponent.Tag.ToString & "@" & myAttrTitle & ">"
Clipboard.SetText(output)
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'attribute not found
MessageBox.Show("Attribute '" & myAttrTitle & "' not found, journal exiting", "Attribute not found", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
Else
theSession.UndoToMark(markId1, undoMarkName)
MessageBox.Show(ex.Message, "Error: " & ex.ErrorCode, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Finally
End Try
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
'----Other unload options-------
'Unloads the image immediately after execution within NX
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module