Copy link to clipboard
Copied
Hello,
Is there an api to import an XML via extendscript?
thanks,
Kelly
Hi Kelly,
I presume you mean Final Cut XML. The API call to import it is the same as importing "normal" media files:
app.project.importFiles(importThese, // an array of file paths
1, // suppress warnings
targetBin); // a bin object to import to (retrieved from app.project)
Copy link to clipboard
Copied
Hi Kelly,
I presume you mean Final Cut XML. The API call to import it is the same as importing "normal" media files:
app.project.importFiles(importThese, // an array of file paths
1, // suppress warnings
targetBin); // a bin object to import to (retrieved from app.project)
Copy link to clipboard
Copied
Hey Kelly
If jingtaotan's answer doesn't work, or isn't what you're after, have a try with:
var result = app.openFCPXML(
fileToOpen
)
Or do you just want to read an arbitary XML and process it yourself? In that case
var result = window.cep.fs.readFile(fileToOpen);
And then use something like jQuery's parse XML to handle the result
https://api.jquery.com/jQuery.parseXML/
Hope it helps
Andy
Copy link to clipboard
Copied
Minor clarification: Andrew's first suggestion will not import an FCP XML into the current project; it will open the specified .xml file, AS a new project.
Copy link to clipboard
Copied
Well thank you all for your quick responses. However, I'm still having issues.
I've tried 2 different approaches.
I see the API's in the in the Data Browser. But no luck. Any ideas....Thanks.
I'm running:
Extendscript v4.0.0.1 Extendscript 4.5.5 ScriptUI 6.2.2
Premiere Pro 2015.4 Release 10.4.0 (30) Build
APPROACH #1 (Errors out in Extendscript by highlighting the app.openFCPXML line)
var fileToOpen = new File("/Users/ops.kanderson/Library/Application Support/FCPXMLModifier/Vanity Fair Black Sails Clip Pull.xml");
if (fileToOpen.exists) {
alert("found file");
var result = app.openFCPXML(fileToOpen);
} else {
alert("file not found");
}
APPROACH #2 (Errors out in Extendscript by highlighting the app.project.importFiles line)
var targetBin = "Targeted by PProPanel import";
var importThese = new Array();
var fileToOpen = new File("/Users/ops.kanderson/Library/Application Support/FCPXMLModifier/Vanity Fair Black Sails Clip Pull.xml");
//Check if bin exists - PASS
if (searchForBinWithName(targetBin)) {
alert("Found bin");
} else {
alert("Bin not found");
}
//Check for file exists - PASS
if (fileToOpen.exists) {
alert("found file");
importThese.push(fileToOpen);
app.project.importFiles(importThese, 1, targetBin);
} else {
alert("file not found");
}
function searchForBinWithName(nameToFind) {
var numItemsAtRoot = app.project.rootItem.children.numItems;
var foundBin = 0;
for (var i = 0; (numItemsAtRoot >0) && (i < numItemsAtRoot) && (foundBin === 0); i++) {
var currentItem = app.project.rootItem.children;
if ((currentItem) && currentItem.name == nameToFind) {
foundBin = currentItem;
}
}
return foundBin;
}
Copy link to clipboard
Copied
You're telling PPro to import a File object; it wants a path.
Try file.fsName.
The code above will still fail, if you don't (like PProPanel does) create the bin if it doesn't exist. Perhaps if it doesn't exist, pass no targetBin to importFiles()?
if (targetBin === 0) { | ||||||||
// If panel can't find the target bin, it creates it. | ||||||||
app.project.rootItem.createBin(nameToFind); | ||||||||
targetBin = $._PPP_.searchForBinWithName(nameToFind); | ||||||||
} | ||||||||
if (targetBin){ |
targetBin.select(); |
Copy link to clipboard
Copied
Thanks Bruce. Seems I had a few things wrong.
Here is my working code, if anyone would like to see it.
var filePathsArray = new Array();
var fileToOpen = "/Users/ops.kanderson/Library/Application Support/FCPXMLModifier/Vanity Fair Black Sails Clip Pull.xml";
var binName = 'Targeted by PProPanel import1';
//add file path to array
filePathsArray.push(fileToOpen);
var targetBin = searchForBinWithName(binName);
if (targetBin === 0) {
// If panel can't find the target bin, it creates it.
app.project.rootItem.createBin(binName);
targetBin = searchForBinWithName(binName);
}
if (targetBin){
targetBin.select();
app.project.importFiles(filePathsArray);
}
function searchForBinWithName(binName) {
var numItemsAtRoot = app.project.rootItem.children.numItems;
var foundBin = 0;
for (var i = 0; (numItemsAtRoot >0) && (i < numItemsAtRoot) && (foundBin === 0); i++) {
var currentItem = app.project.rootItem.children;
if ((currentItem) && currentItem.name == binName) {
foundBin = currentItem;
}
}
return foundBin;
}
Copy link to clipboard
Copied
Nice, glad you got it working!
Copy link to clipboard
Copied
Is there a method I can import XML as string or does it need to be a filePath?