PDA

View Full Version : way to skip if modifer exists


originalfake
10-25-2007, 06:30 AM
hey,

I have this script:

for obj in $ do
(
randVal = random 0 20
for i in selection do addModifier i (Materialmodifier())
obj.modifiers[#Material].materialID = randvVal
)

The problem I'm encountering is when I select multiple objects
to assign random Material ID's to them it applys more then one
modifier.
I.e. If I select three boxes and run the script it adds 3 modifiers
to each box, if I select one box, only one modifier is added.

I've come to the conclusion that I need to work out a
statement to bypass adding a new modifier if one already exists.

Any help would be greatly appreciated!
Cheers

focomoso
10-25-2007, 10:11 PM
It’s because you have two for loops that do the same thing. The first (for obj in $ do) one steps through all the selected objects and the second one does the same (for i in selection do).

Try deleting the second for loop making that line read just:

addModifier obj (Materialmodifier())

and see what happens.

focomoso
10-25-2007, 10:15 PM
Actually, try this:


for obj in selection do (
randVal = random 0 20
matMod = Materialmodifier()
matMod.materialID = randVal
addModifier obj matMod
)

originalfake
10-26-2007, 12:53 AM
awesome, worked a charm!

thank you!

focomoso
10-26-2007, 05:48 AM
Good on ya mate. (sorry, couldn't resist)

originalfake
10-26-2007, 06:50 AM
hah! nice use of the lingo ;)

CGTalk Moderation
10-26-2007, 06:50 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.