loop through objects

Hi.

I no doubt know this is a easy fix but and help would be most apreciated.

I can apply and randomise a UVW map easily enough but I'm having trouble counting the objects selected and looping through the script for each object.

The general idea is to say randomise a stone texture over several tiles.

My poor ass script is as follows :

arr = $.count
mapSize = 500

for i = 1 to arr do
(
modPanel.addModToSelection (Uvwmap ()) ui:off
$.modifiers[#UVWMapping].maptype = 4
$.modifiers[#UVWMapping].length = mapSize
$.modifiers[#UVWMapping].width = mapSize
$.modifiers[#UVWMapping].height = mapSize
$.modifiers[#UVWMapping].gizmo.rotation = (quat (random -20 20) (random -20 20) (random -20 20) (random -20 20))

maxOps.CollapseNode $ off

)

Any Help would be most apreciated.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

2 loop manners exist

You can loop through in any collection in 2 ways - by-item and by-index. If you use by-index for selection w'd looks like:
for i=1 to selection.count do ( selection[i]... )

But if you like to use modPanel.addModToSelection then you'd need to select only 1 object at a time. So in this case more appropriate w'd be to loop by-item.

mapSize = 500
theObjs = selection as array
clearSelection()
max modify mode
 
for obj in theObjs do
(
	select obj
	uvwMod = Uvwmap maptype:4
	uvwMod.length = uvwMod.width = uvwMod.height = mapSize
	angVals = for i=1 to 4 collect (random -20 20)
	rotVal = (quat angVals[1] angVals[2] angVals[3] angVals[4])
	uvwMod.gizmo.rotation = rotVal
	modPanel.addModToSelection uvwMod ui:off
	maxOps.CollapseNode obj off
)

hope this help

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.