But I don`t know how to read it to a variable? Can someone help?
What you mean by that. Do you mean adding the custom property for the model and setting the value as the applied material OR something different.
I want to right a macro which will read Material from material library to a variable.
For example I can read a custom property into the variable:
PartType = swModel.CustomInfo2("", "Part Type")
Can I read assigned material from material DB into a variable:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim sMatName As String
Dim sMatDB As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
sMatName = swPart.GetMaterialPropertyName2("Default", sMatDB)
Debug.Print " Material = " & sMatName & " (" & sMatDB & ")"
beautiful! Thanks man!