现在的位置: 首页 > 综合 > 正文

solidworks二次开发-01-录制一个宏

2013年08月10日 ⁄ 综合 ⁄ 共 1767字 ⁄ 字号 评论关闭

solidworks二次开发-01-录制一个宏

第一步:

我们需要自己录制一个宏,然后看看程序产生了什么代码。当初学习excel时候就是这么干的。只是,solidworks要复杂一些,直接录制的宏不能使用,需要做一些调整。在没有经验的时候我们最好按照下面的建议来做。

 Edit or Debug SolidWorks Macro

 

Edit or debug SolidWorks macros using Microsoft VBA.   使用Microsoft VBA编辑或调试宏

To edit or debug a SolidWorks macro:

  1. 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个宏程序列表供选择。

  1. 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。

  2. 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 Object

        • Dim Part As Object

        • Dim boolstatus As Boolean

        • Dim longstatus As Long, longwarnings As Long

        • Dim FeatureData As Object

        • Dim Feature As Object

        • Dim Component As Object

      • Delete all lines of code that change the view. 删除切换试图的代码

      译者注:像这样的 Part.ActiveView().RotateAboutCenter 0.0662574, 0.0346621 无情的删掉吧

Delete all ModelDoc2::ClearSelection2 calls appearing immediately before ModelDocExtension::SelectByID2.

抱歉!评论已关闭.