Solidworks宏:自动分离名称和图号
2023-03-06
Solidworks
' ;;--------------------------------------------------------------;;
' ;; Author: bati8888, Copyright 2023 - cad555.com ;;
' ;;--------------------------------------------------------------;;
' ;; Version 1.0.0 - 2023-03-06 ;;
' ;;--------------------------------------------------------------;;
Sub main()
Const delimiter As String = "_"
Const codeTitle As String = "代号"
Const nameTitle As String = "名称"
Dim swApp As Object
Dim Part As Object
Dim titleTemp As String
Dim arrayTemp() As String
Dim strTemp As String
Dim arrayCount As Integer
Dim boolTemp As Boolean
Dim code As String
Dim name As String
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
titleTemp = swApp.ActiveDoc.GetTitle()
arrayTemp = Split(titleTemp, ".")
strTemp = arrayTemp(0)
arrayTemp = Split(strTemp, delimiter)
arrayCount = UBound(arrayTemp)
If arrayCount > 0 Then
name = arrayTemp(1)
code = arrayTemp(0)
boolTemp = Part.DeleteCustomInfo2("", codeTitle)
boolTemp = Part.DeleteCustomInfo2("", nameTitle)
boolTemp = Part.AddCustomInfo3("", codeTitle, swCustomInfoText, code)
boolTemp = Part.AddCustomInfo3("", nameTitle, swCustomInfoText, name)
End If
End Sub