Hello,
I’m working on a rather large script, but one problem I have so far is that flattening UVs for an object doesn’t seem to be working inside of a loop (this is just an example script, but it displays the same behavior).
In the example below, the script just creates several spheres, applies a standard material w/ a checker texture, and attempt to flatten them all in a loop, and then it manually selects two of them, and then performs the same function, but it only works on those selected ones, and not those in the loop.
(
resetMaxFile()
--resetMaxFile #noPrompt
fn flattentheUVs whatObject angleDeg =
(
max modify mode
addModifier whatObject (Unwrap_UVW ()) ui:on
whatObject.modifiers[#unwrap_uvw].setMapChannel 1
whatObject.modifiers[#unwrap_uvw].flattenMap angleDeg #() 0.01 true 0 true true
)
checkMap = checker Color1:black Color2: white --checker texture for the example
checkMap.coordinates.uTiling = checkMap.coordinates.vTiling = 4
sphArray = #() --empty array to eventually contain all the spheres
offset = 100
for i = 1 to 100 by 20 do
(
aSphere = convertToPoly(Sphere pos:[0,i * 2, offset*sin(i)] radius: 5 material: (standard diffusemap:checkMap))
showTextureMap aSphere.material true
append sphArray aSphere
)
for o in geometry where canconvertto o Editable_Poly do
(
convertToPoly o
--max modify mode --doesn't appear to fix the problem
flattentheUVs o 55
)
--iterating through the array below also doesn't work
/* for o = 1 to sphArray.count do
* (
* convertTopoly sphArray[o]
* flattentheUVs sphArray[o] 55
* )
*/
--works outside of a loop though
select $'Sphere01'
flattentheUVs $ 55
select $'Sphere03'
flattentheUVs $ 55
select $'Sph*'
actionMan.executeAction 0 "311" -- Tools: Zoom Extents All Selected
actionMan.executeAction 0 "50026" -- Tools: Maximize Viewport Toggle
)
I’ve done several things from restructuring the for loop structure, etc., as from what I understand, it could be something to do with a possible Maxscript optimization of for loops (i.e.-not returning any results until completion), but I’m not sure just yet.