7 Replies Latest reply on Feb 2, 2017 12:33 PM by Bruce Bullis

    Import XML programmatically

    Kelly Anderson Level 1

      Hello,

       

      Is there an api to import an XML via extendscript?

       

      thanks,

      Kelly

        • 1. Re: Import XML programmatically
          jingtaotan Level 1

          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)
          
          • 2. Re: Import XML programmatically
            andymees@aje Level 3

            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

            • 3. Re: Import XML programmatically
              Bruce Bullis Adobe Employee

              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.

              • 4. Re: Import XML programmatically
                Kelly Anderson Level 1

                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[i];

                  if ((currentItem) && currentItem.name == nameToFind) {

                  foundBin = currentItem;

                  }

                  }

                  return foundBin;

                }

                • 5. Re: Import XML programmatically
                  Bruce Bullis Adobe Employee

                  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();
                  • 6. Re: Import XML programmatically
                    Kelly Anderson Level 1

                    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[i];

                           if ((currentItem) && currentItem.name == binName) {

                                foundBin = currentItem;

                           }

                       }

                      return foundBin;

                    }

                    • 7. Re: Import XML programmatically
                      Bruce Bullis Adobe Employee

                      Nice, glad you got it working!