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.

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

  1. #******************************************************
  2. # Adds a material layer to every material in a scene
  3. # that isn't a mixed material or other material that
  4. # can't accept layers
  5. #
  6. # - addlayertoall.py
  7. # - By Mark Caldwell
  8. # - Version 0.4
  9. # - Version 0.4 27th September 2009
  10. # - Copyright Mark Caldwell 2009
  11. # - Tested with Vue 7.5 Infinite
  12. #
  13. # How to use in 3 easy steps
  14. #
  15. # 1. Download this file onto your computer
  16. #
  17. # 2. Edit the python script to set the material to
  18. #    be added as a layer following the instructions
  19. #    below
  20. #
  21. # 3. Then run script and wait for it to work
  22. #    To run it go to Python -> Run Python Script
  23. #    Then locate the file on your computer
  24. #
  25. #******************************************************
  26. #----------------------------------------------
  27. # Configuration: Change matname to change the
  28. # material to be added.  Matname should be
  29. # set to the filename of the material to be
  30. # used but don't put .mat on the end.
  31. # It may not be the same as the material name
  32. # displayed in Vue.
  33. #
  34. # For example the material Varnish has a filename
  35. # Varnish 1.mat so to use it you would replace
  36. # Default on the line below with Varnish 1
  37. # so the line would read matname="Varnish 1"
  38. #----------------------------------------------
  39. matname="Default"
  40. #----------------------------------------------
  41. # Do Not Edit Anything After Here
  42. #----------------------------------------------
  43. #----------------------------------------------
  44. # Find Selected Objects Calculate the Centre
  45. #----------------------------------------------
  46. SelectAll()
  47. countobj=CountSelectedObjects()
  48. firstadd=0
  49. matcheckname=""
  50. if countobj>0:
  51. for i in range(0,countobj):
  52. SelectAll()
  53. obj=GetSelectedObjectByIndex(i)
  54. SelectOnly (obj)
  55. countmaterial=obj.CountMaterials ()
  56. if countmaterial>0:
  57. for j in range (0,countmaterial):
  58. DeselectAll()
  59. SelectOnly (obj)
  60. index=obj.Material (j).CountLayers()
  61. if obj.Material (j).GetSubLayer(index-1).Name()!=matcheckname and obj.Material (j).Type()==0:
  62. addlayer=obj.Material(j).AddLayer((index),matname)
  63. if firstadd==0:
  64. firstadd=1
  65. matcheckname=obj.Material (j).GetSubLayer(index).Name()
  66. DeselectAll()
  67. #----------------------------------------------
  68. # Refresh Vue's Display
  69. #----------------------------------------------
  70. Refresh()
  71. #----------------------------------------------
  72. # End of Script
  73. #----------------------------------------------

addlayertoalltop.py

  1. #******************************************************
  2. # Adds a material layer on the top of all the other
  3. # layers on every material in a scene that isn't a
  4. # mixed material or other material that can't accept
  5. # layers
  6. #
  7. # - addlayertoalltop.py
  8. # - By Mark Caldwell
  9. # - Version 0.4
  10. # - Version 0.4 27th September 2009
  11. # - Copyright Mark Caldwell 2009
  12. # - Tested with Vue 7.5 Infinite
  13. #
  14. # How to use in 3 easy steps
  15. #
  16. # 1. Download this file onto your computer
  17. #
  18. # 2. Edit the python script to set the material to
  19. #    be added as a layer following the instructions
  20. #    below
  21. #
  22. # 3. Then run script and wait for it to work
  23. #    To run it go to Python -> Run Python Script
  24. #    Then locate the file on your computer
  25. #
  26. #******************************************************
  27. #----------------------------------------------
  28. # Configuration: Change matname to change the
  29. # material to be added.  Matname should be
  30. # set to the filename of the material to be
  31. # used but don't put .mat on the end.
  32. # It may not be the same as the material name
  33. # displayed in Vue.
  34. #
  35. # For example the material Varnish has a filename
  36. # Varnish 1.mat so to use it you would replace
  37. # Default on the line below with Varnish 1
  38. # so the line would read matname="Varnish 1"
  39. #----------------------------------------------
  40. matname="Default"
  41. #----------------------------------------------
  42. # Do Not Edit Anything After Here
  43. #----------------------------------------------
  44. #----------------------------------------------
  45. # Find Selected Objects Calculate the Centre
  46. #----------------------------------------------
  47. SelectAll()
  48. countobj=CountSelectedObjects()
  49. firstadd=0
  50. matcheckname=""
  51. if countobj>0:
  52. for i in range(0,countobj):
  53. SelectAll()
  54. obj=GetSelectedObjectByIndex(i)
  55. SelectOnly (obj)
  56. countmaterial=obj.CountMaterials ()
  57. for j in range (0,countmaterial):
  58. DeselectAll()
  59. SelectOnly (obj)
  60. if obj.Material (j).GetSubLayer(0).Name()!=matcheckname and obj.Material (j).Type()==0:
  61. addlayer=obj.Material(j).AddLayer((0),matname)
  62. if firstadd==0:
  63. firstadd=1
  64. matcheckname=obj.Material (j).GetSubLayer(0).Name()
  65. DeselectAll()
  66. #----------------------------------------------
  67. # Refresh Vue's Display
  68. #----------------------------------------------
  69. Refresh()
  70. #----------------------------------------------
  71. # End of Script
  72. #----------------------------------------------

