Hide Table of Contents

Get Drawing Sheets' Properties (VB.NET)

This example shows how to get the properties of a drawing's sheets.

'--------------------------------------------------------

' Preconditions: Specified drawing document exists.

'

' Postconditions: None.

'

' NOTE: Drawing sheet properties are printed to

' Immediate Window.

'----------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports SwDocumentMgr

Imports System

Imports System.Diagnostics

 

Partial Class SolidWorksMacro

 

    Public Sub main()

        Dim swClassFact As SwDocumentMgr.SwDMClassFactory

        Dim docMgrApp As SwDocumentMgr.SwDMApplication

        Dim docDrw As SwDocumentMgr.SwDMDocument13

        Dim res As SwDocumentMgr.SwDmDocumentOpenError

        swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")

        docMgrApp = swClassFact.GetApplication("Your_license_file")

        docDrw = docMgrApp.GetDocument("C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\advdrawings\foodprocessor.slddrw", SwDmDocumentType.swDmDocumentDrawing, True, res)

 

        Dim sheetNameVar As Object

        Dim sheetCount As Long

        sheetCount = docDrw.GetSheetCount

        sheetNameVar = docDrw.GetSheetNames

        Dim sheetName As String

        Dim sheetNameCount As Integer

        For sheetNameCount = LBound(sheetNameVar) To UBound(sheetNameVar)

            Dim formatName As String

            Dim status1 As swSheetFormatPathResult

            sheetName = sheetNameVar(sheetNameCount)

            status1 = docDrw.GetSheetFormatPath(sheetName, formatName)

            Debug.Print(sheetName & " ---- " & formatName & vbNewLine)

            Dim status2 As swSheetPropertiesResult

            Dim formatProp As Object

            status2 = docDrw.GetSheetProperties(sheetName, formatProp)

            Dim para As Double

            para = formatProp(0)

            Dim paperSize As String

            GetPaperSize(para, paperSize)

            Debug.Print("Paper Size = " & paperSize)

            Debug.Print("size = " & formatProp(1) & " x " & formatProp(2))

            Debug.Print("Scale = " & formatProp(3) & " : " & formatProp(4))

            Dim boolData As Boolean

            boolData = False

            If (formatProp(5) = 1) Then

                boolData = True

            End If

            Debug.Print("FirstAngle = " & boolData)

            Dim templateSize As String

            para = formatProp(6)

            GetTemplateSize(para, templateSize)

            Debug.Print("Template Size = " & templateSize)

            boolData = False

            If (formatProp(7) = 1) Then

                boolData = True

            End If

            Debug.Print("TemplateVisible = " & boolData)

            Debug.Print("===========================================")

        Next

        docDrw.CloseDoc()

    End Sub

 

    ''' <summary>

    ''' The SldWorks swApp variable is pre-assigned for you.

    ''' </summary>

    Public swApp As SldWorks

 

#Region "Helper Functions"

 

    Sub GetPaperSize(ByVal inpNum As Double, ByVal outPaperType As String)

        If (inpNum = 0) Then

            outPaperType = "swDwgPaperAsize"

        ElseIf (inpNum = 1) Then

            outPaperType = "swDwgPaperAsizeVertical"

        ElseIf (inpNum = 2) Then

            outPaperType = "swDwgPaperBsize"

        ElseIf (inpNum = 3) Then

            outPaperType = "swDwgPaperCsize"

        ElseIf (inpNum = 4) Then

            outPaperType = "swDwgPaperDsize"

        ElseIf (inpNum = 5) Then

            outPaperType = "swDwgPaperEsize"

        ElseIf (inpNum = 6) Then

            outPaperType = "swDwgPaperA4size"

        ElseIf (inpNum = 7) Then

            outPaperType = "swDwgPaperA4sizeVertical"

        ElseIf (inpNum = 8) Then

            outPaperType = "swDwgPaperA3size"

        ElseIf (inpNum = 9) Then

            outPaperType = "swDwgPaperA2size"

        ElseIf (inpNum = 10) Then

            outPaperType = "swDwgPaperA1size"

        ElseIf (inpNum = 11) Then

            outPaperType = "swDwgPaperA0size"

        ElseIf (inpNum = 12) Then

            outPaperType = "swDwgPapersUserDefined"

        End If

    End Sub

 

    Sub GetTemplateSize(ByVal inpNum As Double, ByVal outTemplateType As String)

        If (inpNum = 0) Then

            outTemplateType = "swDwgTemplateAsize"

        ElseIf (inpNum = 1) Then

            outTemplateType = "swDwgTemplateAsizeVertical"

        ElseIf (inpNum = 2) Then

            outTemplateType = "swDwgTemplateBsize"

        ElseIf (inpNum = 3) Then

            outTemplateType = "swDwgTemplateCsize"

        ElseIf (inpNum = 4) Then

            outTemplateType = "swDwgTemplateDsize"

        ElseIf (inpNum = 5) Then

            outTemplateType = "swDwgTemplateEsize"

        ElseIf (inpNum = 6) Then

            outTemplateType = "swDwgTemplateA4size"

        ElseIf (inpNum = 7) Then

            outTemplateType = "swDwgTemplateA4sizeVertical"

        ElseIf (inpNum = 8) Then

            outTemplateType = "swDwgTemplateA3size"

        ElseIf (inpNum = 9) Then

            outTemplateType = "swDwgTemplateA2size"

        ElseIf (inpNum = 10) Then

            outTemplateType = "swDwgTemplateA1size"

        ElseIf (inpNum = 11) Then

            outTemplateType = "swDwgTemplateA0size"

        ElseIf (inpNum = 12) Then

            outTemplateType = "swDwgTemplateCustom"

        ElseIf (inpNum = 13) Then

            outTemplateType = "swDwgTemplateNone"

        End If

    End Sub

 

#End Region

 

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:   Get Drawing Sheets Properties (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) 2011 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.