Journal Read Attribute
Journal Read Attribute
(OP)
This may be something simple that I am overlooking but how would I read a component attribute through a journal and assign it to a string variable? The main purpose being able to read the descriptive part name.
Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17





RE: Journal Read Attribute
If it is a certain component in the assembly, then you will have to cycle through your components in your assembly to find each part name.
But if you do have an assembly and you want a part name attribute from one of the components then a journal would not be a best option. In your assembly you can go to expressions and insert object attribute and select your component. Then in your attributes you can link it to the expression.
RE: Journal Read Attribute
CODE
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 Modulewww.nxjournaling.com
RE: Journal Read Attribute
NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000
RE: Journal Read Attribute
- DB_PART_NO
- DB_PART_REV
- DB_PART_DESC
I'm 95% sure these are common to all TC installations (someone please correct me if I'm wrong).If TC is not running, it will return the user's part name style preference, file name, and part description (found in the header).
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module1 ' Explicit Activation ' This entry point is used to activate the application explicitly Sub Main() Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim IsTcEng As Boolean = False theUfSession.UF.IsUgmanagerActive(IsTcEng) lw.WriteLine("TC running? " & IsTcEng.ToString) If IsTcEng Then Dim strPartNo As String strPartNo = workPart.GetStringAttribute("DB_PART_NO") lw.WriteLine("part number: " & strPartNo) Dim strRevision As String strRevision = workPart.GetStringAttribute("DB_PART_REV") lw.WriteLine("part revision: " & strRevision) Dim strPartDesc As String strPartDesc = workPart.GetStringAttribute("DB_PART_DESC") lw.WriteLine("part description: " & strPartDesc) Else lw.WriteLine("part name style: " & theSession.Preferences.Assemblies.PartNameStyle.ToString) If theSession.Preferences.Assemblies.PartNameStyle = Preferences.SessionAssemblies.PartNameOption.SpecifiedAttributes Then lw.WriteLine(" attribute: " & theSession.Preferences.Assemblies.PartNameAttribute) Try lw.WriteLine(" attribute value: " & workPart.GetStringAttribute(theSession.Preferences.Assemblies.PartNameAttribute)) Catch ex As NXException If ex.ErrorCode = 512008 Then lw.WriteLine(" attribute value: <not set>") Else lw.WriteLine("error: " & ex.ErrorCode & ", " & ex.Message) End If End Try End If Dim partNo As String partNo = IO.Path.GetFileNameWithoutExtension(workPart.FullPath) lw.WriteLine("part number: " & partNo) 'get description from header (File -> Utilities -> edit work/other part header) Dim partDesc As String theUfSession.Part.AskDescription(workPart.Tag, partDesc) lw.WriteLine("part description: " & partDesc) End If End Sub 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 Modulewww.nxjournaling.com