通过宏添加solidworks零件材料
本帖最后由 735057167 于 2019-11-28 16:25 编辑由于模型需要测量总的重量,可通过宏来一键添加solidworks自带材料中304密度不是7。9需要自定义材料
也可以通过批量打开(dim)来实现
宏代码如下
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub 自适应材料()
Dim N
Dim a, b
Dim name, NAME1
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set selngr = Part.SelectionManager
swApp.ActiveDoc.ActiveView.FrameState = 1
N = swApp.ActiveDoc.GetTitle() '取得文件名
Set swModel = swApp.ActiveDoc
Set swConfig = swModel.GetActiveConfiguration
CFGNAME = swConfig.name() '当前配置名称
NAME1 = CFGNAME
For i = 1 To Len(N)
a = Mid(N, i, 1)
b = Mid(N, i, 2)
If a = "瓷" Then
name = "A95瓷管"
Exit For
ElseIf a = "铜" Then
name = "铜"
Exit For
ElseIf b = "环氧" Then
name = "环氧板"
Exit For
ElseIf b = "云母" Then
name = "云母"
Exit For
Else
name = "SUS 304"
End If
Next
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("未知", "BROWSERITEM", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("未知", "BROWSERITEM", 0, 0, 0, False, 0, Nothing, 0)
Part.SetMaterialPropertyName2 N, "C:/Program Files/SolidWorks Corp/SOLIDWORKS (2)/lang/chinese-simplified/sldmaterials/materials.sldmat", name
Part.SetMaterialPropertyName2 NAME1, "C:/Program Files/SolidWorks Corp/SOLIDWORKS (2)/lang/chinese-simplified/sldmaterials/materials.sldmat", name
Part.Save '保存
End Sub
由于无法上传宏文件,需要的可以留个邮件
可以从这里粘贴代码 直接添加零件材料,这个宏貌似更方方便。 学习一下,顶一下
页:
[1]