收藏 分销(赏)

solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc

上传人:1587****927 文档编号:1361244 上传时间:2024-04-24 格式:DOC 页数:10 大小:484.19KB
下载 相关 举报
solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc_第1页
第1页 / 共10页
solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc_第2页
第2页 / 共10页
solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc_第3页
第3页 / 共10页
solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc_第4页
第4页 / 共10页
solidworks代号名称分离宏命令(属性”自定义“或”配置特定“中).doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

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.AddCustomInf

14、o3(, 代号, swCustomInfoText, e) 代号blnretval = Part.AddCustomInfo3(, 名称, swCustomInfoText, m) 名称blnretval = Part.AddCustomInfo3(, 表面处理, swCustomInfoText, )End Sub3. 4保存退出。第一部分做到这就算完成了。下面是创建宏按钮;END二、创建宏按钮1. 返回Solidworks工作界面,进入自定义工具栏:工具自定义;选择命令选项卡,找到宏 ,把新建宏按钮拖到工具栏的空白处;2. 弹出自定义宏按钮对话框:1、选择上面保存的宏文件;2、指定一个图标,以便在工具栏中显示;3、指定一个指示的名称,以便在工具栏中显示;3. 点击确定,退出自定义宏按钮,完成制作。4. 4新建零件命名规则:代号+空格+名称注意:代号中不能出现空格,宏以第一个空格为分隔符。

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服