AREA forums upgrade
Read more about the planned upgrade of our forums
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / iterate through objects
IMPORTANT ANNOUNCEMENT ABOUT AREA FORUMS
  RSS 2.0 ATOM  

iterate through objects
Rate this thread
 
71239
 
Permlink of this thread  
avatar
  • d2d2
  • Posted: 17 September 2012 10:38 AM
  • Total Posts: 6
  • Joined: 17 September 2012 10:17 AM

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.



Replies: 0
avatar
  • barigazy
  • Posted: 17 September 2012 03:09 PM

something like this

fn multiplyPropByName arr prop: = 
(
 if 
arr.count != do
 (
 for 
obj in arr where isProperty obj prop do
 (
 
val ""
 
for 1 to obj.name.count where (obj.name[s] as number) != undefined do 
 (
 if 
val.count == and (obj.name[s] as number) > or val.count do append val obj.name[s]
 
)
 if 
val.count != 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:[(i*12), 00]
boxArr 
$Box* as array
multiplyPropByName boxArr prop:"height"


Replies: 1
/img/forum/light/default_avatar.png

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

Author: d2d2

Replied: 17 September 2012 08:56 PM  
avatar
  • barigazy
  • Posted: 17 September 2012 10:53 PM

Post your example to see what is wrong.



Replies: 1
/img/forum/light/default_avatar.png

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

I’m using this for particles though.

Author: d2d2

Replied: 17 September 2012 10:57 PM  
avatar
  • barigazy
  • Posted: 17 September 2012 11:06 PM

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!



Replies: 1
/img/forum/light/default_avatar.png

I’m sorry, I’m a newbie and I appreciate your help. I’ve already learned huge amount by your example, thank you.

Author: d2d2

Replied: 17 September 2012 11:13 PM  
avatar
  • d2d2
  • Posted: 17 September 2012 11:12 PM

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[s] as number) != undefined do
(
if val.count == 0 and (obj.name[s] as number) > 0 or val.count > 0 do append val obj.name[s]
)
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



Replies: 0
avatar
  • barigazy
  • Posted: 18 September 2012 12:38 AM

Try now.
If you select some supersprays then script will operate on selection otherwise it will all be taken in calculation.
link superspray test



Replies: 0
avatar
  • d2d2
  • Posted: 18 September 2012 01:43 AM

Brilliant, thanks very much.



Replies: 0