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

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值