Part Color does not change when SetMaterialPropertyName2 is used, VBA

Short story: When I apply a custom material using a macro, the color of the part does not change as expected.

Long story:

I have a user-form where an engineer can see search for one of our thousands of material combinations to see if we have a specific material in one of our custom databases. If the material is found in the database, the user can apply the material to a part. We rarely deal with assemblies so we're assuming we'll only be applying materials to parts.

Using the method in my title, I can apply the material to the part. See code below:

CustConfig = ""

CustFilePath = "C:\Users\Public\SOLIDWORKS\Material Database\" & UF_MaterialSelect.cmb_MatTyp.Text & ".sldmat"

CustMatID = UF_MaterialSelect.lbl_MatID_value

Set swModel = swApp.ActiveDoc

Set swPart = swModel

swPart.SetMaterialPropertyName2 CustConfig, CustFilePath, CustMatID

  • UF_MaterialSelect is my user-form
  • cmb_MatTyp is my material type, which is also the name of my material database (ex. Rubber.sldmat)
  • lbl_MatID_Value is the label in the user-form that contains the custom material name that was found in the custom material database

It appears that when I run this, my material is found in the database and is successfully applied to the part. However, the color of the part does not change. And the swatch of the material is specified in the .sldmat file. See example of one of my materials below.

As you can see, I haven't messed with changing the "pwshader2, cgshader2, xhatch" shaders from the standard shaders. I don't think that has anything to do with it, but I could be wrong.

Any help is much appreciated.

SolidworksApi/macros