SolidWorksAPI 获取工程图的图幅
时间: 2024-01-11 11:05:23 浏览: 160
要获取 SOLIDWORKS 工程图的图幅,你可以使用 SOLIDWORKS API 中的 `GetSheetProperties` 方法。以下是一个示例函数,可用于获取工程图的图幅:
```vb
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Public Class SolidWorksHelper
Private swApp As SldWorks
Public Sub New()
swApp = New SldWorks()
End Sub
Public Sub GetDrawingSheetSize(ByVal filePath As String)
' 启动 SOLIDWORKS
swApp.Visible = False
swApp.UserControl = False
' 打开工程图文档
Dim swModel As ModelDoc2 = swApp.OpenDoc6(filePath, swDocumentTypes_e.swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0)
If swModel IsNot Nothing Then
' 获取活动工作表
Dim swDraw As DrawingDoc = CType(swModel, DrawingDoc)
Dim swSheet As Sheet = swDraw.GetCurrentSheet()
' 获取图幅尺寸
Dim sheetWidth As Double = 0
Dim sheetHeight As Double = 0
swSheet.GetProperties(sheetWidth, sheetHeight)
' 打印图幅尺寸
Console.WriteLine("工程图的图幅尺寸:{0} x {1}", sheetWidth, sheetHeight)
' 关闭工程图文档
swModel.CloseDoc()
End If
' 退出 SOLIDWORKS
swApp.ExitApp()
swApp = Nothing
End Sub
End Class
```
使用这个函数时,你需要将 `filePath` 参数设置为要打开的 SOLIDWORKS 工程图的文件路径。例如:
```vb
Dim helper As New SolidWorksHelper()
helper.GetDrawingSheetSize("C:\Path\To\Your\Drawing.slddrw")
```
该函数会在后台打开 SOLIDWORKS,并获取工程图的图幅尺寸。你可以根据需要,将图幅尺寸用于其他用途。
阅读全文