Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

SwagOne

Mechanical
May 21, 2012
8
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.
 
Replies continue below

Recommended for you

Try the code below:

Code:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.Windows.Forms  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
    [COLOR=blue]Dim[/color] defaultPrinterName [COLOR=blue]As String =[/color] ""  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  
        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
 [COLOR=green]'lw.Open()[/color]

        [COLOR=blue]Dim[/color] printerSettings [COLOR=blue]As New[/color] System.Drawing.Printing.PrinterSettings  
        [COLOR=blue]Try[/color]  
            defaultPrinterName [COLOR=blue]=[/color] printerSettings.PrinterName  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] System.Exception  
            defaultPrinterName [COLOR=blue]=[/color] ""  
        [COLOR=blue]Finally[/color]  
            printerSettings [COLOR=blue]= Nothing[/color]  
        End [COLOR=blue]Try[/color]  

        [COLOR=blue]If[/color] String.IsNullOrEmpty(defaultPrinterName) [COLOR=blue]Then[/color]  
            MessageBox.Show("No [COLOR=blue]default[/color] printer found.", "Printer error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
            [COLOR=blue]Return[/color]  
        End [COLOR=blue]If[/color]  

        [COLOR=blue]For Each[/color] tempPart [COLOR=blue]As[/color] Part [COLOR=blue]In[/color] theSession.Parts  

            [COLOR=blue]If[/color] tempPart.IsFullyLoaded [COLOR=blue]Then[/color]  
 [COLOR=green]'lw.WriteLine("part: " & tempPart.FullPath)[/color]
                ChangeDisplayPart(tempPart)  

                [COLOR=blue]For Each[/color] tempSheet [COLOR=blue]As[/color] Drawings.DrawingSheet [COLOR=blue]In[/color] tempPart.DrawingSheets  
 [COLOR=green]'lw.WriteLine("  sheet: " & tempSheet.Name)[/color]
                    tempPart.DraftingViews.UpdateViews(Drawings.DraftingViewCollection.ViewUpdateOption.OutOfDate, tempSheet)  

                    PrintSheet(tempPart, tempSheet)  

                [COLOR=blue]Next[/color]  
 [COLOR=green]'lw.WriteLine("")[/color]

            End [COLOR=blue]If[/color]  

            ChangeDisplayPart(workPart)  

        [COLOR=blue]Next[/color]  

 [COLOR=green]'lw.Close()[/color]

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Sub[/color] PrintSheet(ByVal thePart [COLOR=blue]As[/color] Part, [COLOR=blue]ByVal[/color] theSheet [COLOR=blue]As[/color] Drawings.DrawingSheet)  

        [COLOR=blue]Dim[/color] printBuilder1 [COLOR=blue]As[/color] PrintBuilder  
        printBuilder1 [COLOR=blue]=[/color] thePart.PlotManager.CreatePrintBuilder()  

        printBuilder1.PrinterText [COLOR=blue]=[/color] defaultPrinterName  

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

        [COLOR=blue]Dim[/color] paper1 [COLOR=blue]As[/color] PrintBuilder.PaperSize  
        paper1 [COLOR=blue]=[/color] printBuilder1.Paper  


        [COLOR=blue]Dim[/color] sheets1(0) [COLOR=blue]As[/color] NXObject  
        sheets1(0) [COLOR=blue]=[/color] theSheet  
        printBuilder1.SourceBuilder.SetSheets(sheets1)  

        [COLOR=blue]Dim[/color] nXObject1 [COLOR=blue]As[/color] NXObject  

        [COLOR=blue]Try[/color]  
            nXObject1 [COLOR=blue]=[/color] printBuilder1.Commit()  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] NXException  
 [COLOR=green]'log error[/color]
        [COLOR=blue]Finally[/color]  
            printBuilder1.Destroy()  
        End [COLOR=blue]Try[/color]  

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Public Sub[/color] ChangeDisplayPart(ByVal myPart [COLOR=blue]As[/color] Part)  

 [COLOR=green]'make the given component the display part[/color]
        [COLOR=blue]Dim[/color] markId1 [COLOR=blue]As[/color] Session.UndoMarkId  
        markId1 [COLOR=blue]=[/color] theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Display Part")  

        [COLOR=blue]Try[/color]  
            [COLOR=blue]Dim[/color] partLoadStatus1 [COLOR=blue]As[/color] PartLoadStatus  
            [COLOR=blue]Dim[/color] status1 [COLOR=blue]As[/color] PartCollection.SdpsStatus  
            status1 [COLOR=blue]=[/color] theSession.Parts.SetDisplay(myPart, False, False, partLoadStatus1)  

            partLoadStatus1.Dispose()  
        [COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] NXException  
 [COLOR=green]'log error[/color]
            theSession.UndoToMark(markId1, "Display Part")  
        [COLOR=blue]Finally[/color]  
            theSession.DeleteUndoMark(markId1, "Display Part")  
        End [COLOR=blue]Try[/color]  

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Public Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As String[/color]) [COLOR=blue]As Integer[/color]  

 [COLOR=green]'Unloads the image when the NX session terminates[/color]
        GetUnloadOption [COLOR=blue]=[/color] NXOpen.Session.LibraryUnloadOption.AtTermination  

 [COLOR=green]'----Other unload options-------[/color]
 [COLOR=green]'Unloads the image immediately after execution within NX[/color]
 [COLOR=green]'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately[/color]

 [COLOR=green]'Unloads the image explicitly, via an unload dialog[/color]
 [COLOR=green]'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly[/color]
 [COLOR=green]'-------------------------------[/color]

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Thank you, cowski! It works great for printers. I am going to try and modifiy it to do PDFs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor