I have been trying to update material properties to custom materials which I have followed this example for:
2018 SOLIDWORKS API Help - Set Material Example (C#)
<p>swPart = (SldWorks.PartDoc)swModel;</p><p>// Get the material schema and names</p><p>// of available materials databases</p><p>vMatDBarr = (object[])swApp.GetMaterialDatabases();</p><p>Debug.Print("Material schema pathname = " + swApp.GetMaterialSchemaPathName());</p><p>for (i = 0; i < vMatDBarr.Length; i++)</p><p>{</p><p>Debug.Print(" Material database: " + vMatDB);</p><p>}</p><p>Debug.Print("");</p><p>Bodies = (object[])swPart.GetBodies2((int)swBodyType_e.swAllBodies, false);</p><p>for (j = 0; j < Bodies.Length; j++)</p><p>{</p><p>swBody = (SldWorks.Body2)Bodies[j];</p><p>// Get the name of the body</p><p>Debug.Print(swBody.Name);</p><p></p><p></p><p>// Set the SOLIDWORKS material for that body</p><p>swBody.Select2(false, null);</p><p>BodyMaterialError = swBody.SetMaterialProperty("Default", "LinktoMaterials", "AISI 304 Stainless Steel");</p><p></p><p>// Get the names of the body's material and the database to which it belongs</p><p>sMatName = swBody.GetMaterialPropertyName("", out sMatDB);</p><p>if (string.IsNullOrEmpty(sMatName))</p><p>{</p><p>Debug.Print("Body " + j + "'s material name: No material applied");</p><p>}</p><p>else</p><p>{</p><p>Debug.Print("Body " + j + "'s material name: " + sMatName);</p><p>Debug.Print("Body " + j + "'s material database: " + sMatDB);</p><p>Debug.Print(" ");</p><p>}</p><p>}</p>The code is finding the correct database and material name but it isn't applying it to the part.
"BodyMaterialError" is returning a value of 1 ( swBodyMaterialApplicationError_NoError 1 )
During the last IF statement it returns my database and material name which is correct but the material is still not updating:
Can anyone point me in the right direction as to what I'm doing incorrectly?
SolidworksApi/macros