ScriptSpot

Forum topic · Scripts Wanted

MS to resize an object's texture map

By Rokhound · 2012-10-16

Description

Hi everybody!

I'm new here and totaly new to maxscripting.

I've looked around and it seems possible but no clue how to get
it going. I'm looking for a script that will allow me to resize
the bitmap texture of a selected object.

For example a cube in scene has an 512x512 diff map assigned to
it and I would like to bring it down to 128 x 128

If anyone can steer to a right direction it would be much
appreciated.

Thank you!

RK

Comments (6)

Rokhound · 2012-10-17

Thanks! I think the problem is if I execute with the numPAD enter.

When I drag drop the script it seems to work fine.

Rokhound · 2012-10-16

Sure thing, will send it shortly. I'm using Max 2013.

miauu · 2012-10-16

Can you upload the test scene? Which max version?.

Rokhound · 2012-10-16

Thank you for the quick response Miauu

I went through it and slowly understanding scripting better.

But when I ran it I got this error from the listener:

-- Error occurred in anonymous codeblock; filename: ; position: 818; line: 28
-- Syntax error: at ), expected
-- In line: )

I can't seem to find the answer anywhere :/

Try this:

miauu · 2012-10-16


(
	local newMapSize = [128,128]
	local curObj = selection[1]
	local diffuseMapPath = curObj.material.DiffuseMap.filename
	--	slower but with better quality
	local texMap = bitmaptexture bitmap:(openBitmap diffuseMapPath)
	local theNewMap = renderMap texMap size:newMapSize filter:on
	
	/* 
	--	faster but with lower quality
	texMap = openBitmap diffuseMapPath
	theNewMap = bitmap newMapSize.x newMapSize.y
	copy texMap theNewMap
	
	*/
	
	--	show map in VFB
-- 	display theNewMap
	--	this will override the original diffuse map
	theNewMap.filename = diffuseMapPath
	save theNewMap
	close theNewMap
	freeSceneBitmaps()
	
	--	assign the resized map
	curObj.material.diffuseMap = Bitmaptexture bitmap:(openBitmap theNewMap.filename)
	showTextureMap curObj.material curObj.material.diffuseMap on
)