Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Danlap on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a part from the part family using nx open ?

Status
Not open for further replies.

biw01

Automotive
Dec 31, 2011
152
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 !!!
 
Replies continue below

Recommended for you

Status
Not open for further replies.

Part and Inventory Search

Sponsor