|
- Sub MAIN()
- Set swApp = CreateObject("sldworks.application")
- Set Part = swApp.ActiveDoc
- swApp.ActiveDoc.ActiveView.FrameState = 1
- Set CurCFG = Part.GetActiveConfiguration()
- ConfName = CurCFG.Name
- Name = swApp.ActiveDoc.GetTitle()
- c = Replace(Name, " ", "")
- 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
- f = Left(c, b - 7)
- Else
- f = c
- End If
- k = Len(f)
- kk = LenB(StrConv(f, vbFromUnicode))
- If k = kk Then '纯数字的情况
- s = ""
- t = f
- Response = MsgBox("文件名不包含零件名称,已整体写入“代号”属性栏", vbOKOnly, "未读取到零件名称") '窗口提示,不需要提示可以删除本行
- Else
- If kk / k = 2 Then '纯汉字的情况
- t = ""
- s = f
- Response = MsgBox("文件名不包含代号,已整体写入“名称”属性栏", vbOKOnly, "未读取到零件代号") '窗口提示,不需要提示可以删除本行
- Else
- For i = 1 To k
- If Asc(Mid$(f, i, 1)) < 0 Then
- w = i '确定第一个汉字的位置
- Exit For
- End If
- Next
- If w = 1 Then '名称+代号的情况
- s = Left(f, kk - k)
- t = Right(f, k - (kk - k))
- Else '代号+名称的情况
- s = Right(f, k - w + 1)
- t = Left(f, w - 1)
- End If
- End If
- End If
- dummy = Part.Extension.CustomPropertyManager(Part.ConfigurationManager.ActiveConfiguration.Name).Set("代号", t)
- dummy = Part.Extension.CustomPropertyManager(Part.ConfigurationManager.ActiveConfiguration.Name).Set("名称", s)
- End Sub
复制代码 最新亲测可用.
|
|