×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Anyone have a macro to print all drawings in open files?

Anyone have a macro to print all drawings in open files?

Anyone have a macro to print all drawings in open files?

(OP)
I create my assemblies and drawings per the master model format. The assemblies I create can have 7-10 drawings total all in separate files. If I open all the drawings in drafting, does anyone has a macro, grip, or vb that will print all the drawings in the open files with a few (one) clicks?
I have tried recording macros, but I haven't figured out how to make it generic enough to work on other files.

RE: Anyone have a macro to print all drawings in open files?

Print or plot?

www.nxjournaling.com

RE: Anyone have a macro to print all drawings in open files?

(OP)
Print to current printer.

RE: Anyone have a macro to print all drawings in open files?

Try the code below:

CODE

Option Strict Off  
Imports System  
Imports System.Windows.Forms  
Imports NXOpen  

Module Module1  

    Dim theSession As Session = Session.GetSession()  
    Dim defaultPrinterName As String = ""  

    Sub Main()  

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

        Dim printerSettings As New System.Drawing.Printing.PrinterSettings  
        Try  
            defaultPrinterName = printerSettings.PrinterName  
        Catch ex As System.Exception  
            defaultPrinterName = ""  
        Finally  
            printerSettings = Nothing  
        End Try  

        If String.IsNullOrEmpty(defaultPrinterName) Then  
            MessageBox.Show("No default printer found.", "Printer error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
            Return  
        End If  

        For Each tempPart As Part In theSession.Parts  

            If tempPart.IsFullyLoaded Then  
 'lw.WriteLine("part: " & tempPart.FullPath)
                ChangeDisplayPart(tempPart)  

                For Each tempSheet As Drawings.DrawingSheet In tempPart.DrawingSheets  
 'lw.WriteLine("  sheet: " & tempSheet.Name)
                    tempPart.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, tempSheet)  

                    PrintSheet(tempPart, tempSheet)  

                Next  
 'lw.WriteLine("")

            End If  

            ChangeDisplayPart(workPart)  

        Next  

 'lw.Close()

    End Sub  

    Sub PrintSheet(ByVal thePart As Part, ByVal theSheet As Drawings.DrawingSheet)  

        Dim printBuilder1 As PrintBuilder  
        printBuilder1 = thePart.PlotManager.CreatePrintBuilder()  

        printBuilder1.PrinterText = defaultPrinterName  

 'printer settings, change as desired
        printBuilder1.Copies = 1  
        printBuilder1.ThinWidth = 1.0  
        printBuilder1.NormalWidth = 2.0  
        printBuilder1.ThickWidth = 3.0  
        printBuilder1.Output = PrintBuilder.OutputOption.WireframeBlackWhite  
        printBuilder1.RasterImages = True  
        printBuilder1.Orientation = PrintBuilder.OrientationOption.Landscape  
        printBuilder1.Paper = PrintBuilder.PaperSize.Letter  

        Dim paper1 As PrintBuilder.PaperSize  
        paper1 = printBuilder1.Paper  


        Dim sheets1(0) As NXObject  
        sheets1(0) = theSheet  
        printBuilder1.SourceBuilder.SetSheets(sheets1)  

        Dim nXObject1 As NXObject  

        Try  
            nXObject1 = printBuilder1.Commit()  
        Catch ex As NXException  
 'log error
        Finally  
            printBuilder1.Destroy()  
        End Try  

    End Sub  

    Public Sub ChangeDisplayPart(ByVal myPart As Part)  

 'make the given component the display part
        Dim markId1 As Session.UndoMarkId  
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Display Part")  

        Try  
            Dim partLoadStatus1 As PartLoadStatus  
            Dim status1 As PartCollection.SdpsStatus  
            status1 = theSession.Parts.SetDisplay(myPart, False, False, partLoadStatus1)  

            partLoadStatus1.Dispose()  
        Catch ex As NXException  
 'log error
            theSession.UndoToMark(markId1, "Display Part")  
        Finally  
            theSession.DeleteUndoMark(markId1, "Display Part")  
        End Try  

    End Sub  

    Public Function GetUnloadOption(ByVal dummy As String) As Integer  

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

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

 'Unloads the image explicitly, via an unload dialog
 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
 '-------------------------------

    End Function  

End Module 

www.nxjournaling.com

RE: Anyone have a macro to print all drawings in open files?

(OP)
Thank you, cowski! It works great for printers. I am going to try and modifiy it to do PDFs.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources