×
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

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.

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?

RE: A journal to able to place things on reference sets based on their layer.

Something like this?

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 Module 

www.nxjournaling.com

RE: A journal to able to place things on reference sets based on their layer.

(OP)
That was exactly what I needed. Thank you.

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 Module 

RE: A journal to able to place things on reference sets based on their layer.

Assuming you have a reference to your reference set named: theReferenceSet, the following should work

CODE

theReferenceSet.RemoveObjectsFromReferenceSet(theReferenceSet.AskAllDirectMembers()) 

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

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