Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

journal move to layer

Status
Not open for further replies.

Lars1978

Mechanical
Dec 30, 2015
327
Ha All,
Does anybody have a journal which makes me select de object to move to layer 2 and then make layer 2 invisible?

I've made a journal for this only the selection of the I can't figure out?

Lars


Lars
NX11.0.1.11 native
Solid Edge
Inventor
 
Replies continue below

Recommended for you

Hello,

Try this code:

Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports System.Collections
Imports System.Collections.Generic

Module layer_2

    Dim theSession As Session = Session.GetSession()
    Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager 

    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
    Dim lw As  ListingWindow = theSession.ListingWindow
    Dim newlayer as Integer = 2

    Sub Main()
	
        Dim selectedObjectsArray() As NXObject
        Selectbody(selectedObjectsArray)
	
	lw.open
	
        Dim BodyArray(selectedObjectsArray.Length - 1) As DisplayableObject


        For i As Integer = 0 To selectedObjectsArray.Length - 1
            BodyArray(i) = CType(selectedObjectsArray(i), DisplayableObject)

        Next

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

	Dim displayModification1 As DisplayModification
	displayModification1 = theSession.DisplayManager.NewDisplayModification()

        With displayModification1
	    .NewLayer = newlayer
            .Apply(bodyArray)
            .Dispose()
        End With

	Dim markId1 As Session.UndoMarkId
	markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

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

	Dim stateArray1(0) As Layer.StateInfo
	stateArray1(0) = New Layer.StateInfo(2, Layer.State.Hidden)
	workPart.Layers.ChangeStates(stateArray1, False)

	theSession.SetUndoMarkName(markId1, "Layer Settings")
	theSession.DeleteUndoMark(markId1, Nothing)

    End Sub

    Sub Selectbody(ByRef selectedObjects As NXObject())

        Dim ui As UI = NXOpen.UI.GetUI

        Dim message As String = "Select body"
        Dim title As String = "Selection"

        Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = False
        Dim response As Selection.Response

        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific

        Dim selectionMask_array(1) As Selection.MaskTriple
	With selectionMask_array(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY 
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY 
        End With

        With selectionMask_array(1)
            .Type = UFConstants.UF_solid_type
            .Subtype = 0
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY 
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY 
	End with

        response = ui.SelectionManager.SelectObjects(message, title, scope, _
                                         selectionAction, includeFeatures, _
                                     keepHighlighted, selectionMask_array, _
                                                      selectedObjects)

        If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
            Return

	else
		
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY

    End Function
End Module


With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor