Cancel
Showing results for 
Search instead for 
Did you mean: 

Get Drafting View associated with Drawing Dimensions

Pioneer
Pioneer

Looking for a quick way to get the Drafting Views assoicated with Dimensions.  The .getViews method under the Dimension object is giving the PMI view.  I want the drafting view on the drawing sheet.

 

 

4 REPLIES

Re: Get Drafting View associated with Drawing Dimensions

Phenom
Phenom

Use UFView.AskViewDependentStatus to get the view dependent status and view name.

Suresh
Production: NX10.0.3 Developing: NX11.0.2.7, NX12.0.1
Development: C++, C# .Net, VB .Net, KF

Re: Get Drafting View associated with Drawing Dimensions

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

The associativities of the dimension object will tell you which drafting view(s) the dimension is associated with. A short, example journal is below (PMI dimensions were not tested as I do not currently have access to a PMI license).

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

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

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

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

        lw.Open()

        Dim myDim1 As Annotations.Dimension

        If SelectDimension("Select first dimension", myDim1) = Selection.Response.Cancel Then
            Return
        End If

        Dim myDimAssociativity As Annotations.Associativity

        For i As Integer = 1 To myDim1.NumberOfAssociativities
            lw.WriteLine("associativity: " & i.ToString)

            myDimAssociativity = myDim1.GetAssociativity(i)
            Dim myView As View = myDimAssociativity.ObjectView

            lw.WriteLine("associated view: " & myView.Name)

        Next


        lw.Close()

    End Sub

    Function SelectDimension(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a dimension"
        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

        With selectionMask_array(0)
            .Type = UFConstants.UF_dimension_type
            .Subtype = UFConstants.UF_dim_horizontal_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
            Return Selection.Response.Ok
        Else
            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

Re: Get Drafting View associated with Drawing Dimensions

Pioneer
Pioneer

Hi Cowski,

 

This works great when have regular dimension that have been creating in the drafting application.  But, this fails to get the drafting view of a PMI dimension that was inherited from the modeling space.

 

 

Highlighted

Re: Get Drafting View associated with Drawing Dimensions

Pioneer
Pioneer

This is what I had to do to distingish between a regular drafting dimension and an inherited PMI dimension into drafting.  Using GetAssociativity method of the Inhertied PMI dimension was returning nothing for the view.  Therefore, I used AskViewDependentStatus to get the name of the drafting view and then use findObject to get the drafting view object.  Funny thing is if I where to use AskViewDependentStatus on an inherited PMI dimension it'll return the modeling space view name and not the drafting space view name.

Dim myDimensionPreferences As DimensionPreferences = Nothing
        Dim myMainTextLines() As String = Nothing
        Dim myDualTextLines() As String = Nothing
        Dim myView As NXOpen.Drawings.DraftingView
        Dim myProjectedView As NXOpen.Drawings.ProjectedView = Nothing
        Dim myViewSettingsBuilder As NXOpen.Drawings.EditViewSettingsBuilder
        Dim counter As Integer = 0

        Dim ListOfDraftingViewNames As New List(Of String)
        For Each aView As NXOpen.Drawings.DraftingView In workPart.DraftingViews.ToArray()
            ListOfDraftingViewNames.Add(aView.Name)
        Next

        For Each aDimension As Dimension In workPart.Dimensions

            myView = aDimension.GetAssociativity(1).ObjectView

            '  MyView is nothing when there is a PMI inherited dimension.  We need to use the UFunc approach.
            If myView Is Nothing Then
                Dim viewName As String = Nothing
                Dim status As Integer = Nothing
                theUFSession.View.AskViewDependentStatus(aDimension.Tag, status, viewName)
                'check is view is a drafting view
                If Not ListOfDraftingViewNames.Contains(viewName) Then
                    Continue For
                End If
                myView = CType(workPart.DraftingViews.FindObject(viewName), NXOpen.Drawings.BaseView)
            End If

            counter = counter + 1
            Echo("Counter = " & counter)

            myDimensionPreferences = aDimension.GetDimensionPreferences()
            aDimension.GetDimensionText(myMainTextLines, myDualTextLines)
            Echo("Dimension = " & myMainTextLines(0))

            myViewSettingsBuilder = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder({myView})
            Echo(" Using EditViewSettingsBuilder.ViewStyle.")
            If myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.ScaleType = ViewScaleBuilder.Type.Expression Then
                Echo("  Scale Type = Expression")
            ElseIf myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.ScaleType = ViewScaleBuilder.Type.Ratio Then
                Echo("  Scale Type = Ratio")
            End If
            If myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.ScaleType = ViewScaleBuilder.Type.Expression Then
                Echo("Expression Value = " & myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.Expression.RightHandSide)
                Echo("Expression Name = " & myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.Expression.Name)
            ElseIf myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.ScaleType = ViewScaleBuilder.Type.Ratio Then
                Echo("  Denominator = " + myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.Denominator.ToString())
                Echo("  Numerator = " + myViewSettingsBuilder.ViewStyle.ViewStyleGeneral.Scale.Numerator.ToString())
            End If
            
        Next