如何利用vb对SolidWorks进行二次开发

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

如何利用vb.net对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.swDocPART}thisAssembly=System.Reflection.Assembly.GetAssembly(Me.GetType())DimcmdGroupErrAsInteger=0DimignorePreviousAsBoolean=FalseDimregistryIDsAsObject=NothingDimgetDataResultAsBoolean=iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID,registryIDs)DimknownIDsAsInteger()=NewInteger(1){mainItemID1,mainItemID2}IfgetDataResultThenIfNotCompareIDs(registryIDs,knownIDs)Then'iftheIDsdon'tmatch,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

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功