Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Reference Sets in NX 7.5

Status
Not open for further replies.

DesEngineer4

Mechanical
Feb 19, 2013
181
Hi all,

I am using the below journal to create a new reference set "S" and move all the assembly components to that reference set. And it will show the an error popup like reference set exists, if there is already a reference set 's'. But, I am facing a problem with this journal. If i execute this journal multiple times it was creating duplicate reference set as shown in attachment. Kindly advice me in resolving this issue.


Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")

        Dim referenceSet1 As ReferenceSet
        referenceSet1 = workPart.CreateReferenceSet()
        referenceSet1.SetName("S")
        'add all components (existing and future)
        referenceSet1.SetAddComponentsAutomatically(True, True)
        'create list variable for solid bodies
        Dim mySolids As List(Of Body) = New List(Of Body)
        'workPart.Bodies collection contains both solid and sheet bodies
        'filter out solid bodies and add them to the list
        For Each solid As Body In workPart.Bodies
            If solid.IsSolidBody Then
                mySolids.Add(solid)
            End If
        Next
        'add solid bodies to reference set
        referenceSet1.AddObjectsToReferenceSet(mySolids.ToArray)

    End Sub


    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

Thanks & Regards,
Sam
 
Replies continue below

Recommended for you

Check to see if the reference set exists before creating a new one with the same name.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create New Reference Set")
		
		Const newRefSetName As String = "S"
		Dim found as Boolean = False
		Dim myRefSet as ReferenceSet
		
		'check to see if reference set already exists
		For Each myRefSet In workPart.GetAllReferenceSets()
            If myRefSet.Name.ToUpper() = newRefSetName Then
				found = True
				Exit For
            End If
        Next
		
		Dim referenceSet1 As ReferenceSet
		
		If Not found Then
			'create new reference set
			referenceSet1 = workPart.CreateReferenceSet()
			referenceSet1.SetName(newRefSetName)
		Else
			'use the existing reference set
			referenceSet1 = myRefSet
		End If
		
        'add all components (existing and future)
        referenceSet1.SetAddComponentsAutomatically(True, True)
        'create list variable for solid bodies
        Dim mySolids As List(Of Body) = New List(Of Body)
        'workPart.Bodies collection contains both solid and sheet bodies
        'filter out solid bodies and add them to the list
        For Each solid As Body In workPart.Bodies
            If solid.IsSolidBody Then
                mySolids.Add(solid)
            End If
        Next
        'add solid bodies to reference set
        referenceSet1.AddObjectsToReferenceSet(mySolids.ToArray)

    End Sub


    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
 
Hi,

The above code is working fine..(Thanks for that)

I like to add another points to this code..

1. I need a notification window stating "REFERENCE SET S ALREADY EXISTS" (If already reference set s is created)

2. In the same way I need the notification window stating "REFERENCE SET S CREATED". (When this journal creating reference set s)

Thanks & Regards,
Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor