|
發表於 2024/4/3 09:08:06
|
顯示全部樓層
- Sub JET_零件圖名轉料號_機構_零件及組件()
- Dim swApp As SldWorks.SldWorks
- Dim swModel As SldWorks.ModelDoc2
- Dim aCode As String '機種代碼
- Dim bCode As String '加工代碼
- Dim cCode As String '版次代碼
- Dim dCode As String '模組代碼
- Dim eCode As String '流水碼
- Dim fCode As String '加工碼
- Dim gCode As String '階層碼
- Dim sapNumber As String '料號總成
- Set swApp = Application.SldWorks '初始化SOLIDWORKS應用程式
- '-------------------------------檢查檔案格式---------------------------------
- Set swApp = Application.SldWorks
- Set swModel = swApp.ActiveDoc '設置模型為激活的文件
- '*********************************************************
- If swModel.GetType = swDocASSEMBLY Then '此為組合件檔
- 'Get the current file name
- Dim fileName As String
- ' 取得當前開啟的檔案名稱(含路徑)
- fileName = swModel.GetPathName()
- ' 取得檔案名稱(含副檔名)
- fileName = Right(fileName, Len(fileName) - InStrRev(fileName, ""))
- 'Get the aCode(機種代碼截取)
- aCode = Left(fileName, InStr(fileName, "-") - 3)
- ' aCode(機種代碼轉換)
- Select Case aCode
- Case "共用型選項": aCode = "1100"
- Case "5500V": aCode = "1101"
- Case "5500MLR": aCode = "1102"
- Case "5500MLB": aCode = "1103"
- Case "5500SLR": aCode = "1104"
- Case "5500SLB": aCode = "1105"
- Case "5500SLGR": aCode = "1106"
- Case "7700S": aCode = "6666"
- Case "3000SLR": aCode = "1104"
- Case Else: aCode = "****"
- End Select
- 'Get the bCode(加工碼截取)
- bCode = Mid(fileName, InStr(fileName, "-") + 1, 1)
- ' bCode(加工碼轉換)
- Select Case bCode
- Case "D": bCode = "3001"
- Case "C": bCode = "3002"
- Case "M": bCode = "3003"
- Case "L": bCode = "3004"
- Case "P": bCode = "3005"
- Case "A": bCode = "3006"
- Case "S": bCode = "3007"
- Case "U": bCode = "3008"
- Case "B": bCode = "3009"
- Case "R": bCode = "3010"
- Case "Y": bCode = "3011"
- Case "F": bCode = "3012"
- Case "Z": bCode = "3013"
- Case "G": bCode = "3015"
- Case "H": bCode = "3016"
- Case "J": bCode = "3017"
- Case Else: bCode = "****"
- End Select
- 'Get the cCode(版次代碼截取)
- cCode = Mid(fileName, InStr(fileName, "-") + 6, 1)
- ' cCode(版次代碼轉換)
- Select Case cCode
- Case "A": cCode = "01"
- Case "B": cCode = "02"
- Case "C": cCode = "03"
- Case "D": cCode = "04"
- Case "E": cCode = "05"
- Case "F": cCode = "06"
- Case "G": cCode = "07"
- Case "H": cCode = "08"
- Case "I": cCode = "09"
- Case "J": cCode = "10"
- Case "K": cCode = "11"
- Case "L": cCode = "12"
- Case "M": cCode = "13"
- Case "N": cCode = "14"
- Case "O": cCode = "15"
- Case "P": cCode = "16"
- Case "Q": cCode = "17"
- Case "R": cCode = "18"
- Case "S": cCode = "19"
- Case "T": cCode = "20"
- Case "U": cCode = "21"
- Case "V": cCode = "22"
- Case "W": cCode = "23"
- Case "X": cCode = "24"
- Case "Y": cCode = "25"
- Case "Z": cCode = "26"
- Case Else: cCode = "**"
- End Select
- 'Get the dCode(模組碼截取)
- dCode = Mid(fileName, InStr(fileName, "-") - 2, 2)
- 'Get the eCode(流水碼截取)
- eCode = Mid(fileName, InStr(fileName, "-") + 3, 3)
- 'Get the fCode(加工碼截取)
- fCode = Mid(fileName, InStr(fileName, "-") + 1, 1)
- 'Get the gCode(階層碼截取)
- gCode = Mid(fileName, InStr(fileName, "-") + 1, 1)
- ' gCode(階層碼轉換)
- Select Case gCode
- Case "P": gCode = "4"
- Case Else: gCode = "3"
- End Select
- 'Generate the SAP number(料號組合)
- sapNumber = bCode & aCode & dCode & eCode & cCode
- ' 建立自訂屬性值
- Dim sConfigName As String
- sConfigName = "預設" ' *****設定要寫入的組態名稱*****
- Dim Configs As Variant
- Configs = swApp.ActiveDoc.GetConfigurationNames()
- ' 檢查是否有現有的組態名稱
- If IsArray(Configs) Then
- For i = 0 To UBound(Configs)
- If Configs(i) = sConfigName Then
- ' 如果已存在,將 sConfigName 設定為現有的組態名稱
- sConfigName = Configs(i)
- Exit For
- End If
- Next
- End If
- Dim retval As Long
- '刪除"SAP料號"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "SAP料號")
- '新增"SAP料號"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "SAP料號", swCustomInfoText, sapNumber)
- '刪除"加工方法"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "加工方法")
- '新增"加工方法"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "加工方法", swCustomInfoText, fCode)
- '刪除"階層"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "階層")
- '新增"階層"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "階層", swCustomInfoText, gCode)
- '寫入作者
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Part.SummaryInfo(swSumInfoAuthor) = "XXX"
- '刪除全部屬性
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- p = "" '指定模型組態名稱 ,如果要刪自訂則空白
- k = Part.GetCustomInfoNames2(p)
- For i = 0 To UBound(k)
- Part.DeleteCustomInfo2 p, k(i)
- Next
- '-------------------------------------------------------------------------
- '樹狀結構顯示
- Set swApp = _
- Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set intance = Part.FeatureManager
- '顯示特徵名稱
- intance.ShowFeatureName = True
- '顯示特徵描述
- intance.ShowFeatureDescription = False
- '顯示零組件名稱
- intance.ShowComponentNames = True
- '顯示零組件描述
- intance.ShowComponentDescriptions = True
- '顯示零組件模型組態名稱
- intance.ShowComponentConfigurationNames = True
- '顯示零組件模型組態描述
- intance.ShowComponentConfigurationDescriptions = False
- '顯示顯示狀態名稱
- intance.ShowDisplayStateNames = False
- '顯示特徵
- intance.ViewFeatures = True
- '------------------------------------------------------------------------------
- '重新整理
- Set Part = swApp.ActiveDoc
- boolstatus = Part.EditRebuild3()
- ' 顯示成功訊息
- 'MsgBox "█ SAP 料號已寫入 █"
- End if
- '*********************************************************
- If swModel.GetType = swDocPART Then '此為零件檔
- 'Get the current file name
- Dim fileName As String
- ' 取得當前開啟的檔案名稱(含路徑)
- fileName = swModel.GetPathName()
- ' 取得檔案名稱(含副檔名)
- fileName = Right(fileName, Len(fileName) - InStrRev(fileName, ""))
- 'Get the aCode(機種代碼截取)
- aCode = Left(fileName, InStr(fileName, "#") - 3)
- ' aCode(機種代碼轉換)
- Select Case aCode
- Case "共用型選項": aCode = "1100"
- Case "5500V": aCode = "1101"
- Case "5500MLR": aCode = "1102"
- Case "5500MLB": aCode = "1103"
- Case "5500SLR": aCode = "1104"
- Case "5500SLB": aCode = "1105"
- Case "5500SLGR": aCode = "1106"
- Case Else: aCode = "****"
- End Select
- 'Get the bCode(模組碼截取)
- bCode = Mid(fileName, InStr(fileName, "#") - 2, 2)
- 'Generate the SAP number(料號組合)
- sapNumber = aCode & bCode & "**"
- ' 建立自訂屬性值
- Dim sConfigName As String
- sConfigName = "預設" ' *****設定要寫入的組態名稱*****
- Dim Configs As Variant
- Configs = swApp.ActiveDoc.GetConfigurationNames()
- ' 檢查是否有現有的組態名稱
- If IsArray(Configs) Then
- For i = 0 To UBound(Configs)
- If Configs(i) = sConfigName Then
- ' 如果已存在,將 sConfigName 設定為現有的組態名稱
- sConfigName = Configs(i)
- Exit For
- End If
- Next
- End If
- Dim retval As Long
- '刪除"SAP料號"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "SAP料號")
- '新增"SAP料號"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "SAP料號", swCustomInfoText, sapNumber)
- '刪除"加工方法"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "加工方法")
- '新增"加工方法"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "加工方法", swCustomInfoText, fCode)
- '刪除"階層"欄
- retval = swApp.ActiveDoc.DeleteCustomInfo2(sConfigName, "階層")
- '新增"階層"欄
- retval = swApp.ActiveDoc.AddCustomInfo3(sConfigName, "階層", swCustomInfoText, gCode)
- '寫入作者
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- Part.SummaryInfo(swSumInfoAuthor) = "XXX"
- '刪除全部屬性
- Set swApp = Application.SldWorks
- Set Part = swApp.ActiveDoc
- p = "" '指定模型組態名稱 ,如果要刪自訂則空白
- k = Part.GetCustomInfoNames2(p)
- For i = 0 To UBound(k)
- Part.DeleteCustomInfo2 p, k(i)
- Next
- '-------------------------------------------------------------------------
- '樹狀結構顯示
- Set swApp = _
- Application.SldWorks
- Set Part = swApp.ActiveDoc
- Set intance = Part.FeatureManager
- '顯示特徵名稱
- intance.ShowFeatureName = True
- '顯示特徵描述
- intance.ShowFeatureDescription = False
- '顯示零組件名稱
- intance.ShowComponentNames = True
- '顯示零組件描述
- intance.ShowComponentDescriptions = True
- '顯示零組件模型組態名稱
- intance.ShowComponentConfigurationNames = True
- '顯示零組件模型組態描述
- intance.ShowComponentConfigurationDescriptions = False
- '顯示顯示狀態名稱
- intance.ShowDisplayStateNames = False
- '顯示特徵
- intance.ViewFeatures = True
- '------------------------------------------------------------------------------
- '重新整理
- Set Part = swApp.ActiveDoc
- boolstatus = Part.EditRebuild3()
- ' 顯示成功訊息
- 'MsgBox "█ SAP 料號已寫入 █"
- '------------------------------------------------------------------------------
- End If
- '*********************************************************
- End Sub
複製代碼 |
|