AnsweredAssumed Answered

Part Color does not change when SetMaterialPropertyName2 is used, VBA

Question asked by Joe Spaulding on Jan 28, 2019

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.

 

<material name="NRUB-MRED-60-000" description="NATURAL RUBBER, MEDIUM RED, 60 DURO, NO CUSTOM PROPERTIES" envdata="1" appdata="Material financial impact data from references documented in database creation spreadsheet">
<swatchcolor RGB="ff0000">
<sldcolorswatch:Optical Ambient="1.00000" Transparency="0.000000" Diffuse="1.000000" Specularity="1.000000" Shininess="0.200000" Emission="0.300000" />
</swatchcolor>
<physicalproperties>
<EX displayname="Elastic modulus" value="0" />
<NUXY displayname="Poisson's ratio" value="0" />
<GXY displayname="Shear modulus" value="0" />
<ALPX displayname="Thermal expansion coefficient" value="0" />
<DENS displayname="Mass density" value="930" />
<KX displayname="Thermal conductivity" value="0.13" />
<C displayname="Specific heat" value="1880" />
<SIGXT displayname="Tensile strength" value="7000000" />
<SIGYLD displayname="Yield strength" value="0" />
</physicalproperties>
<shaders>
<pwshader2 path="\metal\steel\matte steel.p2m" name="matte steel" isNewShader="1" />
<cgshader2 name="defaultplastic" />
</shaders>
<xhatch name="ANSI32 (Steel)" angle="0.0" scale="1.0" />
<custom>
<prop name="Material Cost" description="High Volume / Large Part" value="0.008" units="USD/g" />
<prop name="Material Cost" description="Low Volume / Small Part" value="0.009" units="USD/g" />
<prop name="Melt Temp" description="" value="453.15" units="K" />
<prop name="Mold Temp" description="" value="293.15" units="K" />
<prop name="Eject Temp" description="" value="295.13" units="K" />
</custom>

 

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.

Outcomes