Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Reference Sets with Journaling

Status
Not open for further replies.

kr7530

Automotive
Aug 9, 2011
130
Can anybody help me with this? I am working on a journal that that checks for specific reference sets and if found it clears them of all objects. Then I create and/or populate them with user selections. The problem I am having is that the program works fine if it has to create the reference sets. If runs without errors if the reference sets already exist but it populates them incorrectly.
It should be 2 entities in the "FORMS" ref set, 1 entity in the "LWR" and 1 in the "UPR". I am getting 0 in the "FORMS" and in the "LWR" but 2 in the "UPR"
Any help would be greatly appropriated!
Thanks,
Kevin
NX8.0

'------------------Create and/or Populate Reference Sets----------------------------------------------------------------------
Dim myRefSet11 As ReferenceSet
Dim myRefSet22 As ReferenceSet
Dim myRefSet33 As ReferenceSet
Dim theReferenceSet11 As ReferenceSet
Dim theReferenceSet22 As ReferenceSet
Dim theReferenceSet33 As ReferenceSet
Dim found as Boolean = False
Dim found2 as Boolean = False
Dim found3 as Boolean = False


'------------------------------Forms Reference Set Population----------------------------------------
For Each myRefSet11 In workPart.GetAllReferenceSets()
If myRefSet11.Name.ToUpper() = "FORMS" Then
found = True
End If
Next

If Not found Then
theReferenceSet11 = workPart.CreateReferenceSet()
theReferenceSet11.SetName("FORMS")
theReferenceSet11.AddObjectsToReferenceSet(mySelections)
theReferenceSet11.AddObjectsToReferenceSet(mySelections2)
Else If found = True
theReferenceSet11 = myRefSet11
theReferenceSet11.AddObjectsToReferenceSet(mySelections)
theReferenceSet11.AddObjectsToReferenceSet(mySelections2)

End If

'------------------------------Lower Reference Set Population----------------------------------------
For Each myRefSet22 In workPart.GetAllReferenceSets()
If myRefSet22.Name.ToUpper() = "LWR" Then
found2 = True
End If
Next

If Not found2 Then
theReferenceSet22 = workPart.CreateReferenceSet()
theReferenceSet22.SetName("LWR")
theReferenceSet22.AddObjectsToReferenceSet(mySelections)
Else If found2 = True
theReferenceSet22 = myRefSet22
theReferenceSet22.AddObjectsToReferenceSet(mySelections)

End If
'------------------------------Upper Reference Set Population----------------------------------------
For Each myRefSet33 In workPart.GetAllReferenceSets()
If myRefSet33.Name.ToUpper() = "UPR" Then
found3 = True
End If
Next

If Not found3 Then
theReferenceSet33 = workPart.CreateReferenceSet()
theReferenceSet33.SetName("UPR")
theReferenceSet33.AddObjectsToReferenceSet(mySelections2)
Else If found3 = True
theReferenceSet33 = myRefSet33
theReferenceSet33.AddObjectsToReferenceSet(mySelections2)
End If

End Sub
 
Replies continue below

Recommended for you

Code:
For Each myRefSet11 In workPart.GetAllReferenceSets()
If myRefSet11.Name.ToUpper() = "FORMS" Then
found = True
End If
Next

When this loop finishes, myRefSet11 will point to the last reference set in the collection. For instance, let's say you have ref1, ref2, FORMS, and ref3; at the end of the loop, myRefSet11 will point to ref3. Later, you set
Code:
theReferenceSet11 = myRefSet11
so now, theReferenceSet11 also points to ref3.

Instead, try this:
Code:
For Each myRefSet11 In workPart.GetAllReferenceSets()
  If myRefSet11.Name.ToUpper() = "FORMS" Then
    theReferenceSet11 = myRefSet11
    found = True
    'stop looping, we found it
    exit for
  End If
Next

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor