下面结合程序,介绍其实现方法。程序如下:
Private Function SwAddin_ConnectToSW(ByVal ThisSW As Object, &_ByVal cookie As Long) As Boolean
Dim Ret As Boolean
Set iSldWorks = ThisSWicookie = cookie
Ret = iSldWorks.SetAddinCallbackInfo(App.hInstance, Me,icookie)
增加菜单部分
Ret = iSldWorks.AddMenuItem2(swDocDRAWING, icookie,&_"公差标注...@附加项(&A)", -1, "DocDRAWING_dimension",&_"DocDRAWING_ItemUpdate","DocDRAWING_Item hintstring")
Ret = iSldWorks.AddMenuItem2(swDocDRAWING, icookie,&_"粗糙度...@附加项(&A)", -1, "DocDRAWING_symbol", &_"DocDRAWING_ItemUpdate", "DocDRAWING_Item hintstring")
SwAddin_ConnectToSW = True
End Function
……
函数中前面是定义部分变量,下面就为添加菜单的关键部分,语句中许多函数在 SolidWorks的对象库和本软件的公用模块中已经定义。在开发过程中,可能遇到许多有关 API 函数的问题,这就需要仔细阅读 SolidWorks 所带的 API 帮助函数,帮助文件为英文,这就提高了我国用户进行开发的难度。