‘ ******************************************************************************
‘ C:\Users\Administrator\AppData\Local\Temp\swx6576\Macro1.swb - macro recorded on 05/13/20 by Administrator
‘ ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks ‘链接到sldworks接口
‘ 新建文件
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2018\templates\GB.prtdot", 0, 0, 0)
Dim swPart As PartDoc
Set swPart = Part
swApp.ActivateDoc2 "test1", False, longstatus
Set Part = swApp.ActiveDoc
Dim myModelView As Object
‘选择草图平面
boolstatus = Part.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
‘插入草图
Part.SketchManager.InsertSketch True
‘画一个圆
Dim skSegment As Object
Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, 0.017995, -0.005952, 0#)
‘画一个多边形
Dim vSkLines As Variant
vSkLines = Part.SketchManager.CreatePolygon(0, 0, 0, 3.34976656173865E-02, 0, 0, 6, True)
‘退出草图
Part.SketchManager.InsertSketch True
‘插入一个拉伸特征
Dim myFeature As Object
Set myFeature = Part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, 0.02, 0.01, False, False, False, False, 1.74532925199433E-02, 1.74532925199433E-02, False, False, False, False, True, True, True, 0, 0, False)
Part.SelectionManager.EnableContourSelection = False
Part.ClearSelection2 True
‘ 全显视图
Part.ViewZoomtofit2
End Sub
SolidWorks二次开发::录制一个宏文件做一点修改就是一个好程序(螺母)
原文:https://www.cnblogs.com/shejiyizhan/p/12884829.html