Showing results for 
Search instead for 
Did you mean: 

Keep the drafting view selected



         In NX 9 drafting I want to perform 2 or 3 operation on the view, like view setting then view dependant edit and later view boundary. But after performing each of these operation view gets deselected, hence I need to select it again. Is there any option such that the view is selected throught all there operation. I need it because I have macro for all these opreration. So I want to combine all the 3 macro.  


Re: Keep the drafting view selected

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Continuing your thread from the design forum


The code below allows you to select a drafting view. All it does is report the name of the view you selected, but you can perform other operations on the view as desired.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow

        Dim theDrftView As Drawings.DraftingView
        If SelectDraftingView("select drafting view", theDrftView) = Selection.Response.Cancel Then
        End If

        lw.WriteLine("view selected: " & theDrftView.Name)


    End Sub

    Function SelectDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a drafting view"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj As TaggedObject

        With selectionMask_array(0)
            .Type = UFConstants.UF_view_type
            .Subtype = UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selView = CType(selObj, Drawings.DraftingView)
            Return Selection.Response.Ok
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module