[Closed] Array as String truncated
I’ve been storing arrays as strings and then accessing them using (execute string) with no problems.
Now, running this code:
allChildren = join #() $
tempHiddenStates = #()
for i in allChildren do
(
obj = i.inode.handle
append tempHiddenStates #(obj, (maxOps.getNodeByHandle obj).isHidden)
)
hiddenStates = tempHiddenStates as string
Im get the following string:
“#(#(6400, false), #(5767, false), #(5769, false), #(5768, false), …)”
The above string is shortened for clarity, the string actually prints out 20 array items before cutting off. tempHiddenStates.count = 73. Obviously having the string end with “, …)” causes an error when I try to execute, not to mention the 53 missing array entries. Does anyone know why this is happening and how I can get it to stop? I’ve been writing much bigger arrays to strings without incident… maybe I’m just really tired but I can’t figure out what’s different about this one. Thanks for any clues.
Can I ask why you store arrays into strings? I think that it’s a bad practice but anyway, try this:
allChildren = getCurrentSelection()
tempHiddenStates = #()
hiddenStates = "#("
for i=1 to allChildren.count do
(
obj = allChildren[i].inode.handle
hiddenStates += "#(" + obj as string + ", " + (maxOps.getNodeByHandle obj).isHidden as string + ( if i < allChildren.count then "), " else ")" )
)
hiddenStates += ")"
use options.printallelements = true. This will set a global switch which enables printing all elements of an array. Keep in mind this could lead to freezes if your arrays are indeed quite long. You can also use it as a context.
Check out the docs for more info: http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/files/GUID-92B98D11-60FF-4742-A1BA-692EE135E085.htm
Thanks Nick,
So basically the same approach to building a dynamic rollout or something.
Klaas,
I had no idea about this! Thanks! I guess my arrays have all been less than 20 elements but I thought they were bigger because they’ve been multi-dimensional with pretty big sub-elements? Anyway, this should make things work the way I need.