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