Hide Table of Contents

Print Drawing Example (VB.NET)

This example shows how to print the active drawing document.

'------------------------------------------------------------------
' Preconditions:
' 1. Verify that the specified drawing exists.
' 2. Open the Immediate window.
'
' Postconditions: 
' 1. Prints the drawing to your default printer using the 
'    specified page setup and print specification.
' 2. Inspect the Immediate window.
'
' NOTE: Because the model is used elsewhere, do not save changes.
'------------------------------------------------------------------
 
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Dim swModel As ModelDoc2
    Dim swModelDocExt As ModelDocExtension
    Dim swPageSetup As PageSetup
    Dim printSpec As PrintSpecification
    Dim drawing As String
    Dim errors As Integer
    Dim warnings As Integer
    Dim footerTextNumber As String
    Dim footerTextCount As String
    Dim footerText As String
 
    Sub main()
 
        drawing = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\advdrawings\foodprocessor.slddrw"
        swModel = swApp.OpenDoc6(drawing, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
 
        'Set up page's footer text
        swModelDocExt = swModel.Extension
        swModelDocExt.UsePageSetup = swPageSetupInUse_e.swPageSetupInUse_Document
        swPageSetup = swModel.PageSetup
        footerTextNumber = swPageSetup.GetHeaderFooterString(swStandardHeaderFooterPageSetupTexts_e.swHeaderFooterText_PageNumber)
        footerTextCount = swPageSetup.GetHeaderFooterString(swStandardHeaderFooterPageSetupTexts_e.swHeaderFooterText_PageCount)
        footerText = (footerTextNumber & " of " & footerTextCount)
        swPageSetup.CenterFooter = footerText
 
        'Create a print specification
        printSpec = swModelDocExt.GetPrintSpecification
        printSpec.ConvertToHighQuality = True
        printSpec.AddPrintRange(1, 1)
        printSpec.FromScale = 1.5
        printSpec.ToScale = 0.5
        printSpec.ScaleMethod = swPrintSelectionScaleFactor_e.swPrintSelection
        printSpec.PrinterQueue = ""
        printSpec.PrintToFile = False
 
        Debug.Print("Printing specifications:")
        Debug.Print("  Collate: " & printSpec.Collate)
        Debug.Print("  Convert to high quality: " & printSpec.ConvertToHighQuality)
        Debug.Print("  Current sheet: " & printSpec.CurrentSheet)
        Debug.Print("  From scale: " & printSpec.FromScale)
        Debug.Print("  To scale: " & printSpec.ToScale)
        Debug.Print("  Number of copies: " & printSpec.NumberOfCopies)
        Debug.Print("  Print background: " & printSpec.PrintBackground)
        Debug.Print("  Print cross hatch on out-of-date views: " & printSpec.PrintCrossHatchOnOutOfDateViews)
        Debug.Print("  Printer queue: " & printSpec.PrinterQueue)
        Debug.Print("  Print white items black: " & printSpec.PrintWhiteItemsBlack)
        Debug.Print("  Selection as defined in swPrintSelectionScaleFactor_e: " & printSpec.ScaleMethod)
        Debug.Print("  Total sheet count: " & printSpec.SheetCount)
        Debug.Print("  X origin: " & printSpec.XOrigin)
        Debug.Print("  Y origin: " & printSpec.YOrigin)
 
        'Print the drawing to your default printer
        swModelDocExt.PrintOut4("""", printSpec)
 
        printSpec.RestoreDefaults()
        printSpec.ResetPrintRange()
 
    End Sub
 
    Public swApp As SldWorks
 
End Class


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Print Drawing Example (VB.NET)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2017 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.