×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journal Read Attribute

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

you would need the program to search through all the attributes in the file. When the attribute name is equal to the one you want then you can write the value of the attribute to a variable. I am not able to share the code for the program, but If you do a search on this forum you should find it.


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

Here's a quick example (for NX 7.5), it will prompt you to select a component and look for a string attribute titled "attribute_title" - change this line to the attribute you are interested in before running. If the attribute is found, it will assign the value to a string variable and print that to the information window.

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 Module 

www.nxjournaling.com

RE: Journal Read Attribute

Cowski, your example shows how to retrieve an attribute, but as Denis asked, how would you retrieve the descriptive part name? I've looked through the documentation, and I haven't found any method to get it. The descriptive part name is what is shown on the Header Description line in Properties > Part File tab. It can be edited via Files > Utilities > Edit work file header, but how can this be done with NXopen/journaling?

NX8.5 Win7SP1 64bit i7-3770K@4.3Ghz 16GB Quadro2000

RE: Journal Read Attribute

The following code will determine if TC is running; if so, it will write the following attributes to the listing window:
  • 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 Module 

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources