SolidWorks*Excel+VBA-找尺寸
- 2026-09-20 15:14:29
SolidWorks*Excel+VBA-找尺寸基础打好了,开始步入正轨 出图出BOM前总得知道尺寸吧 尺寸有了,下一步干啥呢 
已关注
关注
重播 分享 赞
Sub GetSwFilesSizes() '获取模型尺寸数据Dim swApp As SldWorks.SldWorks, FullModelPath As StringDim OpennedModel As ModelDoc2, SwErr As LongDim k As Integer, Posn As Long, Pbox As VariantDim dx As Double, dy As Double, dz As Double'On Error Resume NextSet swApp = GetObject(, "SldWorks.Application")If swApp Is Nothing ThenMsgBox "请先打开SolidWorks!", vbExclamation, "不正经的机械仙人"Exit SubEnd IfIf myselcondi ThenWith ThisWorkbook.ActiveSheetswApp.CloseAllDocuments (True)For k = 1 To SelnumberProcessBarUpdater k, Selnumber, "正在获取尺寸:", "共" & Selnumber & "个,第" & k & "个 ..."Posn = Selarray(k)If UCase(.Cells(Posn, 4)) = ".SLDPRT" ThenFullModelPath = .Cells(Posn, 2) & "\" & .Cells(Posn, 3) & .Cells(Posn, 4)Set OpennedModel = swApp.OpenDoc2(FullModelPath, swDocPART, True, False, True, SwErr)If OpennedModel Is Nothing Then.Cells(Posn, 1) = "获取失败!"ElsePbox = OpennedModel.GetPartBox(False)dx = Round(Pbox(3) - Pbox(0), 2)dy = Round(Pbox(4) - Pbox(1), 2)dz = Round(Pbox(5) - Pbox(2), 2)Erase Pbox.Cells(Posn, 7) = dx & "*" & dy & "*" & dzSet OpennedModel = NothingswApp.QuitDoc FullModelPath.Cells(Posn, 1) = "尺寸√"End IfEnd IfNextEnd WithElseMsgBox "未选择正确行,程序结束!", vbExclamation, "不正经的机械仙人"End IfErr.ClearSet swApp = NothingApplication.StatusBar = FalseEnd Sub

本文来自网友投稿或网络内容,如有侵犯您的权益请联系我们删除,联系邮箱:wyl860211@qq.com 。