版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、SolidWorks2014基于宏实现快速图号名称分离1. 两类代码 代码1(内容添加至“自定义下”)Dim swApp As ObjectDim Part As ObjectDim SelMgr As ObjectDim boolstatus As BooleanDim longstatus As Long, longwarnings As LongDim Feature As ObjectDim a As IntegerDim b As StringDim m As StringDim e As StringDim k As StringDim t As StringDim c As St
2、ringDim j As IntegerDim strmat As StringDim tempvalue As StringSub main()link solidworksSet swApp = Application.SldWorksSet Part = swApp.ActiveDocSet SelMgr = Part.SelectionManagerswApp.ActiveDoc.ActiveView.FrameState = 1设定变量c = swApp.ActiveDoc.GetTitle() 零件名strmat = Chr(34) + Trim(SW-Material + ) +
3、 c + Chr(34)blnretval = Part.DeleteCustomInfo2(, 图样代号)blnretval = Part.DeleteCustomInfo2(, 图样名称)blnretval = Part.DeleteCustomInfo2(, 材料)a = InStr(c, ) - 1 重点:分隔标识符,这里是一个空格,也可用其他符号区分If a 0 Then k = Left(c, a) t = Left(LTrim(e), 3) If t = GBT Then e = GB/T + Mid(k, 4) Else e = k End If b = Mid(c, a +
4、2) t = Right(c, 7) If t = .SLDPRT Or t = .SLDASM Or t = .sldprt Or t = .sldasmThen j = Len(b) - 7 消除后缀(区分大小写,即含4种) Else j = Len(b) End If m = Left(b, j)End Ifblnretval = Part.AddCustomInfo3(, 图样代号, swCustomInfoText, e) 代号blnretval = Part.AddCustomInfo3(, 图样名称, swCustomInfoText, m) 名称blnretval = Part
5、.AddCustomInfo3(, 表面处理, swCustomInfoText, )End Sub 代码2(内容添加至“配置特定”下)定义swDim a As IntegerDim b As StringDim m As StringDim e As StringDim k As StringDim t As StringDim c As StringDim j As IntegerDim strmat As StringDim tempvalue As StringDim Part As ObjectDim swApp As SldWorks.SldWorksDim swModelDoc
6、As SldWorks.ModelDoc2Dim swConfig As SldWorks.ConfigurationDim CustPropMgr As SldWorks.CustomPropertyManagerDim swModel As SldWorks.ModelDoc2Sub main()Set swApp = Application.SldWorksSet swModelDoc = swApp.ActiveDocSet swConfig = swModelDoc.ConfigurationManager.ActiveConfigurationSet swModel = swApp
7、.ActiveDocSet CustPropMgr = swModel.Extension.CustomPropertyManager(swModel.ConfigurationManager.ActiveConfiguration.Name) 配置特定延伸设定变量c = swApp.ActiveDoc.GetTitle() 零件名strmat = Chr(34) + Trim(SW-Material + ) + c + Chr(34)a = InStr(c, ) - 1 重点:分隔标识符,这里是一个空格,也可换成其他符号If a 0 Then k = Left(c, a) t = Left(
8、LTrim(e), 3) If t = GBT Then e = GB/T + Mid(k, 4) Else e = k End If b = Mid(c, a + 2) t = Right(c, 7) If t = .SLDPRT Or t = .SLDASM Or t = .sldprt Or t = .sldasmThen j = Len(b) - 7 消除后缀(区分大小写,即含4种) Else j = Len(b) End If m = Left(b, j)End If删除栏CustPropMgr.Delete (图样代号)CustPropMgr.Delete (图样名称)CustPr
9、opMgr.Delete (材料)新增CustPropMgr.Add2 图样代号, swCustomInfoText, eCustPropMgr.Add2 图样名称, swCustomInfoText, mCustPropMgr.Add2 数量, swCustomInfoText, CustPropMgr.Add2 材料, swCustomInfoText, strmatCustPropMgr.Add2 单重, swCustomInfoText, CustPropMgr.Add2 总重, swCustomInfoText, CustPropMgr.Add2 备注, swCustomInfoTe
10、xt, End Sub特别说明:在虚拟件中添加属性时,名称会自动加上从属装配体,非虚拟件则不会(此问题急需高人指点)2. 操作步骤(以上述代码1为例)一、宏代码1新建宏代码:工具宏新建在文件名中输入:图号分离.swp ;点击保存,进入宏编辑界面;1. 2认识宏编辑界面:1、工程信息2、编程区域3、做一个写代码前的准备工作,把2区域的内容Ctrl+A 全选删除。2. 3写代码:复制如下代码,写到上图的2区域;从这里开始复制:定义solidworkDim swApp As ObjectDim Part As ObjectDim SelMgr As ObjectDim boolstatus As B
11、ooleanDim longstatus As Long, longwarnings As LongDim Feature As ObjectDim a As IntegerDim b As StringDim m As StringDim e As StringDim k As StringDim t As StringDim c As StringDim j As IntegerDim strmat As StringDim tempvalue As StringSub main()link solidworksSet swApp = Application.SldWorksSet Par
12、t = swApp.ActiveDocSet SelMgr = 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(
13、, 材料)a = InStr(c, ) - 1 重点:分隔标识符,这里是一个空格If a 0 Then k = Left(c, a) t = Left(LTrim(e), 3) If t = GBT Then e = GB/T + Mid(k, 4) Else e = k End If b = Mid(c, a + 2) t = Right(c, 7) If t = .SLDPRT Or t = .SLDASM Then j = Len(b) - 7 Else j = Len(b) End If m = Left(b, j)End Ifblnretval = Part.AddCustomInfo3(, 代号, swCustomInfoText, e) 代号blnretval = Part.AddCustomInfo3(, 名称, swCustomInfoText, m) 名称blnretval = Part.AddCustomInfo3(, 表面处理, swCustomInfoText, )End Sub3. 4保存退出。第一部分做到这就算完成了。下面是创建
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论