ScriptSpot

Forum topic · General Scripting

SCript to change material "show in viewport"

By windrock · 2010-12-31

Description

Hi all and happy new year!

Somthing tells me this 'could' be easy...

I am trying to make a script that will automatically change every material that is in the current scene so they do NOT 'show standard map in viewport'. Does anyone have an idea on the code for this?

Comments (3)

Garp · 2011-01-02

Some texture maps can have nested texture maps in them. But it would be tedious to go through all of them turning them off.
A workaround is to force the material to on, then off.

fn offShowInViewport theMat =
(
	if (numSubMtls = getNumSubMtls theMat) != 0 then
		for i = 1 to numSubMtls do
			offShowInViewport (getSubMtl theMat i)
	else
	(
		theMat.showInViewport = true
		theMat.showInViewport = false
	)
)

for m in sceneMaterials do offShowInViewport m

windrock · 2011-01-01

Thanks alot. The code below is working except for one problem. If there is no diffusemap in the slot, the script halts. Would you know how to add a check to see if a diffuse map exists before proceeding?

(
for object in selection do
if (classOf object.material == Vraymtl) then
(
object.material.showInViewport = off
showTextureMap object.material object.material.diffusemap off
)
else if (classOf object.material == Multimaterial) then
(
for b = 1 to b = object.material.numsubs do
(
if (classOf object.material.materialList[b] == Vraymtl) then
(
object.material.showInViewport = off
)
)
)
updateToolbarButtons()
)

hedphelym · 2010-12-31

here's a script.
source : http://www.polycount.com/forum/showthread.php?t=76143

for object in selection do

if (classOf object.material == Standard) then
(
object.material.showInViewport = off

)
else if (classOf object.material == Multimaterial) then
(
for b = 1 to b = object.material.numsubs do
(
if (classOf object.material.materialList[b] == Standard) then
(
object.material.showInViewport = off

)
)
)