×
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

Reference Sets in NX 7.5

Reference Sets in NX 7.5

Reference Sets in NX 7.5

(OP)
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

RE: Reference Sets in NX 7.5

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

RE: Reference Sets in NX 7.5

(OP)
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

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