您现在的位置是:首页 > 自动化教程 > 自动化编程教程自动化编程教程

Solidworks宏:自动分离名称和图号

2025-12-02 08:11:53自动化编程教程957人已围观

简介 ' ;;--------------------------------------------------------------;; ' ;; Author: bati8888, Copyright 2023 - cad555.com ;; ' ;;

  ' ;;--------------------------------------------------------------;;
   ' ;; 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

Tags: 图号  Solidworks  

很赞哦! ()

留言与评论 (共有 条评论)
验证码: