Execute on each object in the selection problem

Hello!I can't figure out how to do modPanel.addModToSelection (TurboSmooth ()) ui:on once for every object in my selection :(
if i use : for obj in selection do(modPanel.addModToSelection (TurboSmooth ()) ui:on) it will add the turbosmooth modifier as many times as the number of the objects in my selection :[
I want it to add the turbosmooth modifier once for every object that i have in my selection.Please help me

Comments

Comment viewing options

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

This may help you!

rollout mywinRoll "Add Modifier on group of Objects"
(
button DoBtn "Press to add modifier"

on DoBtn pressed do
(
currentSelection = selection as array

for ModLoop in currentSelection do
(
select ModLoop
max modify mode
addMod Edit_Poly --or whatever modifier you want
)
select currentSelection
)
)
CreateDialog mywinRoll

holycause's picture

you could write the beginning

you could write the beginning like this:

...
arr = selection as array
 
for i = 1 to arr.count do(
    addModifier arr[i](TurboSmooth())
    addModifier arr[i](Edit_Poly())
...
tedchirvasiu07's picture

I did it!rollout Divide

I did it!

rollout Divide "Divide"(

button divide "Divide"

on divide pressed do(
----------
arr = selection as array

for obj in selection do( addModifier obj (TurboSmooth()) )
for obj in selection do( addModifier obj (Edit_Poly()))

for i = 1 to arr.count do(

max modify mode
select arr[i]
subobjectlevel = 4

arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}
arr[i].modifiers[#Edit_Poly].Select #Face #{1..16}
arr[i].modifiers[#Edit_Poly].SetOperation #SetMaterial
arr[i].modifiers[#Edit_Poly].materialIDToSet = 1
arr[i].modifiers[#Edit_Poly].Commit ()

arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}
arr[i].modifiers[#Edit_Poly].Select #Face #{17..32}
arr[i].modifiers[#Edit_Poly].SetOperation #SetMaterial
arr[i].modifiers[#Edit_Poly].materialIDToSet = 2
arr[i].modifiers[#Edit_Poly].Commit ()

arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}
arr[i].modifiers[#Edit_Poly].Select #Face #{33..48}
arr[i].modifiers[#Edit_Poly].SetOperation #SetMaterial
arr[i].modifiers[#Edit_Poly].materialIDToSet = 3
arr[i].modifiers[#Edit_Poly].Commit ()

arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}
arr[i].modifiers[#Edit_Poly].Select #Face #{49..64}
arr[i].modifiers[#Edit_Poly].SetOperation #SetMaterial
arr[i].modifiers[#Edit_Poly].materialIDToSet = 4
arr[i].modifiers[#Edit_Poly].Commit ()
arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}

-----------------------------------------------------------------------

arr[i].modifiers[#Edit_Poly].selectByMaterialID = 1
arr[i].modifiers[#Edit_Poly].ButtonOp #SelectByMaterial

arr[i].modifiers[#Edit_Poly].ButtonOp #DetachFace
arr[i].modifiers[#Edit_Poly].DetachToObject "Objectdude"
arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}

arr[i].modifiers[#Edit_Poly].selectByMaterialID = 2
arr[i].modifiers[#Edit_Poly].ButtonOp #SelectByMaterial

arr[i].modifiers[#Edit_Poly].ButtonOp #DetachFace
arr[i].modifiers[#Edit_Poly].DetachToObject "Objectdude"
arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}

arr[i].modifiers[#Edit_Poly].selectByMaterialID = 3
arr[i].modifiers[#Edit_Poly].ButtonOp #SelectByMaterial

arr[i].modifiers[#Edit_Poly].ButtonOp #DetachFace
arr[i].modifiers[#Edit_Poly].DetachToObject "Objectdude"
arr[i].modifiers[#Edit_Poly].SetSelection #Face #{}

arr[i].modifiers[#Edit_Poly].selectByMaterialID = 4
arr[i].modifiers[#Edit_Poly].ButtonOp #SelectByMaterial

arr[i].modifiers[#Edit_Poly].ButtonOp #DetachFace
arr[i].modifiers[#Edit_Poly].DetachToObject "Objectdude"

--End by deleting the object
delete arr[i]

)
)
)

createdialog divide

The array fixed it!Thank you for your help,guys :)

However,can someone help me improve it?My computer always freezes if there are more than 128 chunks :(
Obviously,this is not the "healthiest" code :S
What can i do to improve performance?

br0t's picture

Hey, you could try wrapping

Hey, you could try wrapping your code in a no-redraw context, so the viewport will not have to update during script execution.

with redraw off
(
     ...
)

Also, are you using the material IDs just to detach the faces or do you need them also for other stuff? If not, you could detach the faces directly without going over material IDs.

Never get low & slow & out of ideas

tedchirvasiu07's picture

Awesome but still...

Awesome,thanks!But what to do with the rest of the code ? :

subobjectlevel = 4
obj.modifiers[#Edit_Poly].SetSelection #Face #{}
obj.modifiers[#Edit_Poly].Select #Face #{1..16}
obj.modifiers[#Edit_Poly].SetOperation #SetMaterial
obj.modifiers[#Edit_Poly].materialIDToSet = 1
obj.modifiers[#Edit_Poly].Commit ()

obj.modifiers[#Edit_Poly].selectByMaterialID = 1
obj.modifiers[#Edit_Poly].ButtonOp #SelectByMaterial

obj.modifiers[#Edit_Poly].ButtonOp #DetachFace
obj.modifiers[#Edit_Poly].DetachToObject "Objectdude"
obj.modifiers[#Edit_Poly].SetSelection #Face #{}

I need the same thing :( Please help

br0t's picture

Well as the cmd says, it adds

Well as the cmd says, it adds the modifier to the current selection. your selection does not change during the loop, so it adds up. Instead of using the modPanel.addMod command you could better use this:

for obj in selection do addModifier obj (TurboSmooth())

Cheers

Never get low & slow & out of ideas

Comment viewing options

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