Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal to change layers based on category names.

Status
Not open for further replies.

JAYDEE66

Aerospace
Jan 6, 2020
13
I have several macros that change the layer settings based on the category names. They work regardless of the layers I want turned on and off.
I wanted to start using journals to accomplish this however when the category name is selected the journal file has the layer numbers not the layer category.

here is an example

' NX 12.0.0.27
' Journal created by jdower on Mon Jan 6 11:25:00 2020 Central Standard Time
'
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Format->Layer Settings...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

theSession.SetUndoMarkName(markId1, "Layer Settings Dialog")

Dim stateArray1(6) As NXOpen.Layer.StateInfo
stateArray1(0) = New NXOpen.Layer.StateInfo(1, NXOpen.Layer.State.Selectable)
stateArray1(1) = New NXOpen.Layer.StateInfo(100, NXOpen.Layer.State.Selectable)
stateArray1(2) = New NXOpen.Layer.StateInfo(101, NXOpen.Layer.State.Selectable)
stateArray1(3) = New NXOpen.Layer.StateInfo(110, NXOpen.Layer.State.Selectable)
stateArray1(4) = New NXOpen.Layer.StateInfo(111, NXOpen.Layer.State.Selectable)
stateArray1(5) = New NXOpen.Layer.StateInfo(112, NXOpen.Layer.State.Selectable)
stateArray1(6) = New NXOpen.Layer.StateInfo(113, NXOpen.Layer.State.Selectable)
workPart.Layers.ChangeStates(stateArray1, False)

theSession.SetUndoMarkName(markId1, "Layer Settings")

theSession.DeleteUndoMark(markId1, Nothing)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

thanks in advance for any help
 
Replies continue below

Recommended for you

Once you have a reference to a layer category, you can use its .GetMemberLayers method to access the layers in the category. The code below looks for the "Curves" layer category then makes all the member layers selectable.

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module4
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim layerStateInfo As New List(Of Layer.StateInfo)

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "make 'Curves' layers selectable"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)


        For Each temp As Layer.Category In theSession.Parts.Work.LayerCategories

            If Not temp.Name.ToUpper = "CURVES" Then
                Continue For
            End If

            For Each layNum As Integer In temp.GetMemberLayers
                'lw.WriteLine("  " & layNum.ToString)
                layerStateInfo.Add(New Layer.StateInfo(layNum, Layer.State.Selectable))
            Next

        Next

        theSession.Parts.Work.Layers.ChangeStates(layerStateInfo.ToArray, False)

        lw.Close()

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Thank you that works perfectly. Can you help me in addition to this?
I should have been more specific. I want to switch the layers in a category based on it being selectable or invisible.

ex: if the layers in the category are selectable make them invisible.
if the layers in the category are invisible make them selectable.

your help is greatly appreciated. I have been trying to figure this out for quite some time now.

thank you
 
Do any of your categories contain multiple layers?
If so, there are 3 starting possibilities (ignoring the "visible only" layer option):
[ul]
[li]All the layers are selectable[/li]
[li]All the layers are invisible[/li]
[li]Some mix of the above[/li]
[/ul]

The first 2 cases are fairly easy - toggle the visibility/selectability of all layers. The code above shows how to get the layers contained in a particular layer category. Once you have a layer number you are interested in, you can use the layer manager to query its state. If all the layers are "work layer" or "selectable", you will need to change the work layer then change them all to "hidden". If they are all "hidden", change them all to "selectable".

However, you need to decide what you want the journal to do in the 3rd case. Make all layers selectable? Make them all invisible? Toggle the individual layers? Warn the user and exit? Something else?

Also, what should the journal do if it runs into a layer that is "visible only" (visible but not selectable)?

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

Part and Inventory Search

Sponsor