如何利用vb对SolidWorks进行二次开发.pdf
《如何利用vb对SolidWorks进行二次开发.pdf》由会员分享,可在线阅读,更多相关《如何利用vb对SolidWorks进行二次开发.pdf(6页珍藏版)》请在冰点文库上搜索。
![如何利用vb对SolidWorks进行二次开发.pdf](https://file1.bingdoc.com/fileroot1/2023-4/30/4a0b09b3-4a6f-4515-9a93-a61b2d99fd49/4a0b09b3-4a6f-4515-9a93-a61b2d99fd491.gif)
如何利用如何利用对对SolidWorks进行二次开发进行二次开发1.首先正确安装vs2010与SolidWorks,打开vs2010新建项目如图1。
图1系统会自动生成解决方案如图2。
图22.然后添加窗口Form1,向窗体中添加一个Button按钮,编写代码如下。
PublicClassForm1PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.ClickMsgBox(测试成功by_NYX)EndSubEndClass3.修改代码,如图3。
图3将代码修改为:
PublicSubAddCommandMgr()DimcmdGroupAsICommandGroupIfiBmpIsNothingTheniBmp=NewBitmapHandler()EndIfDimthisAssemblyAsAssemblyDimTitleAsString=NYX_CESHIDimToolTipAsString=Form1DesignSystemDimdocTypes()AsInteger=swDocumentTypes_e.swDocASSEMBLY,_swDocumentTypes_e.swDocDRAWING,_swDocumentTypes_e.swDocPARTthisAssembly=System.Reflection.Assembly.GetAssembly(Me.GetType()DimcmdGroupErrAsInteger=0DimignorePreviousAsBoolean=FalseDimregistryIDsAsObject=NothingDimgetDataResultAsBoolean=iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID,registryIDs)DimknownIDsAsInteger()=NewInteger
(1)mainItemID1,mainItemID2IfgetDataResultThenIfNotCompareIDs(registryIDs,knownIDs)TheniftheIDsdontmatch,resetthecommandGroupignorePrevious=TrueEndIfEndIfcmdGroup=iCmdMgr.CreateCommandGroup2(mainCmdGroupID,Title,ToolTip,-1,ignorePrevious,cmdGroupErr)IfcmdGroupIsNothingOrthisAssemblyIsNothingThenThrowNewNullReferenceException()EndIfIfNotIsNothing(cmdGroup)ThencmdGroup.LargeIconList=iBmp.CreateFileFromResourceBitmap(SwVBAddin1_Matlab.ToolbarLarge.bmp,thisAssembly)cmdGroup.SmallIconList=iBmp.CreateFileFromResourceBitmap(SwVBAddin1_Matlab.ToolbarSmall.bmp,thisAssembly)cmdGroup.LargeMainIcon=iBmp.CreateFileFromResourceBitmap(SwVBAddin1_Matlab.MainIconLarge.bmp,thisAssembly)cmdGroup.SmallMainIcon=iBmp.CreateFileFromResourceBitmap(SwVBAddin1_Matlab.MainIconSmall.bmp,thisAssembly)cmdGroup.AddCommandItem2(测试用,0,Form1Design,Form1Design,4,Form1,Form1_EnableMethod,0,swconst.swCommandItemType_e.swMenuItem)cmdGroup.HasToolbar=TruecmdGroup.HasMenu=TruecmdGroup.Activate()EndIfthisAssembly=NothingiBmp.Dispose()EndSub判断菜单工具条按钮可用性FunctionForm1_EnableMethod()AsIntegerIfiSwApp.ActiveDocIsNothingThenForm1_EnableMethod=1ElseForm1_EnableMethod=0EndIfEndFunctionFunctionForm1()AsBooleanDimstAsNewForm1st.Show()EndFunction4.重新生成解决方案,如图4。
图45.运行SolidWorks,查看成果,如图5。
图56.最终插件如图6。
图6