# Change component's material

**URL:** <https://forum.visualcomponents.com/t/change-components-material/959>\
**Category:** Python Programming\
**Created:** [February 19, 2020, 4:26pm UTC](https://forum.visualcomponents.com/t/change-components-material/959 "2020-02-19T16:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stransky](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stransky](https://forum.visualcomponents.com/u/stransky)\
**Post date:** [February 19, 2020, 4:26pm UTC](https://forum.visualcomponents.com/t/change-components-material/959/1 "2020-02-19T16:26:15Z")

</div>

Hi,

I would like to change material of component on “component level” - i want to change material of all features - I have in my component lot of features with lot of kind of materials and i need set one material to all component.

I tried to use script like this:

&nbsp;

&nbsp;

**from vcScript import \***

**app = getApplication()**

&nbsp;

# definition of function

**def setMaterial(part, material\_name):**  
**# find the materialname matching the given name**  
**material = app.findMaterial(material\_name)**

**# this will force even feature materials to be over-written**  
**part.MaterialInheritance = VC\_MATERIAL\_FORCE\_INHERIT**

**# assigning material as node material doesn’t force rebuild**  
**# =\> more efficient coz dynamic components still share geometry representation**  
**part.NodeMaterial = material**

&nbsp;

**def OnRun():**

**comp = getComponent()**  
**setMaterial(comp, ‘arctic\_hite’)**

**comp.rebuild()**  
**app.render()**

&nbsp;

Source of this code was Help of Visual Components.

It is works. But when i saved component into My Models, and reload it into Works space , materials was the origin - no change of material was saved.

How to change material of component by right way?

&nbsp;

&nbsp;

[layout\_wheel.vcmx](https://forum.visualcomponents.com/uploads/short-url/oV8rrxeij5nZaTE0y3cCOU12nAE.vcmx) (1.39 MB)

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [February 20, 2020, 1:32pm UTC](https://forum.visualcomponents.com/t/change-components-material/959/2 "2020-02-20T13:32:30Z")

</div>

Hy stransky,

```
def setMaterial(materialName,comp = none):
  material = app.findMaterial(materialName)
  if material:
    if comp:
      comp.MaterialInheritance = VC_MATERIAL_FORCE_INHERIT_NODE
      comp.NodeMaterial = material
    else:
      print "Give a component as Parameter!"
  else:
    print "Material %s could not be found! :(" %(materialName)
```

Regards

Feature

---

<div class="post-metadata">

**Author:** ![stransky](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stransky](https://forum.visualcomponents.com/u/stransky)\
**Post date:** [February 25, 2020, 5:28pm UTC](https://forum.visualcomponents.com/t/change-components-material/959/3 "2020-02-25T17:28:16Z")

</div>

Hi Captain Feature,

thanks for reply. It seem to me, that difference between my and your code is constant only.

VC\_MATERIAL\_FORCE\_INHERIT\_NODE

(Inherit node’s material to all geometries in this node)

&nbsp;

VC\_MATERIAL\_FORCE\_INHERIT

(Inherit node’s material to geometries in the node and all its child nodes.)

&nbsp;

Unfortunatelly on my computer (Premium 4.2.1) do not work both - material is changed but when I save component and reload back - origin material will appear, change is lost.

&nbsp;

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [February 25, 2020, 5:35pm UTC](https://forum.visualcomponents.com/t/change-components-material/959/4 "2020-02-25T17:35:17Z")

</div>

Hy,

try before change material:

```
comp.makeUnique()
```

Regards

Feature
