Change component's material

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:

 

 

from vcScript import *

app = getApplication()

 

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

 

def OnRun():

comp = getComponent()
setMaterial(comp, ‘arctic_hite’)

comp.rebuild()
app.render()

 

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?

 

 

layout_wheel.vcmx (1.39 MB)

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

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)

 

VC_MATERIAL_FORCE_INHERIT

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

 

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.

 

 

 

 

Hy,

try before change material:

comp.makeUnique()

Regards

Feature