[Closed] Character Assembly Load/Save Animation Error
Using 3ds Max 8. I was attempting to do the Chef Dance Character Assembly save/load animation tutorial (straight out of the tutorial section)– except that rather than save the file as .ANM (as the tutorial stated) I wanted to save it as a .XML animation file because I want to become familiar with .XAF and the motion mixer for Max Bone rigs… anyway…
When I click on the Save Animation button in the Character Assembly rollout… it starts the XML save process but then gives me the following error messagebox:
–Unable to convert: #(50.0) to type: String
and it brings up the XMLIO.ms script and highlights the last line in the default “else” statement in the function: fn array2xml arr arrElem = (…) block of code. The line “else > str = arr as string”
fn array2xml arr arrElem =
(
local str
if isValidNode arr[1] then
(
arrElem.setAttribute "type" "object"
str = "#("
for i=1 to (arr.count-1) do str += "$" + arr[i].name + ","
if arr.count > 0 then str += "$" + arr[arr.count].name
str += ")"
)
else
(
if arr.count > 20 then
(
str = "#("
for i=1 to (arr.count-1) do str += arr[i] as string + ","
if arr.count > 0 then str += arr[arr.count] as string
str += ")"
)
else
str = arr as string
)
arrElem.text = str
),
If I use the File Menu > Save Animation option it does write out an .XAF file but then when trying to use the “Insert Animation” on the Character Assembly rollout– it says it fails to open the file.
Can someone tell me what the problem is, or what I’m doing wrong, and/or how to fix it? Is there a problem or error in the script? Or a problem with that Chef tutorial character that causes the save to fail?
Someone please advise…
Here is the errors posted to the Listener from this failed save:
-- Error occurred in array2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 6042
-- Frame:
-- arr: #(50.0)
-- str: undefined
-- arrElem: IXMLDOMElement
-- called in i loop; filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 8886
-- Frame:
-- ctrl: undefined
-- sc: MAXObject
-- Prop: #(50.0)
-- i: 1
-- cls: ArrayParameter
-- saElem: IXMLDOMElement
-- called in subAnims2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9189
-- Frame:
-- propsElem: IXMLDOMElement
-- animElem: IXMLDOMElement
-- anim: Controller:Orientation_Constraint
-- subanims: #(#weight, #relative, #local_world)
-- called in ctrl2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 7062
-- Frame:
-- ctrl: Controller:Orientation_Constraint
-- keysElem: undefined
-- valueElem: undefined
-- kpElem: undefined
-- keyMap: undefined
-- animElem: IXMLDOMElement
-- ctrlElem: IXMLDOMElement
-- called in i loop; filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9178
-- Frame:
-- ctrl: Controller:Orientation_Constraint
-- sc: undefined
-- Prop: (quat 0 0 -0.707107 0.707107)
-- i: 2
-- cls: undefined
-- saElem: IXMLDOMElement
-- called in subAnims2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9189
-- Frame:
-- propsElem: IXMLDOMElement
-- animElem: IXMLDOMElement
-- anim: Controller:Position_Rotation_Scale
-- subanims: #(#position, #rotation, #scale)
-- called in ctrl2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 7062
-- Frame:
-- ctrl: Controller:Position_Rotation_Scale
-- keysElem: undefined
-- valueElem: undefined
-- kpElem: undefined
-- keyMap: undefined
-- animElem: IXMLDOMElement
-- ctrlElem: IXMLDOMElement
-- called in i loop; filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9178
-- Frame:
-- ctrl: Controller:Position_Rotation_Scale
-- sc: undefined
-- Prop: SubAnim:FK_Sub_Control
-- i: 43
-- cls: undefined
-- saElem: IXMLDOMElement
-- called in subAnims2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9189
-- Frame:
-- propsElem: IXMLDOMElement
-- animElem: IXMLDOMElement
-- anim: Controller:IKControl
-- subanims: #(#PosXActive, #PosXLLimited, #PosXULimited, #PosXLimited, #PosXLLimit, #PosXULimit, #PosYActive, #PosYLLimited, #PosYULimited, #PosYLimited, #PosYLLimit, #PosYULimit, #PosZActive, #PosZLLimited, #PosZULimited, #PosZLimited, #PosZLLimit, #PosZULimit, #RotXActive, #RotXLLimited, ...)
-- called in obj2xml(); filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 9999
-- Frame:
-- obj: $Chef_Bone_LPalm
-- chkTransform: true
-- chkCustAttrib: true
-- nodeElem: IXMLDOMElement
-- tmElem: IXMLDOMElement
-- chldElem: undefined
-- parentElem: IXMLDOMElement
-- tmc: Controller:IKControl
-- objElem: undefined
-- chkModifiers: true
-- modsElem: undefined
-- recurse: true
-- postCallback: postSaveCB()
-- chkBaseObject: true
-- called in c loop; filename: C:\Program Files\Autodesk\3dsMax8\stdplugs\stdscripts\baseLib\xmlIO.ms; position: 11644
-- Frame:
-- c: $Chef_Bone_LPalm
>> MAXScript Rollout Handler Exception: -- Unable to convert: #(50.0) to type: String <<
Can anyone at least replicate the errors I’m experiencing? :banghead:
Edit:
Ok, I got the script to work properly and write out the .xml file by changing the function as follows (highlighted changes in green):
fn array2xml arr arrElem =
(
local str
if isValidNode arr[1] then
(
arrElem.setAttribute "type" "object"
str = "#("
for i=1 to (arr.count-1) do str += "$" + arr[i].name + ","
if arr.count > 0 then str += "$" + arr[arr.count].name
str += ")"
)
else
(
if arr.count > [b]2[/b] then
(
str = "#("
for i=1 to (arr.count-1) do str += arr[i] as string + ","
if arr.count > 0 then str += arr[arr.count] as string
str += ")"
)
else
[b]str = "#(" + (arr[1] as string) + ")"[/b]
)
arrElem.text = str
),
Just a couple of questions:
[ol]
[li]Does anyone see how these minor edits could break anything else?[/li][li]Secondly, why does the Character Assembly “Save Animation” write out an .XML file, whereas the toolbar menu “File > Save Animation” writes out a .XAF ? There appears to be some minor differences in the text files… aren’t these suppose to be the exact same outputs? (ok so there are some embedded questions there… :hmm: )[/li][/ol]
I don’t have Max 8 around, but I am totally surprised that the conversion of an array to string fails at that place.
The whole point of checking whether the array has more than 20 elements or not is that until Max 7, calling print, format or as String on an array would only print the first 20 elements and then add … in the end.
This is the default behavior even today, but in Max 7, the context
with PrintAllElements ON …
was introduced which suppresses this behavior.
So in theory, that script could be totally rewritten to just say
fn array2xml arr arrElem =
(
local str
if isValidNode arr[1] then
(
arrElem.setAttribute "type" "object"
str = "#("
for i=1 to (arr.count-1) do str += "$" + arr[i].name + ","
if arr.count > 0 then str += "$" + arr[arr.count].name
str += ")"
)
else
(
with PrintAllElements on str = arr as string
)
arrElem.text = str
),
But given the crash you reported initially, this might or might not work…
There is really no obvious reason for ‘arr as string’ to throw an error like
MAXScript Rollout Handler Exception: – Unable to convert: #(50.0) to type: String <<
The alternative would be to remove the IF test against 20 and just use the THEN portion of it,
else
(
str = "#("
for i=1 to (arr.count-1) do str += arr[i] as string + ","
if arr.count > 0 then str += arr[arr.count] as string
str += ")"
)
Because it would work with any number of elements, from 0 to N.
In fact, I would suggest going with that modification. See if it helps…
Thank you so much Bobo for your reply. I changed the else block (dropping the IF test as you suggested) and that works to create the .XML file.
Just another curious question– Why does the Character Assembly Save & Insert Animation buttons use “.XML” file formats (a completely different format/schema from the Main Menu’s .XAF save/load animations)??? Because the Motion Mixer will only recognize the .XAF files for Max Objects, no?