Add Material Layer

These scripts add a new material layer to every material in a scene that is applied to an object except mixed, cloud and volumetric materials. They can be used to speed up adding a toon shader layers or other effects material layer to a scene. addlayertoalltop.py adds a layer as the top layer in a material. addlayertoall.py adds a layer as the bottom most layer. addlayertoalltopnotrans.py adds a layer as the top layer in a material if the material doesn’t include any fuctions linked to its trasparancy output node.

The material that will be applied can be changed by editing the script file. Change the line matname=”Default” substituting the filename of the material you want to use without the .mat extension. So to use the material Varnish, which has the filename Varnish 1.mat, replace Default with Varnish 1. The line would now read matname=”Varnish 1″.

The python script has been tested with:

  • Vue 7.5 Infinite (2009)
  • Vue R5 (2020)

This video tutorial shows you how to edit the python script to change the material to be applied as a new layer. It was made using version 0.1 of the scripts but the version 0.2 scripts require the same change to be made and are not significantly different.

addlayertoall.py

[codesyntax lang=”python”]

#******************************************************
# Adds a material layer to every material in a scene
# that isn’t a mixed material or other material that
# can’t accept layers
#
# – addlayertoall.py
# – By Mark Caldwell
# – Version 0.4
# – Version 0.4 27th September 2009
# – Copyright Mark Caldwell 2009
# – Tested with Vue 7.5 Infinite
#
# How to use in 3 easy steps
#
# 1. Download this file onto your computer
#
# 2. Edit the python script to set the material to
#    be added as a layer following the instructions
#    below
#
# 3. Then run script and wait for it to work
#    To run it go to Python -> Run Python Script
#    Then locate the file on your computer
#
#******************************************************

#———————————————-
# Configuration: Change matname to change the
# material to be added.  Matname should be
# set to the filename of the material to be
# used but don’t put .mat on the end.
# It may not be the same as the material name
# displayed in Vue.
#
# For example the material Varnish has a filename
# Varnish 1.mat so to use it you would replace
# Default on the line below with Varnish 1
# so the line would read matname=”Varnish 1″
#———————————————-

matname=”Default”

#———————————————-
# Do Not Edit Anything After Here
#———————————————-

#———————————————-
# Find Selected Objects Calculate the Centre
#———————————————-

SelectAll()
countobj=CountSelectedObjects()
firstadd=0
matcheckname=””

if countobj>0:
for i in range(0,countobj):
SelectAll()
obj=GetSelectedObjectByIndex(i)
SelectOnly (obj)
countmaterial=obj.CountMaterials ()
if countmaterial>0:
for j in range (0,countmaterial):
DeselectAll()
SelectOnly (obj)
index=obj.Material (j).CountLayers()
if obj.Material (j).GetSubLayer(index-1).Name()!=matcheckname and obj.Material (j).Type()==0:
addlayer=obj.Material(j).AddLayer((index),matname)
if firstadd==0:
firstadd=1
matcheckname=obj.Material (j).GetSubLayer(index).Name()

DeselectAll()

#———————————————-
# Refresh Vue’s Display
#———————————————-

Refresh()

#———————————————-
# End of Script
#———————————————-
[/codesyntax]

addlayertoalltop.py

[codesyntax lang=”python”]

#******************************************************
# Adds a material layer on the top of all the other
# layers on every material in a scene that isn’t a
# mixed material or other material that can’t accept
# layers
#
# – addlayertoalltop.py
# – By Mark Caldwell
# – Version 0.4
# – Version 0.4 27th September 2009
# – Copyright Mark Caldwell 2009
# – Tested with Vue 7.5 Infinite
#
# How to use in 3 easy steps
#
# 1. Download this file onto your computer
#
# 2. Edit the python script to set the material to
#    be added as a layer following the instructions
#    below
#
# 3. Then run script and wait for it to work
#    To run it go to Python -> Run Python Script
#    Then locate the file on your computer
#
#******************************************************

