iterate through objects

iterate through objects

Anonymous
Not applicable
537 Views
9 Replies
Message 1 of 10

iterate through objects

Anonymous
Not applicable
Hi,
I'm trying to create a simple script that iterates through objects and increments a property according to object name suffix (01,02,03,04,05 etc)

01 - leave property as is
02 - multiply by 2
05 - multiply by 5 etc


for i = 1 to selection.count do
(
selection.property = i*5
)

Thanks in advance.
0 Likes
538 Views
9 Replies
Replies (9)
Message 2 of 10

barigazy
Enthusiast
Enthusiast
something like this
fn multiplyPropByName arr prop: = 
(
if arr.count != 0 do
(
for obj in arr where isProperty obj prop do
(
val = ""
for s = 1 to obj.name.count where (obj.name as number) != undefined do
(
if val.count == 0 and (obj.name as number) > 0 or val.count > 0 do append val obj.name
)
if val.count != 0 do
(
format "value = %\n" val
val = val as number
currVal = getProperty obj prop
setProperty obj prop (currVal*val)
)
)
)
)
--example
for i in 1 to 10 do Box width:10 length:10 height:2 pos:
boxArr = $Box* as array
multiplyPropByName boxArr prop:"height"
0 Likes
Message 3 of 10

Anonymous
Not applicable
Thanks, so much for help. While putting to amazing piece of code it returns an error: unknown property count in undefined highlighting (3rd line) if arr.count != 0 do
0 Likes
Message 4 of 10

barigazy
Enthusiast
Enthusiast
Post your example to see what is wrong.
0 Likes
Message 5 of 10

Anonymous
Not applicable
for i in 1 to 10 do
boxArr = $Obj* as array
multiplyPropByName boxArr prop:"viewPercent"

I'm using this for particles though.
0 Likes
Message 6 of 10

barigazy
Enthusiast
Enthusiast
If function *fn multiplyPropByName arr prop: =* first argument must by array of nodes (maxobject) e.i:
arr = selection as array
--or
arr = objects as array
--or
arr = geometry as array
--or (lights,helpers,cameras etc.)

Second argument is property string ("width", "height", "radius" etc.)
If you want to set property of some modifiers then i need to change code.
This is why i need your example, or post some screenshots
Cheers!
0 Likes
Message 7 of 10

Anonymous
Not applicable
macroScript OperationX category: "PFun"
(
fn multiplyPropByName arr prop: =
(
if arr.count != 0 do
(
for obj in arr where isProperty obj prop do
(
val = ""
for s = 1 to obj.name.count where (obj.name as number) != undefined do
(
if val.count == 0 and (obj.name as number) > 0 or val.count > 0 do append val obj.name
)
if val.count != 0 do
(
format "value = %\n" val
val = val as number
currVal = getProperty obj prop
setProperty obj prop (currVal*val)
)
)
)

)
rollout particles_rollout "Operation X"
(
for i in 1 to 10 do
boxArr = $Obj* as array
multiplyPropByName boxArr prop:"viewPercent"
)--end on
)--end rollout
createDialog particles_rollout 250 100
)

by the way I'm using this on SuperSpray
0 Likes
Message 8 of 10

Anonymous
Not applicable
I'm sorry, I'm a newbie and I appreciate your help. I've already learned huge amount by your example, thank you.
0 Likes
Message 9 of 10

barigazy
Enthusiast
Enthusiast
Try now.
If you select some supersprays then script will operate on selection otherwise it will all be taken in calculation.
link superspray test
0 Likes
Message 10 of 10

Anonymous
Not applicable
Brilliant, thanks very much.
0 Likes