宏程序包含:窗体代码+模块代码
窗体代码:执行不同的命令
模块代码:显示窗体,也就是UI界面
目录
1.程序运行效果:
2.程序窗体代码:
Private Sub 现有零件_Click()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
' Check to see if a part is loaded
If swModel Is Nothing Then
swApp.SendMsgToUser2 "请打开一个零件.", swMbStop, swMbOk
Exit Sub
End If
If 镜像零件.Value = True Then
Dim boolstatus As Boolean
boolstatus = swModel.Extension.SelectByID2("上视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0) '选择上视基准面,记得注意SolidWorks是中文版还是英文版 中文版:上视基准面 英文版:Top Plane
'Next method called from specific PartDoc object.
swPart.MirrorPart2 False, swMirrorPartOptions_ImportSolids, swModel '生成镜像零件
swModel.ShowNamedView2 "*Isometric", 7 '切换到等轴测视图
swModel.ViewZoomtofit2 '使视图适应窗口大小
swApp.ArrangeWindows 1 '1窗口水平平铺排列
End If
End Sub