[Closed] Get Filename and change path problem
Hello folks !
I have a small problem with maxscript.
I have a bank of high def tree texture. I made a low directory with low def tree texture
in it. I wanna make a script that switch the high def texture by the low one on several objects.
i made a script which store map filename, change the path to reapply it in diffusemap and opacitymap slots.
But it return me an error.
This is my script
for obj in selection do
(
Diffmap = filenamefrompath (obj.material.diffusemap.filename)
Opacmap = filenamefrompath (obj.material.opacitymap.filename)
thePath = "F:\Maps\Vegetation\Trees\Low\"
obj.material.diffusemap.filename = thePath + Diffmap
obj.material.opacitymap.filename = thePath + Opacmap
)
This the error :
– Syntax error: at bad, expected <keyword arg>
– In line: obj.material.diffusemap.filename = “F:\M
Check out maxscript string literals in help. Use \ for the \ character in a pathname, or use /
Thank you Professor420 !!
That’s it ! :bounce:
I gonna loose my mind to change severals maps
You saved my mind
By separating your function calls out of the original code it might allow for some easily changable ways, also you need to make sure the alternative low/high quality map exists before changing the filename, this checks to make sure BOTH exist before changing either.
global switchToQualityTexture
global rlt_SwitchTextureQuality
if rlt_SwitchTextureQuality != undefined then destroyDialog rlt_SwitchTextureQuality
fn switchToQualityTexture theobjs pathToQualityTexture = (
for o in theobjs do (
try (
local tempDiffuseMap = pathToQualityTexture + (filenameFromPath (o.material.diffusemap.filename))
local tempOpacityMap = pathToQualityTexture + (filenameFromPath (o.material.opacityMap.filename))
if doesFileExist tempDiffuseMap and doesFileExist tempOpacityMap then (
o.material.diffuseMap.filename = tempDiffuseMap
o.material.opacityMap.filename = tempOpacityMap
)
) catch ()
)
)
rollout rlt_SwitchTextureQuality "Switch Texture Quality" (
button btn_highQuality "High Quality"
button btn_lowQuality "Low Quality"
on btn_highQuality pressed do (
switchToQualityTexture (selection as array) "F:\\Maps\\Vegetation\\Tress\\High\\"
)
on btn_lowQuality pressed do (
switchToQualityTexture (selection as array) "F:\\Maps\\Vegetation\\Tress\\Low\\"
)
)
createDialog rlt_SwitchTextureQuality 100 65
Thank you a lot MoonDoggie !
I’ll test your script. Thanks for your help.
I didn’t test it, because I don’t have the same needs, post with syntax errors and whatnot, but it should work and should give you a good indication for future scripts.
-Colin