Notifications
Clear all

[Closed] Script to show textures in viewport?

Hey guys, i tryed messing around trying to create a test script to actiave the “view map in viewport” button in the material editor, but it doesnt seem to work. So does anyone have a script that goes through and enables all of these on all the materials in the scene?

Cheers

10 Replies
 mef

This should work.

————————–Code Start—————————

for pckdObj in 1 to selection.count do
(
x = $selection
showTextureMap x[pckdObj].material on
)– end for loop

————————–Code End—————————–

Marc

The code below cycles through all the subAnims of the scene materials, finds the material super classes and turns their show in viewport on or off.

As far as I can see it doesn’t work on Shellac materials but it should work on everything else (hopefully), it does step through Multi/Submaterials as well.

fn ShowMaterials obj bOn =
  (
  	if obj.numSubs > 0 then
  		for i = 1 to obj.numsubs do ShowMaterials obj[i] bOn
  	
  	if superclassof obj == Material then try (showTexturemap obj bOn) catch()
  )
  
  -- for mat in sceneMaterials do ShowMaterials mat off -- switches textures off
  for mat in sceneMaterials do ShowMaterials mat on -- switches textures on
  

Hope this helps.

cool guys, ill give this a try tommorow

heres yet another way to do it, though mine was, until a few seconds ago, set to shut off the mat in viewport of selected objects… i use vray, which has a different diffusemat name…

replace the showMatInViewport function with anything you’d like to do to all materials that are on the selected objects…

/shrug


 fn showMatInViewport mat =
 (
 	if (mat != undefined) do
 	(
 		--this works for all materials
 		mat.showinviewport = true
 		
 		--but there could also be the show in viewport of just the bitmaps..
 		
 		--so if it was a standard material
 		if classof mat ==  Standardmaterial then
 		   (
 			-- then we use the .diffusemap object of the material
 			if (mat.diffusemap != undefined) then showTextureMap mat mat.diffusemap on
 		   )
 		--if it wasn't a standard material, check if its a vraymaterial
 		else if classof mat ==  Vraymtl then
 		   (
 			--and then we try and shut off the .texmap_diffuse map
 			if (mat.texmap_diffuse != undefined) then showTextureMap mat mat.texmap_diffuse on
 		   )
 	)
 )--end function
 
 
 -- teh script
 sel = selection as array
 for n = 1 to sel.count do 
 (
 	if classof sel[n].material ==  Multimaterial then 
 	(
 		for i in 1 to sel[n].material.numsubs do
 		(
 			showMatInViewport sel[n].material.materiallist[i]
 		)
 	)
 	else 
 	(
 		showMatInViewport sel[n].material
 	)
 )
 

Is there any way to determine if a material has showTextureMap on or off? I am trying to build a toggle for switching materials on and off at the click of a switch, and for the switch to show the status of ‘showtexturemap’ (if thats possible)

Any suggestions?

I can’t believe there is no way to see if a material has the ‘view material in viewport’ toggle set.

you could try:

print $.material.showInViewport

ah, sorry, I should have been more clear… it was the material maps that I couldn’t work out how to check for their viewport visibility.

the showinviewport variable only works on the top level of a material as far as I can tell.

can you get to show the final blend map result in the viewport…??? right now i dont know how to show my blend result in the viewport, it only shows one of the three maps i.e Diffuse0, diffuse1 or the alpha

Page 1 / 2