9 Replies Latest reply on Mar 22, 2018 6:36 AM by PrashantGupta

    Toggle options in Publish settings with Javascript Code?

    ExtraMurque Level 1

      Hello Community,

       

      I seem not be able to find the javascript code for an automated toggle of an option in the Publish settings.

      For months I am looking for some script codes, but without success.

       

       

      I need to export multiple layers as a separate .swf file, per created Animate document.
      So I need to manually deselect the option here:

      In the File > Publish Settings menu, switch to the Advanced tab: Include hidden layers.

       

       

      I cannot find the javascript code to access this, or the complete codes to change the Quality and the Include hidden layers.

       

      Is there a possibility to have some lines of codes (that someone already found out somehow...), that I can glue just

      before I launch my Layer-Export-Script?

       

      publish settings.jpg

       

      Could you help me out?

      Any suggestions are greatly appreciated.

       

      Marc.

       

       

       

       

      Here is the code of the Export Layers Script as I have it now:

       

       

      var doc = fl.getDocumentDOM();

      var docTimeline = doc.getTimeline();

      var exportName;

       

      var layerNum;

      var layerSelection = docTimeline.getSelectedLayers();

      var layers = new Array();

      var count = 0

      var moreThanTenLayers = false

      var numberLayers = 0

       

      var folder = fl.browseForFolderURL("Choose an output directory");

      var docfoldername = doc.name

       

      if (docfoldername.slice (20,21) == "." || docfoldername.slice (20,21) == "_")

      {

          var exportDest = folder+ "/" +"EXPORT_" + docfoldername.slice (4,20)

      }else{

          var exportDest = folder+ "/" +"EXPORT_" + docfoldername.slice (4,21)

      }

       

       

      FLfile.createFolder(exportDest)

       

      // sort selection by layer index

      for ( var i=0;i<layerSelection.length;i++ )

      {

          for ( var j=0;j<layerSelection.length;j++ )

          {

              if (layerSelection[i] < layerSelection[j])

              {

                  var temp = layerSelection[i];

                  layerSelection[i] = layerSelection[j];

                  layerSelection[j] = temp;

              }

          }

      }

       

      for ( var it=0;i<layerSelection.length;it++ ) {

         var p = docTimeline.layers[layerSelection[it]]

          var layerName2 = p.name; //determinate file name

         

          if(layerName2.indexOf("#")>-1){

              }

          else{

              numberLayers = numberLayers + 1

             

            }

         

          if (numberLayers >9){

             moreThanTenLayers = true

             }

         }

       

       

       

      for ( var i=0;i<layerSelection.length;i++ )

      {

          // hide all layers but current

          for ( var j=0;j<docTimeline.layerCount;j++ )

          {

              //only deal with normal visible layers, remember their index

              if ( docTimeline.layers[j].visible == true && docTimeline.layers[j].layerType == "normal")

              {

                  layers.push (j);

                  docTimeline.layers[j].visible = false;

              } else {

                  docTimeline.layers[j].visible = false;

              }

          }

       

          // show layer

          var l = docTimeline.layers[layerSelection[i]]

          l.visible = true;

          var layerName = l.name; //determinate file name

             

          // export only one image if layer is the frame

          if (layerName.indexOf("#")>-1){

              }

          else{

          if (layerName.indexOf('CADRE')> -1 || layerName.indexOf('cadre')> -1 || layerName.indexOf('SECU')> -1 || layerName.indexOf('secu')> -1 || layerName.indexOf('BOARD')> -1 || layerName.indexOf('board')> -1 || layerName.indexOf('CACHE')> -1 || layerName.indexOf('cache')> -1 || layerName.indexOf('animatique')> -1 || layerName.indexOf('ANIMATIQUE')> -1)

          {

              fl.getDocumentDOM().getTimeline().setLayerProperty('layerType', 'normal');

              if (moreThanTenLayers = true){

              exportName = exportDest + "/" + "000" + "__" + layerName

              }

          else{

               exportName = exportDest + "/" + "00" + "__" + layerName      

              }

              doc.exportSWF(exportName , true , true);

          }

          else

          {   

              // padding 0s

              if (numberLayers >9){

                  moreThanTenLayers = true

              var padding = "0"+count

              }else{

              var padding = "00"+count

              }

       

              exportName = exportDest + "/" + padding + "_" + layerName;   

              doc.exportSWF(exportName , true , false);   

              count += 1;   

          }

          }

          l.visible = false;

      }

       

      //resets visibility

      for ( var i=0;i<docTimeline.layerCount;i++ )

      {

          docTimeline.layers[i].visible = true

       

       

      doc.close(SaveOptions = 0)

       

      }

       

      }

        • 2. Re: Toggle options in Publish settings with Javascript Code?
          ExtraMurque Level 1

          Hello and thank you for the link.

           

          This part works indeed, that is if you have created a profile inside Flash already:

           

          var profileXML=fl.getDocumentDOM().exportPublishProfileString('theCreatedNewProfileWithinFlas h');

          fl.trace(profileXML);

          var newProfileXML = profileXML.replace("<ActionScriptVersion>2</ActionScriptVersion>", "<ActionScriptVersion>1</ActionScriptVersion>");

          fl.getDocumentDOM().importPublishProfileString(newProfileXML);

           

           

           

           

          But somehow I seem not able to import the .apr file inside flash before using the above lines of code...

           

           

          var xmlString = "C:\Users\Windows\AppData\Local\Adobe\Animate CC 2017\en_US\Configuration\Publish Profiles\theSavedProfileFile.apr"

           

          document.importPublishProfileString(xmlString)

          Is this the right approach?

           

           

           

           

          Cheers,
          Marc

          • 3. Re: Toggle options in Publish settings with Javascript Code?
            ExtraMurque Level 1

            P.s.

             

            Maybe good to mention is that the .fla files are made by other people on different computers/ profiles.
            This could mean that the reason why I cannot keep my own created profile on my computer when opening the Flash-files from the Animation-Production-server is that the created version is made with different settings...

            • 4. Re: Toggle options in Publish settings with Javascript Code?
              JoãoCésar Adobe Community Professional

              Hi.

               

              What I think you need is a script to export your current publish profile settings and then run a script that imports this newly created profile and then export the layers as SWFs.

               

              I used this technique to export FLAs to SVGs here: Re: Script to automate a repetitive task in Animate? .

               

              1 - Run this script (export_publish_profile.jsfl) to export whatever publish settings you want:

              var publishProfileName = "fl_publish_profile.xml";
              
              function exportPublishProfile()
              {
                  if (fl.getDocumentDOM())   
                      fl.getDocumentDOM().exportPublishProfile(fl.scriptURI.replace(fl.scriptURI.split("/").pop(), publishProfileName));
              }
              
              exportPublishProfile();
              

               

              2 - Run this script (export_layers_as_swf.jsfl) to export the SWFs to the desired location:

              function exportFromLayers()
              {
                  var doc;
                  var folder;
                  var profileIndex;
                  var layers;
                  var layersIndexes;
                  var publishProfileName = "fl_publish_profile.xml";   
                 
                  doc = fl.getDocumentDOM();
                 
                  if (!doc)
                      return;   
                 
                  folder = fl.browseForFolderURL("Choose an output directory.");
                 
                  if (!folder)
                      return;
                 
                  try
                  {
                      profileIndex = doc.importPublishProfile(fl.scriptURI.replace(fl.scriptURI.split("/").pop(), publishProfileName));       
                      doc.currentPublishProfile = fl.getDocumentDOM().publishProfiles[profileIndex];
                      layers = doc.getTimeline().layers;
                      layersIndexes = doc.getTimeline().getSelectedLayers();
                     
                      for (var i = 0, total = layersIndexes.length; i < total; i++)
                          layers[layersIndexes[i]].visible = false;
                     
                      for (i = 0; i < total; i++)
                      {
                          var layer = layers[layersIndexes[i]];
                         
                          layer.visible = true;
                          doc.exportSWF(folder + "/" + zeropad(i, 2) + "_" + layer.name + ".swf", true);
                          layer.visible = false;
                      }
                     
                      doc.deletePublishProfile();
                  }
                  catch(error)
                  {
                      fl.trace("\n----------");
                      fl.trace(error);
                      fl.trace("Error when loading publish profile. It should be in the same folder where this script is located and should be called " + publishProfileName);       
                      fl.trace("----------\n");
                  }   
              }
              
              function zeropad(number, length) {
              
                  var str = '' + number;
                 
                  while (str.length < length)
                      str = '0' + str;
              
                  return str;
              }
              
              exportFromLayers();
              
              

               

              Scripts download:

              export_layers_as_swf.zip - Google Drive

               

              I hope it helps.

               

              Regards,

              JC

              2 people found this helpful
              • 5. Re: Toggle options in Publish settings with Javascript Code?
                ExtraMurque Level 1

                Thank you so much João!

                 

                That did the trick!
                Really appreciated!

                 


                Have a great weekend!
                Marc

                • 6. Re: Toggle options in Publish settings with Javascript Code?
                  ClayUUID Adobe Community Professional

                  ExtraMurque  wrote

                   

                  Hello and thank you for the link.

                   

                  This part works indeed, that is if you have created a profile inside Flash already:

                  No, there is always a Default profile available.

                   

                  This JSFL code will make the publish profile changes you wanted:

                   

                  var dom = fl.getDocumentDOM();
                  
                  // grab current profile
                  var profileXML = dom.exportPublishProfileString(dom.currentPublishProfile);
                  
                  // modify profile
                  // WARNING: This is a hack that does direct string manipulation instead of properly parsing the XML
                  
                  // exclude hidden layers (Flash)
                  profileXML = profileXML.replace(/<InvisibleLayer>.<\/InvisibleLayer>/g, '<InvisibleLayer>0</InvisibleLayer>');
                  
                  // exclude hidden layers (HTML/SVG)
                  profileXML = profileXML.replace(/<Property name="includeHiddenLayers">.+?<\/Property>/g, '<Property name="includeHiddenLayers">false</Property>');
                  
                  // JPEG quality
                  profileXML = profileXML.replace(/<Quality>.+?<\/Quality>/g, '<Quality>100</Quality>');
                  
                  // apply updated profile
                  dom.importPublishProfileString(profileXML);
                  
                  1 person found this helpful
                  • 7. Re: Toggle options in Publish settings with Javascript Code?
                    JoãoCésar Adobe Community Professional

                    This is great, Marc!

                     

                    You're welcome!

                    • 8. Re: Toggle options in Publish settings with Javascript Code?
                      ExtraMurque Level 1

                      Thank you for the information.

                       

                      Marc

                      • 9. Re: Toggle options in Publish settings with Javascript Code?
                        PrashantGupta Level 2

                        @ExtraMurque : You can create your publish profile with required settings and import/export in fla using jsapi:

                        fl.getDocumentDOM().exportPublishProfile(fileURIToAPRfile);

                        fl.getDocumentDOM().importPublishProfile(fileURIToAPRfile);

                         

                        Also, To export each layer as individual swf file, you can use SWF archive option (more details: Specify publish settings for Animate CC )