A journal to able to place things on reference sets based on their layer.
A journal to able to place things on reference sets based on their layer.
(OP)
Hello,
I am looking for a solution to a problem I have been facing.
We have a some complex rules for what is supposed to be on specific reference sets. We already have a layering convention that captures the same type of information so I would like to take that and use it to make and populate several reference sets.
Something like take all objects on layer 35 and place them on the “access space” reference set.
Does anyone have any kind of code that might do this?
I am looking for a solution to a problem I have been facing.
We have a some complex rules for what is supposed to be on specific reference sets. We already have a layering convention that captures the same type of information so I would like to take that and use it to make and populate several reference sets.
Something like take all objects on layer 35 and place them on the “access space” reference set.
Does anyone have any kind of code that might do this?





RE: A journal to able to place things on reference sets based on their layer.
CODE
Option Strict Off Imports System Imports NXOpen Module Module1 Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Sub Main() If IsNothing(theSession.Parts.Work) Then 'active part required Return End If Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Const undoMarkName As String = "reference set from layer" Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) Const refSetLayer35 As String = "ACCESS SPACE" Try Dim myRefSet As ReferenceSet = CreateReferenceSet(refSetLayer35) Dim layer35Objects() As NXObject = workPart.Layers.GetAllObjectsOnLayer(35) myRefSet.AddObjectsToReferenceSet(layer35Objects) Catch ex As NXException theSession.UndoToMark(markId1, undoMarkName) MsgBox(ex.Message) Finally End Try lw.Close() End Sub Function CreateReferenceSet(ByVal refSetName As String) As ReferenceSet Dim theRefSets() As ReferenceSet = workPart.GetAllReferenceSets 'does the specified reference set exist? 'if so, return it For Each someRefSet As ReferenceSet In theRefSets If someRefSet.Name.ToUpper = refSetName.ToUpper Then Return someRefSet End If Next 'if we get here, the ref set does not exist 'create it Dim targetRefSet As ReferenceSet targetRefSet = workPart.CreateReferenceSet() targetRefSet.SetName(refSetName) Return targetRefSet End Function 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 Modulewww.nxjournaling.com
RE: A journal to able to place things on reference sets based on their layer.
I modified the code as follows and made a sub that places objects on the layer.
I need to find a function that will empty a particular reference set so that each time the script is run it makes sure that there is nothing on a particular reference set before populating it.
Any one have any ideas.
CODE --> VB
Option Strict Off Imports System Imports NXOpen Module Module1 Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work 'SetRefByLayer("ref set name", layer number) Sub Main() SetRefByLayer("ref set name", 100) end sub sub SetRefByLayer(ByVal referencesettosetto As String, ByVal layertosetthingsto As double) If IsNothing(theSession.Parts.Work) Then 'active part required Return End If Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Const undoMarkName As String = "reference set from layer" Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName) dim refSetLayer As String = referencesettosetto Try Dim myRefSet As ReferenceSet = CreateReferenceSet(refSetLayer) Dim layer35Objects() As NXObject = workPart.Layers.GetAllObjectsOnLayer(layertosetthingsto) myRefSet.AddObjectsToReferenceSet(layerObjects) Catch ex As NXException theSession.UndoToMark(markId1, undoMarkName) MsgBox(ex.Message) Finally End Try lw.Close() End sub Function CreateReferenceSet(ByVal refSetName As String) As ReferenceSet Dim theRefSets() As ReferenceSet = workPart.GetAllReferenceSets 'does the specified reference set exist? 'if so, return it For Each someRefSet As ReferenceSet In theRefSets If someRefSet.Name.ToUpper = refSetName.ToUpper Then Return someRefSet End If Next 'if we get here, the ref set does not exist 'create it Dim targetRefSet As ReferenceSet targetRefSet = workPart.CreateReferenceSet() targetRefSet.SetName(refSetName) Return targetRefSet End Function 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 ModuleRE: A journal to able to place things on reference sets based on their layer.
CODE
This line was taken from a journal I have that shows all the reference set members on screen and allows the user to select entities to add or deselect entities to remove from the reference set.
http://nxjournaling.com/content/show-reference-set...
www.nxjournaling.com