|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Creating an array by executing a string?
|
|
|
Hi,
I have some arrays that are created depending on incoming data. That’s why I would like to create them as needed using strings to build the names and execute to create them.
obj_id=1
val_group_num=2
o_buf_ary=#()
str_command = ("if o_buf_ary_"+obj_id as string+"_"+val_group_num as string+".count == undefined do ( \n global o_buf_ary_" + obj_id as string+"_"+val_group_num as string+"=#() \n o_buf_ary[o_buf_ary.count+1]=o_buf_ary_" + obj_id as string+"_"+val_group_num as string+"\n)")
execute str_command
So first it checks to see if an array with that name exists. If not, it creates an empty array, then adds that new array to an existing array that stores all of these dynamically created arrays.
Problem is, I’m not sure the array is being created. Is there something wrong with this code?
Thanks,
Adnan
|
|
|
|
-- str_command is:
if o_buf_ary_1_2.count == undefined do (
global o_buf_ary_1_2 = #()
o_buf_ary[o_buf_ary.count+1] = o_buf_ary_1_2 )
-- it return error: -- Unknown property: "count" in undefined -- that comes from "if o_buf_ary_1_2.count ..."
-- without '.count' will works:
if o_buf_ary_1_2 == undefined do (
global o_buf_ary_1_2 = #()
o_buf_ary[o_buf_ary.count+1] = o_buf_ary_1_2 )
o_buf_ary --> #(#()) o_buf_ary[1] == o_buf_ary_1_2 --> true
Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.
|
|
|
|
Thanks for the reply Anubis!
I had tried it without .count also, without luck. It works if it is hardcoded without .count, but via strings within these loops it does not.
I ended u doing this to make it work:
-- create array if it does not exist
str_command = ("if o_buf_ary_"+obj_id as string+"_"+val_group_num as string+" == undefined do ( \n global o_buf_ary_" + obj_id as string+"_"+val_group_num as string+"=#() \n)")
execute str_command
str_command = ("o_buf_ary_"+obj_id as string+"_"+val_group_num as string + "[1+o_buf_ary_"+obj_id as string+"_"+val_group_num as string + ".count] = point2 " + w_pixel as string + " " + h_pixel as string)
execute str_command
tmp_o_buf_ary[tmp_o_buf_ary.count+1]=("o_buf_ary_" + obj_id as string+"_"+val_group_num as string)
o_buf_ary=makeUniqueArray tmp_o_buf_ary
sort o_buf_ary
I fed the name of the new array as a string into tmp_o_buf_ary, which I then removed duplicates from and sorted into o_buf_ary. I accessed these arrays by using execute (string).
-Adnan
|
|
|
|
|
|