Hi, I hope someone can help me out.
I am a newbe on journaling.
I have made a Journal for creating "Reference Set".
I would like to have the possibility to ad lines and run it again.
There for i need help to run by the existing created reference set.
Thanks in advance, Hove.
NX 8.5
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Try
Dim referenceSet1 As ReferenceSet
referenceSet1 = workPart.CreateReferenceSet()
referenceSet1.SetName("test_1")
'add all components (existing and future)
referenceSet1.SetAddComponentsAutomatically(False, False)
Catch ex As NXException
If ex.ErrorCode = 650030 Then goto lab2 else goto lab2
lab2:
End Try
Try
Dim referenceSet2 As ReferenceSet
referenceSet2 = workPart.CreateReferenceSet()
referenceSet2.SetName("test_2")
'add all components (existing and future)
referenceSet2.SetAddComponentsAutomatically(False, False)
Catch ex As NXException
If ex.ErrorCode = 650030 Then goto lab3 else goto lab3
lab3:
End Try
Try
Dim referenceSet3 As ReferenceSet
referenceSet3 = workpart.CreateReferenceSet()
referenceSet3.SetName("test_3")
'add all components (existing and future)
referenceSet3.SetAddComponentsAutomatically(False, False)
Catch ex As NXException
If ex.ErrorCode = 650030 Then goto lab4 else goto lab4
lab4:
End Try
End sub
End Module
re: creating reference sets
The code below will attempt to create three reference sets in the work part. It begins by looking through the existing reference sets; if it finds an existing reference set with the given name, it will not create a new reference set. If no reference set with the given name exists, it will be created.
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'make a list of the reference set names that we want to create/use
Dim myRefSetNames As New List(Of String)
'add some ref set names
myRefSetNames.Add("test_1")
myRefSetNames.Add("test_2")
myRefSetNames.Add("test_3")
'iterate through the names we want to create
For Each tempRefSetName As String In myRefSetNames
lw.WriteLine("creating reference set: " & tempRefSetName)
Dim refSetExists As Boolean = False
'check through the existing reference sets to see if one with the name already exists
For Each tempRefSet As ReferenceSet In workPart.GetAllReferenceSets
If tempRefSet.Name.ToUpper = tempRefSetName.ToUpper Then
refSetExists = True
End If
Next
If refSetExists Then
'the reference set already exists, do nothing
lw.WriteLine(" reference set already exists")
Else
'ref set does not exist, create it
Dim referenceSet1 As ReferenceSet
referenceSet1 = workPart.CreateReferenceSet()
referenceSet1.SetName(tempRefSetName)
referenceSet1.SetAddComponentsAutomatically(False, False)
lw.WriteLine(" reference set created")
End If
lw.WriteLine("")
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Modify ''SetAddComponentsAutomatically''
If "refSetExists" it is possible to modify the '' referenceSet2.SetAddComponentsAutomatically '' option to (True, True) if not '' referenceSet2.SetAddComponentsAutomatically '' to (False, False)
Example:
Dim referenceSet2 As ReferenceSet
If refSetExists Then
'the reference set already exists, do nothing
If tempRefSetName = "TRUE" Then
referenceSet2.SetAddComponentsAutomatically (True, True)
lw.WriteLine ("The reference set:" & tempRefSetName & "exists")
else
referenceSet2.SetAddComponentsAutomatically (False, False)
lw.WriteLine ("The reference set:" & tempRefSetName & "does not exist")
End If
lw.WriteLine ("reference set already exists")
Regards!
Pat
re: add components automatically
The code sample has 2 If's and only 1 End If statement, so the code won't run as-is. However, it should be possible to change the "add components automatically" option on an existing reference set (which is what I think you are asking about, please correct me if I am wrong).
Yes,it's possible to change this option on an existing ref. set
Hi !
Yes,it's possible to change the "add components automatically" option on an existing reference set ?
Like:
If RefName= "True" Then
?????.add components automatically (True, True)
Else If
?????.add components automatically (False, False)
End if
I lack some knowledge to succeed in modifying your example so that it is functional, here is what I tried:
'----------------------------------------------
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'make a list of the reference set names that we want to create/use
Dim myRefSetNames As New List(Of String)
'add some ref set names
myRefSetNames.Add("TRUE")
myRefSetNames.Add("FALSE")
myRefSetNames.Add("BRUT")
'iterate through the names we want to create
For Each tempRefSetName As String In myRefSetNames
lw.WriteLine("creating reference set: " & tempRefSetName)
Dim refSetExists As Boolean = False
'check through the existing reference sets to see if one with the name already exists
For Each tempRefSet As ReferenceSet In workPart.GetAllReferenceSets
If tempRefSet.Name.ToUpper = tempRefSetName.ToUpper Then
refSetExists = True
End If
Next
Dim referenceSet1 As ReferenceSet
Dim referenceSet2 As ReferenceSet
If refSetExists Then
'the reference set already exists, do nothing
If tempRefSetName = "TRUE" Then
'tempRefSetName.SetAddComponentsAutomatically(True, True)
'referenceSet2 = workPart.CreateReferenceSet()
'referenceSet2.Name(tempRefSetName)
referenceSet2.SetAddComponentsAutomatically(True, True)
lw.WriteLine(" Le reference set: " & tempRefSetName & " existe")
Else
'referenceSet1.SetAddComponentsAutomatically(False, False)
lw.WriteLine(" Le reference set: " & tempRefSetName & " n'existe pas")
End If
lw.WriteLine(" reference set already exists")
Else
'ref set does not exist, create it
referenceSet1 = workPart.CreateReferenceSet()
referenceSet1.SetName(tempRefSetName)
If referenceSet1.Name = "TRUE" Then
referenceSet1.SetAddComponentsAutomatically(True, True)
Else
referenceSet1.SetAddComponentsAutomatically(False, False)
lw.WriteLine(" reference set created")
End If
End If
lw.WriteLine("")
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Pat
re: reference set
I made a few minor changes, try the code below:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Module Module78
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
'make a list of the reference set names that we want to create/use
Dim myRefSetNames As New List(Of String)
'add some ref set names
myRefSetNames.Add("TRUE")
myRefSetNames.Add("FALSE")
myRefSetNames.Add("BRUT")
'iterate through the names we want to create
For Each tempRefSetName As String In myRefSetNames
lw.WriteLine("creating reference set: " & tempRefSetName)
Dim refSetExists As Boolean = False
Dim referenceSet1 As ReferenceSet = Nothing
'check through the existing reference sets to see if one with the name already exists
For Each tempRefSet As ReferenceSet In workPart.GetAllReferenceSets
If tempRefSet.Name.ToUpper = tempRefSetName.ToUpper Then
refSetExists = True
referenceSet1 = tempRefSet
End If
Next
If refSetExists Then
lw.WriteLine(" Le reference set: " & tempRefSetName & " existe")
If tempRefSetName = "TRUE" Then
referenceSet1.SetAddComponentsAutomatically(True, True)
Else
referenceSet1.SetAddComponentsAutomatically(False, False)
End If
Else
'ref set does not exist, create it
lw.WriteLine(" Le reference set: " & tempRefSetName & " n'existe pas")
referenceSet1 = workPart.CreateReferenceSet()
referenceSet1.SetName(tempRefSetName)
If referenceSet1.Name = "TRUE" Then
referenceSet1.SetAddComponentsAutomatically(True, True)
Else
referenceSet1.SetAddComponentsAutomatically(False, False)
End If
lw.WriteLine(" reference set created")
End If
lw.WriteLine("")
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Thank you so much. This is
Thank you so much. This is working very good.
Do you now if it is possible to sort/arrange by name in "reference sets"?
If I start as so:
'add some ref set names
myRefSetNames.Add("test_a")
myRefSetNames.Add("test_b")
myRefSetNames.Add("test_m")
And later want this:
'add some ref set names
myRefSetNames.Add("test_a")
myRefSetNames.Add("test_b")
myRefSetNames.Add("test_c")
myRefSetNames.Add("test_m")
Then NX create as so:
test_a
test_b
test_m
test_c
I am working on a big assembly. So it can be difficult to now the names on all reference sets from the beginning.
Best regards Hove.
Hove
re: sort reference sets
Unfortunately, I know of no way to sort the existing reference sets within the dialog. I would encourage you to contact GTAC, they may be able to add this in as an enhancement in a future version.
Sort reference sets
Hi.
The answer from Siemens is that it is not possible right now in NX8.5 and 9.0
And they will not make it to those versions.
Our company has send a mail to Gtac as a note for improvement in the future versions.
Hove
re: sort reference sets
That's unfortunate; I was hoping there was an 'undocumented' trick that you could use. Thanks for the follow up.
Delete individual reference set
Is there any code to delete model reference set only
Neenad Sawant
Perfect ! It work !
Thank you for you help !
Regards!
Pat