Showing results for 
Search instead for 
Do you mean 
Reply

How to get the drawing sheet which has sheet number 1of x

Hi ,

 

Is there any way to find out the drawing sheet which contains the sheet number 1

3 REPLIES

Re: How to get the drawing sheet which has sheet number 1of x

This will work, if your sheet names have a space in front of the number, and if you do not have more than 9 sheets in the part file.  You can tweak the string in the "...Contains()" filter if you need to, or add another conditional to screen out Sheet 10, Sheet 11...etc.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Drawings
Imports NXOpen.UF

Module find_sheet_1

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

    Sub Main()

        Dim dispPart As Part = theSession.Parts.Display

        Dim allDwgs() As DrawingSheet = dispPart.DrawingSheets.ToArray()

        For Each thisDwg In allDwgs
            If thisDwg.Name.Contains(" 1") Then
                Echo("Found Drawing Sheet: " & thisDwg.Name())
                ' Open the sheet whose name contains " 1"
                thisDwg.Open()
            End If
        Next

    End Sub

    Sub Echo(ByVal output As String)

        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module

Re: How to get the drawing sheet which has sheet number 1of x

If you are using the drawing sheet attributes to do the "SHEET n OF m"

Then you need to use the sheet NUMBER (not the sheet name)

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

For Each dwg As DrawingSheet In theSession.Parts.Work.DrawingSheets
	Dim drawingSheetBuilder1 As NXOpen.Drawings.DrawingSheetBuilder
	drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(dwg)
	lw.WriteLine(drawingSheetBuilder1.Name)    ' NOT this
	lw.WriteLine(drawingSheetBuilder1.Number)  ' THIS
drawingSheetBuilder1.Destroy()
Next

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: How to get the drawing sheet which has sheet number 1of x

Ken is correct - the example above does not allow for the situation where drawings are deleted and new ones are created.  That can result in a situation where you have a sheet that SAYS "Sheet 1 of 4" in the title block, but has a name like "Sheet 3".

 

So using the number from the builder will ensure you get the one that says "Sheet 1..." in the title block.

 

Replace the Main in the example above with this:

 

    Sub Main()

        Dim dispPart As Part = theSession.Parts.Display

        For Each dwg As DrawingSheet In dispPart.DrawingSheets

            Dim drawingSheetBuilder1 As NXOpen.Drawings.DrawingSheetBuilder
            drawingSheetBuilder1 = dispPart.DrawingSheets.DrawingSheetBuilder(dwg)
            If drawingSheetBuilder1.Number.Equals("1") Then
                dwg.Open()
            End If
            drawingSheetBuilder1.Destroy()

        Next

    End Sub

 

Thanks Ken!