• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Import XML programmatically

Explorer ,
Feb 01, 2017 Feb 01, 2017

Copy link to clipboard

Copied

Hello,

Is there an api to import an XML via extendscript?

thanks,

Kelly

TOPICS
SDK

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 01, 2017 Feb 01, 2017

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)

Votes

Translate

Translate
Explorer ,
Feb 01, 2017 Feb 01, 2017

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2017 Feb 01, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 02, 2017 Feb 02, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2017 Feb 02, 2017

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.

  1. APPROACH #1 app.openFCPXML() - (Errors out in Extendscript by highlighting the app.openFCPXML line)
  2. APPROACH #2 app.project.import() - (Errors out in Extendscript by highlighting the app.project.importFiles line)

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 02, 2017 Feb 02, 2017

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

Thanks Bruce. Seems I had a few things wrong.

  1. Needed a file path not a file object.
  2. Needed to select the target bin.

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

Nice, glad you got it working!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 01, 2022 Jun 01, 2022

Copy link to clipboard

Copied

LATEST

Is there a method I can import XML as string or does it need to be a filePath?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines