SolidWorks更改材質的宏

Option Explicit
Dim swApp As SldWorks.SldWorks 'SW應用程序
Dim swModel As ModelDoc2 'sw文檔
Dim sldmatFilePath As String 'SW材質數據文件路徑
Dim sldmatName As String 'SW材質名稱
Dim path As String 'sw文件路徑
Dim filename As String 'sw文件名
Dim boolstatus As Boolean '返回值 狀態

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
MsgBox "無活動文檔,請打開一個SolidWorks文件後重新運行此宏!", vbExclamation    '消息框
Exit Sub '退出Main()
End If

sldmatFilePath = "c:/Program Files/SOLIDWORKS Corp/SOLIDWORKS/lang/chinese-simplified/sldmaterials/SOLIDWORKS materials.sldmat"
sldmatName = "普通碳鋼"
path = swModel.GetPathName 'Get the Path name + File Name
filename = Mid$(path, InStrRev(path, "\") + 1) ' File Name With extension

boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_e.swUnitSystem_Custom) '
    boolstatus = swModel.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, swUnitsMassPropMass_e.swUnitsMassPropMass_Kilograms) '
    boolstatus = swModel.Extension.SelectByID2("未知", "BROWSERITEM", 0, 0, 0, False, 0, Nothing, 0)
    swModel.ClearSelection2 True
    swModel.SetMaterialPropertyName2 "默認", sldmatFilePath, sldmatName

    swModel.ClearSelection2 True


swModel.Save    '保存文件

End Sub

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章