您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 机械/模具设计 > solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中)
SolidWorks2014基于宏实现快速图号名称分离1.两类代码代码1(内容添加至“自定义下”)DimswAppAsObjectDimPartAsObjectDimSelMgrAsObjectDimboolstatusAsBooleanDimlongstatusAsLong,longwarningsAsLongDimFeatureAsObjectDimaAsIntegerDimbAsStringDimmAsStringDimeAsStringDimkAsStringDimtAsStringDimcAsStringDimjAsIntegerDimstrmatAsStringDimtempvalueAsStringSubmain()'linksolidworksSetswApp=Application.SldWorksSetPart=swApp.ActiveDocSetSelMgr=Part.SelectionManagerswApp.ActiveDoc.ActiveView.FrameState=1'设定变量c=swApp.ActiveDoc.GetTitle()'零件名strmat=Chr(34)+Trim(SW-Material+@)+c+Chr(34)blnretval=Part.DeleteCustomInfo2(,图样代号)blnretval=Part.DeleteCustomInfo2(,图样名称)blnretval=Part.DeleteCustomInfo2(,材料)a=InStr(c,)-1'重点:分隔标识符,这里是一个空格,也可用其他符号区分Ifa0Thenk=Left(c,a)t=Left(LTrim(e),3)Ift=GBTThene=GB/T+Mid(k,4)Elsee=kEndIfb=Mid(c,a+2)t=Right(c,7)Ift=.SLDPRTOrt=.SLDASMOrt=.sldprtOrt=.sldasmThenj=Len(b)-7'消除后缀(区分大小写,即含4种)Elsej=Len(b)EndIfm=Left(b,j)EndIfblnretval=Part.AddCustomInfo3(,图样代号,swCustomInfoText,e)'代号blnretval=Part.AddCustomInfo3(,图样名称,swCustomInfoText,m)'名称blnretval=Part.AddCustomInfo3(,表面处理,swCustomInfoText,)EndSub代码2(内容添加至“配置特定”下)'定义swDimaAsIntegerDimbAsStringDimmAsStringDimeAsStringDimkAsStringDimtAsStringDimcAsStringDimjAsIntegerDimstrmatAsStringDimtempvalueAsStringDimPartAsObjectDimswAppAsSldWorks.SldWorksDimswModelDocAsSldWorks.ModelDoc2DimswConfigAsSldWorks.ConfigurationDimCustPropMgrAsSldWorks.CustomPropertyManagerDimswModelAsSldWorks.ModelDoc2Submain()SetswApp=Application.SldWorksSetswModelDoc=swApp.ActiveDocSetswConfig=swModelDoc.ConfigurationManager.ActiveConfigurationSetswModel=swApp.ActiveDocSetCustPropMgr=swModel.Extension.CustomPropertyManager(swModel.ConfigurationManager.ActiveConfiguration.Name)'配置特定延伸'设定变量c=swApp.ActiveDoc.GetTitle()'零件名strmat=Chr(34)+Trim(SW-Material+@)+c+Chr(34)a=InStr(c,)-1'重点:分隔标识符,这里是一个空格,也可换成其他符号Ifa0Thenk=Left(c,a)t=Left(LTrim(e),3)Ift=GBTThene=GB/T+Mid(k,4)Elsee=kEndIfb=Mid(c,a+2)t=Right(c,7)Ift=.SLDPRTOrt=.SLDASMOrt=.sldprtOrt=.sldasmThenj=Len(b)-7'消除后缀(区分大小写,即含4种)Elsej=Len(b)EndIfm=Left(b,j)EndIf'删除栏CustPropMgr.Delete(图样代号)CustPropMgr.Delete(图样名称)CustPropMgr.Delete(材料)'新增CustPropMgr.Add2图样代号,swCustomInfoText,eCustPropMgr.Add2图样名称,swCustomInfoText,mCustPropMgr.Add2数量,swCustomInfoText,CustPropMgr.Add2材料,swCustomInfoText,strmatCustPropMgr.Add2单重,swCustomInfoText,CustPropMgr.Add2总重,swCustomInfoText,CustPropMgr.Add2备注,swCustomInfoText,EndSub特别说明:在虚拟件中添加属性时,名称会自动加上从属装配体,非虚拟件则不会(此问题急需高人指点)2.操作步骤(以上述代码1为例)一、宏代码1新建宏代码:工具——宏——新建在文件名中输入:图号分离.swp;点击保存,进入宏编辑界面;1.2认识宏编辑界面:1、工程信息2、编程区域3、做一个写代码前的准备工作,把2区域的内容Ctrl+A全选删除。2.3写代码:复制如下代码,写到上图的2区域;'从这里开始复制:'定义solidworkDimswAppAsObjectDimPartAsObjectDimSelMgrAsObjectDimboolstatusAsBooleanDimlongstatusAsLong,longwarningsAsLongDimFeatureAsObjectDimaAsIntegerDimbAsStringDimmAsStringDimeAsStringDimkAsStringDimtAsStringDimcAsStringDimjAsIntegerDimstrmatAsStringDimtempvalueAsStringSubmain()'linksolidworksSetswApp=Application.SldWorksSetPart=swApp.ActiveDocSetSelMgr=Part.SelectionManagerswApp.ActiveDoc.ActiveView.FrameState=1'设定变量c=swApp.ActiveDoc.GetTitle()'零件名strmat=Chr(34)+Trim(SW-Material+@)+c+Chr(34)blnretval=Part.DeleteCustomInfo2(,代号)blnretval=Part.DeleteCustomInfo2(,名称)blnretval=Part.DeleteCustomInfo2(,材料)a=InStr(c,)-1'重点:分隔标识符,这里是一个空格Ifa0Thenk=Left(c,a)t=Left(LTrim(e),3)Ift=GBTThene=GB/T+Mid(k,4)Elsee=kEndIfb=Mid(c,a+2)t=Right(c,7)Ift=.SLDPRTOrt=.SLDASMThenj=Len(b)-7Elsej=Len(b)EndIfm=Left(b,j)EndIfblnretval=Part.AddCustomInfo3(,代号,swCustomInfoText,e)'代号blnretval=Part.AddCustomInfo3(,名称,swCustomInfoText,m)'名称blnretval=Part.AddCustomInfo3(,表面处理,swCustomInfoText,)EndSub3.4保存退出。第一部分做到这就算完成了。下面是创建宏按钮;END二、创建宏按钮1.返回Solidworks工作界面,进入自定义工具栏:工具——自定义;选择命令选项卡,找到宏,把新建宏按钮拖到工具栏的空白处;2.弹出自定义宏按钮对话框:1、选择上面保存的宏文件;2、指定一个图标,以便在工具栏中显示;3、指定一个指示的名称,以便在工具栏中显示;3.点击确定,退出自定义宏按钮,完成制作。4.4新建零件命名规则:代号+空格+名称注意:代号中不能出现空格,宏以第一个空格为分隔符。
本文标题:solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中)
链接地址:https://www.777doc.com/doc-4115390 .html