-
How get to acccess XML Elements in After Effects after importing data?
I posted something similar to this earlier today using JSon, but giving up on that I’ve switched to XML. Can someone show me what I am doing wrong here? I have an xml file that I am parsing through a script in After Effects, and I’m not sure how to get access to the XML elements.
My XML file is:
<?xml version="1.0" encoding="utf-8"?> <root> <f> <accelX>0.4682</accelX> <accelY>-0.0352</accelY> <accelZ>-0.9247</accelZ> <gyroX>0.0555</gyroX> <gyroY>0.004</gyroY> <gyroZ>-0.0684</gyroZ> </f> <f> <accelX>-0.4682</accelX> <accelY>-0.0219</accelY> <accelZ>-0.9186</accelZ> <gyroX>0.0049</gyroX> <gyroY>0.0851</gyroY> <gyroZ>-0.046</gyroZ> </f> </root>And my jsx file is this:
var file = new File; var check = 0; var mainWindow = new Window("palette", "File Reader", undefined); mainWindow.orientatizzaaq1on = "column"; var groupOne = mainWindow.add("group", undefined, "groupOne"); groupOne.orientation = "row"; var fileLocBox = groupOne.add("edittext", undefined, "Selected File Location"); fileLocBox.size = [150, 20]; var getFileButton = groupOne.add("button", undefined, "File..."); getFileButton.helpTip = "Select a .json file to change the comp"; var groupTwo = mainWindow.add("group", undefined, "groupTwo"); groupTwo.orientation = "row"; var applyButton = groupTwo.add("button", undefined, "Apply"); mainWindow.center(); mainWindow.show(); getFileButton.onClick = function() { file = file.openDlg("Open a file", "Acceptable Files:*.xml"); fileLocBox.text = file.fsName; check = 1; } applyButton.onClick = function() { if(check == 0) { alert("Please select a file"); return false; } else { //app.beginUndoGroup("Comp Changes"); var fileExtension = fileLocBox.text; var fileData; if(fileExtension.substring(fileExtension.length-4, fileExtension.length) == "json") { fileData = readJson(); } else { switch(fileExtension.substring(fileExtension.length-3, fileExtension.length)) { case "txt": //fileData = readTxt(); break; case "xml": fileData = readXml(); break; } } changeComp(fileData); } alert("done"); } function readXml() { file.open("r"); var xmlString = file.read(); var myXml = new XML(xmlString); file.close(); return myXml; } function changeComp(data) { var nullz = app.project.activeItem.laayers.addNull(); nullz.threeDLayer = true; nullz.name = "parent to me"; for (i = 0; i < 20; i++) { var temp = data.f[i].accelX; var t =i/25; nullz.xRotation.setValueAtTime(t, temp); } }This is the line, near the end, that isn’t working:
var temp = data.f[i].accelX;Am I writing this incorrectly? After Effects will create one keyframe with a value of “0”, but doesn’t finish the for…loop and doesn’t complete the script. Am I accessing these elements incorrectly?