Submitted by GervaldNik on Tue, 03/15/2016 - 10:45
Forums:
Part have a reference set "SOLIDS" and some other reference sets.
We need a code that adds in this reference set of all of the solid objects.
How i can do it in journal?
Part have a reference set "SOLIDS" and some other reference sets.
We need a code that adds in this reference set of all of the solid objects.
How i can do it in journal?
re: add solids to reference set
Before we throw code at this problem, I'd like to mention that NX can "automate" a reference set for you. In the customer defaults (Assemblies -> site standards -> reference sets), you can specify a model reference set name and tell NX to automatically add all the solid/sheet bodies. Perhaps you would like to investigate setting these options so that new files that you create will have this taken care of automatically.
Now, assuming that you have existing files that were not set up as above, you can create a journal to add all the existing solid bodies to a reference set. Journal code to create a new reference set and add all the solid bodies to it can be found here:
http://nxjournaling.com/comment/180#comment-180
It will probably need some tweaking for your purpose, but it shows how to access all of the solid bodies in the file and add them to a given reference set.
Done!
Thanks, I mixed information from the link above and get the desired result
'create list variable for solid bodies
Dim mySolids As List(Of Body) = New List(Of Body)
'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
Dim theRefSets() As ReferenceSet = workPart.GetAllReferenceSets
Const refSetName As String = "solids"
For Each someRefSet As ReferenceSet In theRefSets
If someRefSet.Name.ToUpper = refSetName.ToUpper Then
'remove all objects from reference set
someRefSet.RemoveObjectsFromReferenceSet(someRefSet.AskMembersInReferenceSet)
'add solid bodies to reference set
someRefSet.AddObjectsToReferenceSet(mySolids.ToArray)
End If
Next