cancel
Showing results for 
Search instead for 
Did you mean: 

Return visible Objects from inactive Drawing-Sheet

Experimenter
Experimenter

Hi,

is there a way to find all visible object from a certain drafting sheet that is currently not open/visible? For the current view there is NXOpen.UF.View.AskVisibleObjects.

 

Short sample with sheet As Drawings.DrawingSheet:

Dim visob As Integer = 0
Dim clippedinteg As Integer = 0
Dim visobtags() As NXOpen.Tag = Nothing
Dim clipobtags() As NXOpen.Tag = Nothing
theUFSession.View.AskVisibleObjects(sheet.View.Tag, visob, visobtags, clippedinteg, clipobtags)

 

But this will fail on views which are on non-active sheets. I could loop over all sheets and open each sheet, but I want to hide this action from the user and even want to get this objects if the drafting mode is not active. Does the API (NX 7.5) offer any methods for my needs?

 

 

1 REPLY

Re: Return visible Objects from inactive Drawing-Sheet

Phenom
Phenom

I'd suggest suppressing the display updates while you run your code, then turn updates back on.

 

The following code is a crude illustration, it doesn't do any real error checking (switch to the drafting application before running the code, I had some weird behavior when I tried it from modeling).

 

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

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

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

        If workPart.DrawingSheets.ToArray.Length = 0 Then
            Return
            'no sheets to process
        End If

        Dim drawingDispObjs As New List(Of Array)
        Dim sheetDispObjs() As DisplayableObject

        Dim curSheet As Drawings.DrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet

        'suppress display updates
        theUfSession.Disp.SetDisplay(UFConstants.UF_DISP_SUPPRESS_DISPLAY)

        For Each theSheet As Drawings.DrawingSheet In workPart.DrawingSheets
            theSheet.Open()
            sheetDispObjs = theSheet.View.AskVisibleObjects()
            drawingDispObjs.Add(sheetDispObjs)
        Next

        curSheet.Open()

        'unsuppress display updates
        theUfSession.Disp.SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
        'regenerate display
        theUfSession.Disp.RegenerateDisplay()

        Dim i As Integer = 0
        For Each theArray As Array In drawingDispObjs
            lw.WriteLine("sheet ID: " & i.ToString & " contains " & theArray.Length.ToString & " visible objects")
            i += 1
        Next

        lw.Close()

    End Sub

End Module