#———————————————-
# Configuration: Change matname to change the
# material to be added.  Matname should be
# set to the filename of the material to be
# used but don’t put .mat on the end.
# It may not be the same as the material name
# displayed in Vue.
#
# For example the material Varnish has a filename
# Varnish 1.mat so to use it you would replace
# Default on the line below with Varnish 1
# so the line would read matname=”Varnish 1″
#———————————————-

matname=”Default”

#———————————————-
# Do Not Edit Anything After Here
#———————————————-

#———————————————-
# Find Selected Objects Calculate the Centre
#———————————————-

SelectAll()
countobj=CountSelectedObjects()
firstadd=0
matcheckname=””

if countobj>0:
for i in range(0,countobj):
SelectAll()
obj=GetSelectedObjectByIndex(i)
SelectOnly (obj)
countmaterial=obj.CountMaterials ()
for j in range (0,countmaterial):
DeselectAll()
SelectOnly (obj)
if obj.Material (j).GetSubLayer(0).Name()!=matcheckname and obj.Material (j).Type()==0:
addlayer=obj.Material(j).AddLayer((0),matname)
if firstadd==0:
firstadd=1
matcheckname=obj.Material (j).GetSubLayer(0).Name()

DeselectAll()

#———————————————-
# Refresh Vue’s Display
#———————————————-

Refresh()

#———————————————-
# End of Script
#———————————————-

[/codesyntax]

addlayertoalltopnotrans.py

[codesyntax lang=”python”]

#******************************************************
# Adds a material layer on the top of all the other
# layers on every material in a scene that isn’t a
# mixed material or other material that won’t accept
# layers and the material has nothing attached to its
# transparency output node
#
# – addlayertoalltopnotrans.py
# – By Mark Caldwell
# – Version 0.4
# – Version 0.4 27th September 2009
# – Copyright Mark Caldwell 2009
# – Tested with Vue 7.5 Infinite
#
# How to use in 3 easy steps
#
# 1. Download this file onto your computer
#
# 2. Edit the python script to set the material to
#    be added as a layer following the instructions
#    below
#
# 3. Then run script and wait for it to work
#    To run it go to Python -> Run Python Script
#    Then locate the file on your computer
#
#******************************************************

#———————————————-
# Configuration: Change matname to change the
# material to be added.  Matname should be
# set to the filename of the material to be
# used but don’t put .mat on the end.
# It may not be the same as the material name
# displayed in Vue.
#
# For example the material Varnish has a filename
# Varnish 1.mat so to use it you would replace
# Default on the line below with Varnish 1
# so the line would read matname=”Varnish 1″
#———————————————-

matname=”Default”

#———————————————-
# Do Not Edit Anything After Here
#———————————————-

#———————————————-
# Find Selected Objects Calculate the Centre
#———————————————-

SelectAll()
countobj=CountSelectedObjects()
firstadd=0
matcheckname=””

if countobj>0:
for i in range(0,countobj):
SelectAll()
obj=GetSelectedObjectByIndex(i)
SelectOnly (obj)
countmaterial=obj.CountMaterials ()
for j in range (0,countmaterial):
DeselectAll()
SelectOnly (obj)
functiongraph=obj.Material (j).FunctionGraph ()
countnodes=functiongraph.CountNodes()
trans=0
for k in range (0,countnodes):
if functiongraph.NodeName (k)==”Transparency”:
for l in range (0,functiongraph.CountNodeInputs(k)):
if functiongraph.InputConnection(k,l)[1]==1:
trans=1
if obj.Material (j).GetSubLayer(0).Name()!=matcheckname and obj.Material (j).Type()==0 and trans==0:
addlayer=obj.Material(j).AddLayer((0),matname)
if firstadd==0:
firstadd=1
matcheckname=obj.Material (j).GetSubLayer(0).Name()

DeselectAll()

#———————————————-
# Refresh Vue’s Display
#———————————————-

Refresh()

#———————————————-
# End of Script
#———————————————-

[/codesyntax]

impworks © Copyright Mark Caldwell 1996 - 2024