资源描述:
《solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、SolidWorks2014基于宏实现快速"图号名称"分离1.两类代码代码1(内容添加至“自定义下”)DimswAppAsObjectDimPartAsObjectDimSelMgrAsObjectDimboolstatusAsBooleanDimlongstatusAsLong,longwarningsAsLongDimFeatureAsObjectDimaAsIntegerDimbAsStringDimmAsStringDimeAsStringDimkAsStringDimtAsStringDimcAsStringDimjAsIntege
2、rDimstrmatAsStringDimtempvalueAsStringSubmain()'linksolidworksSetswApp=Application.SldWorksSetPart=swApp.ActiveDocSetSelMgr=Part.SelectionManagerswApp.ActiveDoc.ActiveView.FrameState=1'设定变量c=swApp.ActiveDoc.GetTitle()'零件名strmat=Chr(34)+Trim("SW-Material"+"@")+c+Chr(34)blnret
3、val=Part.DeleteCustomInfo2("","图样代号")blnretval=Part.DeleteCustomInfo2("","图样名称")blnretval=Part.DeleteCustomInfo2("","材料")a=InStr(c,"")-1'重点:分隔标识符,这里是一个空格,也可用其他符号区分Ifa>0Thenk=Left(c,a)t=Left(LTrim(e),3)Ift="GBT"Thene="GB/T"+Mid(k,4)Elsee=kEndIfb=Mid(c,a+2)t=Right(c,7)Ift=".SL
4、DPRT"Ort=".SLDASM"Ort=".sldprt"Ort=".sldasm"Thenj=Len(b)-7'消除后缀(区分大小写,即含4种)Elsej=Len(b)EndIfm=Left(b,j)EndIfblnretval=Part.AddCustomInfo3("","图样代号",swCustomInfoText,e)'代号blnretval=Part.AddCustomInfo3("","图样名称",swCustomInfoText,m)'名称blnretval=Part.AddCustomInfo3("","表面处理",swC
5、ustomInfoText,"")EndSub代码2(内容添加至“配置特定”下)'定义swDimaAsIntegerDimbAsStringDimmAsStringDimeAsStringDimkAsStringDimtAsStringDimcAsStringDimjAsIntegerDimstrmatAsStringDimtempvalueAsStringDimPartAsObjectDimswAppAsSldWorks.SldWorksDimswModelDocAsSldWorks.ModelDoc2DimswConfigAsSldWor
6、ks.ConfigurationDimCustPropMgrAsSldWorks.CustomPropertyManagerDimswModelAsSldWorks.ModelDoc2Submain()SetswApp=Application.SldWorksSetswModelDoc=swApp.ActiveDocSetswConfig=swModelDoc.ConfigurationManager.ActiveConfigurationSetswModel=swApp.ActiveDocSetCustPropMgr=swModel.Exte
7、nsion.CustomPropertyManager(swModel.ConfigurationManager.ActiveConfiguration.Name)'配置特定延伸'设定变量c=swApp.ActiveDoc.GetTitle()'零件名strmat=Chr(34)+Trim("SW-Material"+"@")+c+Chr(34)a=InStr(c,"")-1'重点:分隔标识符,这里是一个空格,也可换成其他符号Ifa>0Thenk=Left(c,a)t=Left(LTrim(e),3)Ift="GBT"Thene="GB/T"+
8、Mid(k,4)Elsee=kEndIfb=Mid(c,a+2)t=Right(c,7)Ift=".SLDPRT"Ort=".SLDASM"Ort="