赞
踩
SolidWorks宏代码,用来分离文件名中的图号与零件名并自动写入属性,文件名不需要“-”或者空格等特殊符号,不限制图号长度,均可识别并分离使用方法打开宏工具栏2 点击新建宏按钮 选择路径,输入新建宏名称3删除窗口里的所有代码,把本文档里的代码粘贴进去保存4打开SolidWorks自定义5 打开命令标签,选择宏,把方框里的图标拖动到SolidWorks主界面工具栏6 在弹出窗口浏览刚刚保存的宏文件路径,点击确定7 在打开文件的情况下,点击刚刚在工具栏创建的宏按钮即可自动识别并写入属性以下为代码:Sub MAIN()Set swApp = CreateObject("sldworks.application")Set Part = swApp.ActiveDocswApp.ActiveDoc.ActiveView.FrameState = 1Set CurCFG = Part.GetActiveConfiguration()ConfName = CurCFG.NameName = swApp.ActiveDoc.GetTitle() c = Replace(Name, " ", "")blnretval = Part.AddCustomInfo3(ConfName, "代号", swCustomInfoText, frmPartID)blnretval = Part.AddCustomInfo3(ConfName, "名称", swCustomInfoText, frmPartID)blnretval = Part.AddCustomInfo3(ConfName, "备注", swCustomInfoText, frmPartID) b = Len(c) e = Right(c, 7)If e = ".SLDPRT" Or e = ".SLDASM" Or e = ".sldprt" Or e = ".sldasm" Then g = Left(c, b - 7)Else g = cEnd If l = Len(g) h = Left(g, 2) k = Len(g)For I = 1 To Len(g) If Asc(Mid$(g, I, 1)) < 0 Then w = I Exit For End IfNextFor I = 0 To Len(g) - 1 If Asc(Mid$(g, Len(g) - I, 1)) < 0 Then X = Len(g) - I Exit For End IfNextIf w > 0 Then If w = 1 Then s = Left(g, X) t = Right(g, k - X) Else t = Left(g, w - 1) s = Right(g, k - w + 1) End IfElse s = "" t = gEnd Ifdummy = Part.Extension.CustomPropertyManager(Part.ConfigurationManager.ActiveConfiguration.Name).Set("代号", t)dummy = Part.Extension.CustomPropertyManager(Part.ConfigurationManager.ActiveConfiguration.Name).Set("名称", s)dummy = Part.Extension.CustomPropertyManager(Part.ConfigurationManager.ActiveConfiguration.Name).Set("备注", j)End Sub
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。