addlayertoalltopnotrans.py

  1. #******************************************************
  2. # Adds a material layer on the top of all the other
  3. # layers on every material in a scene that isn't a
  4. # mixed material or other material that won't accept
  5. # layers and the material has nothing attached to its
  6. # transparency output node
  7. #
  8. # - addlayertoalltopnotrans.py
  9. # - By Mark Caldwell
  10. # - Version 0.4
  11. # - Version 0.4 27th September 2009
  12. # - Copyright Mark Caldwell 2009
  13. # - Tested with Vue 7.5 Infinite
  14. #
  15. # How to use in 3 easy steps
  16. #
  17. # 1. Download this file onto your computer
  18. #
  19. # 2. Edit the python script to set the material to
  20. #    be added as a layer following the instructions
  21. #    below
  22. #
  23. # 3. Then run script and wait for it to work
  24. #    To run it go to Python -> Run Python Script
  25. #    Then locate the file on your computer
  26. #
  27. #******************************************************
  28. #----------------------------------------------
  29. # Configuration: Change matname to change the
  30. # material to be added.  Matname should be
  31. # set to the filename of the material to be
  32. # used but don't put .mat on the end.
  33. # It may not be the same as the material name
  34. # displayed in Vue.
  35. #
  36. # For example the material Varnish has a filename
  37. # Varnish 1.mat so to use it you would replace
  38. # Default on the line below with Varnish 1
  39. # so the line would read matname="Varnish 1"
  40. #----------------------------------------------
  41. matname="Default"
  42. #----------------------------------------------
  43. # Do Not Edit Anything After Here
  44. #----------------------------------------------
  45. #----------------------------------------------
  46. # Find Selected Objects Calculate the Centre
  47. #----------------------------------------------
  48. SelectAll()
  49. countobj=CountSelectedObjects()
  50. firstadd=0
  51. matcheckname=""
  52. if countobj>0:
  53. for i in range(0,countobj):
  54. SelectAll()
  55. obj=GetSelectedObjectByIndex(i)
  56. SelectOnly (obj)
  57. countmaterial=obj.CountMaterials ()
  58. for j in range (0,countmaterial):
  59. DeselectAll()
  60. SelectOnly (obj)
  61. functiongraph=obj.Material (j).FunctionGraph ()
  62. countnodes=functiongraph.CountNodes()
  63. trans=0
  64. for k in range (0,countnodes):
  65. if functiongraph.NodeName (k)=="Transparency":
  66. for l in range (0,functiongraph.CountNodeInputs(k)):
  67. if functiongraph.InputConnection(k,l)[1]==1:
  68. trans=1
  69. if obj.Material (j).GetSubLayer(0).Name()!=matcheckname and obj.Material (j).Type()==0 and trans==0:
  70. addlayer=obj.Material(j).AddLayer((0),matname)
  71. if firstadd==0:
  72. firstadd=1
  73. matcheckname=obj.Material (j).GetSubLayer(0).Name()
  74. DeselectAll()
  75. #----------------------------------------------
  76. # Refresh Vue's Display
  77. #----------------------------------------------
  78. Refresh()
  79. #----------------------------------------------
  80. # End of Script
  81. #----------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017