solidworks 二次开发全教程系列solidworks 二次开发-01-录制一个宏 第一步:我们需要自己录制一个宏,然后看看程序产生了什么代码。当初学习 excel 时候就是这么干的。只是,solidworks 要复杂一些,直接录制的宏不能使用,需要做一些调整。在没有经验的时候我们最好按照下面的建议来做。Edit or Debug SolidWorks MacroEdit or debug SolidWorks macros using Microsoft VBA. 使用 Microsoft VBA 编辑或调试宏To edit or debug a SolidWorks macro:Click Edit Macro on the Macro toolbar, or click Tools, Macro, Edit.NOTES: 注意:To automatically edit a macro after recording it, click Tools, Options, Systems Options. On the General tab, select Automatically edit macro after recording and click OK. This setting is persistent across SolidWorks sessions. 此选项 Automatically edit macro after recording 顾名思义是在记录宏完毕后自动打开编辑界面。If you recently edited the macro, you can select it from the menu when you click Tools, Macro. This menu lists the last nine macros that you edited. 已经编辑了宏,菜单中会有最近的 9 个宏程序列表供选择。In the dialog box, select a macro file (.swp) and click Open. 选择一个宏 swp 文件NOTE: You can also edit .swb files, which are older-style SolidWorks macro files. When you run or edit a .swb file, it is automatically converted to a .swp file. 旧的宏文件后缀为 swb,你也可以打开 swb,那么会自动保存为 swp。Edit or debug the macro. If it is a new macro, be sure to:如果是新的宏Delete extra lines of code: 删除一些多余的代码:The following variables are declared automatically in a SolidWorks macro. Delete any variables not used in the macro. 这些对象的声明是自动产生的,可以将没用的删除 Dim swApp As ObjectDim Part As ObjectDim boolstatus As BooleanDim longstatus As Long, longwarnings As LongDim FeatureData As ObjectDim Feature As ObjectDim Component As ObjectDelete...