×
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

Open a part from the part family using nx open ?

Open a part from the part family using nx open ?

Open a part from the part family using nx open ?

(OP)
I have written a VB.NET code to identify the part which needs to be opened from the part family based on attributes value provided by the user.
Even though i am able to fetch the part name , i am unable to open the part from the part family in NX session using code.

My code is as below , please help !!!

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module report_part_family_members_with_wrapper
    Public Const OS_PART_NAME As String = "OS_PART_NAME"
    Public Const OFFSET_STRAIGHT As String = "OFFSET_STRAIGHT"
    Public Const LENGTH_H_DIM As String = "LENGTH_H_DIM"
    Public Const OFFSET_STRAIGHT_Value As String = "OFFSET 65MM"
    Public Const LENGTH_H_DIM_Value As String = "275MM"
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim dispPart As Part = theSession.Parts.Display
        Dim workPart As Part = theSession.Parts.Work
        Dim theUFSession As UFSession = UFSession.GetUFSession()
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim iColPartName As Integer = -1
        Dim iColOffsetStraight As Integer = -1
        Dim iColLength As Integer = -1

        Dim is_family_template As Boolean
        theUFSession.Part.IsFamilyTemplate(dispPart.Tag, is_family_template)
        lw.WriteLine("Part Family Template: " & is_family_template.ToString())

        If is_family_template = False Then
            Return
        End If

        Dim family_count As Integer
        Dim families As Tag()
        theUFSession.Part.AskFamilies(dispPart.Tag, family_count, families)
        lw.WriteLine("Part Families: " & family_count.ToString())

        For ii As Integer = 0 To family_count - 1
            'lw.WriteLine("Part Familiy: " & families(ii).ToString())

            Dim family_data As UFFam.FamilyData
            theUFSession.Fam.AskFamilyData(families(ii), family_data)

            Dim member_count As Integer = family_data.member_count
            lw.WriteLine("Part Family Name: " & family_data.name)
            'lw.WriteLine("Part Family Members: " & member_count.ToString())


            If iColPartName = -1 Then
                For jj As Integer = 0 To family_data.attribute_count - 1
                    Dim attribute_data As UFFam.AttributeData
                    theUFSession.Fam.AskAttributeData(family_data.attributes(jj), attribute_data)
                    If attribute_data.name = OS_PART_NAME Then
                        iColPartName = jj
                    ElseIf attribute_data.name = OFFSET_STRAIGHT Then
                        iColOffsetStraight = jj
                    ElseIf attribute_data.name = LENGTH_H_DIM Then
                        iColLength = jj
                    End If
                Next
            End If

            'For jj As Integer = 0 To family_data.attribute_count - 1
            'Dim attribute_data As UFFam.AttributeData
            'theUFSession.Fam.AskAttributeData(family_data.attributes(jj), attribute_data)

            'Dim member_data As UFFam.MemberData
            'theUFSession.Fam.AskMemberColumnData(families(ii), jj, member_data)

            For kk As Integer = 0 To member_count - 1
                Dim member_row_data As UFFam.MemberData
                theUFSession.Fam.AskMemberRowData(families(ii), kk, member_row_data)
                If member_row_data.values(iColOffsetStraight) = OFFSET_STRAIGHT_Value And member_row_data.values(iColLength) = LENGTH_H_DIM_Value Then
                    lw.WriteLine("OFFSET_STRAIGHT_Value: " & OFFSET_STRAIGHT_Value)
                    lw.WriteLine("LENGTH_H_DIM_Value: " & LENGTH_H_DIM_Value)
                    lw.WriteLine("Matching Part Found: " & member_row_data.values(iColPartName))
                    'Dim part1 As Part = CType(theSession.Parts.FindObject(member_row_data.values(iColPartName)), Part)
                    Exit For
                End If
            Next

            'For kk As Integer = 0 To member_data.value_count - 1
            '    lw.WriteLine("Member: " & member_data.values(kk))
            'Next

            'End If
            'Next

            'Next
        Next

    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function
End Module

Thanks !!!

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