ScriptSpot

Forum topic · Scripts Wanted

Set U and V tiling of all Bitmap textures of selection

By sketchupmaster · 2024-08-27

Description

Hello,

Here i am creating a script of Set U and V tiling of all Bitmap textures of selection
but script has bug and i can not solve it.

can any one correct the script

thanks


-- Function to set U and V tiling of all Bitmap textures in a V-Ray material to 1.0
fn setVrayMaterialTilingToOne mat =
(
-- Function to set tiling for a Bitmap texture
fn setBitmapTiling tex =
(
if classOf tex == Bitmaptexture do
(
tex.U_Tiling = 1.0
tex.V_Tiling = 1.0
)
)

-- Check and set tiling for all relevant maps in V-Ray material
if (mat != getClassInstances vraymtl) do
(
print mat
-- Diffuse map
if mat.diffuseMap != undefined do setBitmapTiling mat.diffuseMap

-- Bump map
if mat.bumpMap != undefined do setBitmapTiling mat.bumpMap

-- Reflection map
if mat.reflectionMap != undefined do setBitmapTiling mat.reflectionMap

-- Refraction map
if mat.refractionMap != undefined do setBitmapTiling mat.refractionMap

-- Specular map
if mat.specularMap != undefined do setBitmapTiling mat.specularMap

-- Self-illumination map
if mat.selfIllumMap != undefined do setBitmapTiling mat.selfIllumMap

-- Displacement map
if mat.displacementMap != undefined do setBitmapTiling mat.displacementMap

-- Coat map
if mat.coatMap != undefined do setBitmapTiling mat.coatMap

-- Check if the material is a Multi/Sub-Object material
if classOf mat == Multimaterial do
(
for i = 1 to mat.numsubs do
(
local subMat = mat[i]
setVrayMaterialTilingToOne subMat
)
)
)
)

-- Iterate over selected objects and set tiling for their V-Ray materials
for obj in selection do
(
-- local mat = getMaterial obj
local mat = getClassInstances vraymtl target:obj.mat
setVrayMaterialTilingToOne mat
)

Comments (2)

Try this:

SimonBourgeois · 2024-08-30


(
	fn setBitmapTiling BitmapsArr  =
	(
		for map in BitmapsArr do
		(
			map.coords.U_Tiling = 1.0
			map.coords.V_Tiling = 1.0
		)
	)

	local matArr =#()
	local bitmapArr=#()

	for obj in selection where obj.material != undefined do join matArr (getClassInstances VRayMtl target:obj.material) --create an array for all VRayMtl,it collects all VRayMtl within multisub or blend or other type of materials
	
	for m in matArr do
	(
		join bitmapArr (getClassInstances Bitmaptexture target:m) --add all Bitmaps to bitmapArr
		join bitmapArr (getClassInstances VRayBitmap target:m) --add all VrayBitmaps to bitmapArr
	)
	makeUniqueArray bitmapArr --filterout bitmaps that have been collected multiple times (if the same bitmaps are used in multiple materials)

	setBitmapTiling bitmapArr --launch the function for every collected bitmaps
) 

Thank you so much . . . :)

sketchupmaster · 2024-09-01

It is working and all fine.