4 Replies Latest reply on Jul 12, 2013 6:21 AM by Maelvon 75

    [Jsfl] Document settings matches default, content, printer, how to ?

    Maelvon 75

      Hi,

       

      In a Flash Jsfl script, I want to acceed to to the "Document settings" panel (CTRL+J) and select the "content" checkbox for "matches" which propose: "default", "content", "printer". I've copy/paste in a new scene some items who are bigger than the default document size. And checking this boxe solve my problem, but I don't find any way to do that with Jsfl.

       

      In other word, I want to make my document settings to matches the scene content boundaries. I cannot find another way to do that in Jsfl!

       

      Thanks for your help, tips, ideas.

       

      Maelvon

        • 1. Re: [Jsfl] Document settings matches default, content, printer, how to ?
          kglad Adobe Community Professional & MVP

          this should work:

           

          var doc = fl.getDocumentDOM();

          doc.selectAll();

          var rect = doc.getSelectionRect();

           

          //now loop through all the timelines, all the layers, all the frames and move all the instances by -rect.left,-rect.top

          //final assign document.width (using rect's left and right)  and document.height (using rect's top and bottom)

          • 2. Re: [Jsfl] Document settings matches default, content, printer, how to ?
            Maelvon 75 Level 1

            Thanks Kglad,

             

            I've found an other way, based on a code find here :

             

            Added a test to avoid "folder" layer and move elements only when the frame is a startFrame.

            document_to_Content_Size = function() {
                var doc = fl.getDocumentDOM();
                var element;
                var docw = 1;
                var doch = 1;
                var tframes;
                var layer;
                var frame;
                var ox;
                var oy;
                var left = null;
                var right = null;
                var top = null;
                var bottom = null;
                var cf = doc.getTimeline().currentFrame;
                 
                 for (var ln = 0; ln < doc.getTimeline().layerCount; ln++) {
                      
                      layer = doc.getTimeline().layers[ln];
                      
                      if (layer.layerType == "folder") continue;
                      tframes =layer.frameCount;
                      
                      for (var fn = 0; fn < tframes; fn++) {
                           doc.getTimeline().currentFrame = fn;
                           frame = layer.frames[fn];
                           var en = 0;
            
                           for (var en = 0;  en < frame.elements.length; en ++) {
                                if (fn == frame.startFrame) {
                                     element = frame.elements[en];
                                     
                                     ox = element.left;
                                     oy = element.top;
                                     if (left == null){
                                          left = ox;
                                     }
                                     if (right == null){
                                          right = ox + element.width;
                                     }
                                     if (top == null){
                                          top = oy;
                                     }
                                     if (bottom == null){
                                          bottom = oy + element.height;
                                     }
                                     left = Math.min(ox, left);
                                     right = Math.max(ox + element.width, right);
                                     top = Math.min(oy, top);
                                     bottom = Math.max(oy + element.height, bottom);
                                }
                           }
                      }
                 }
                fl.trace("CURRENT SIZE-->\t" + doc.width + " x " + doc.height);
                docw = Math.round(right - left);
                doch = Math.round(bottom - top);
                moveAllElementsBy(-left, -top);
                doc.width=docw;
                doc.height=doch;
                 fl.trace("NEW SIZE-->\t\t\t" + doc.width+" x " + doc.height);
                doc.getTimeline().currentFrame=cf;
            }
            
            moveAllElementsBy = function(tx,ty) {
                doc=fl.getDocumentDOM();
                var element;
                var tframes;
                var layer;
                var frame;
                 for(var ln = 0; ln < doc.getTimeline().layerCount; ln++) {
                    layer = doc.getTimeline().layers[ln];
                      
                      if (layer.layerType == "folder") continue;
                      
                    tframes = layer.frameCount;
            
                    for(var fn = 0; fn < tframes; fn++) {
                        doc.getTimeline().currentFrame = fn;
                        frame = layer.frames[fn];
            
                        for (var fe = 0; fe < frame.elements.length; fe++) {
                            element = frame.elements[fe];
                                if (fn == frame.startFrame) {
                                     element.x += tx;
                                     element.y += ty;
                                     if (element.elementType.search(/instance|text/mig) == -1){
                                          element.x = element.width/2;
                                          element.y = element.height/2;
                                     }
                                }
                        }
                    }
                }
            }
            • 3. Re: [Jsfl] Document settings matches default, content, printer, how to ?
              kglad Adobe Community Professional & MVP

              you should use the code i suggested instead of the first nested loop and the 2nd loop is what i suggested (but will fail if you have any nested movieclips so, in general, you should use my suggestion for that too).

              • 4. Re: [Jsfl] Document settings matches default, content, printer, how to ?
                Maelvon 75 Level 1

                You suggest that I should do a doc.selectAll() instead of the doc.getTimeline() to parse the content of my Scene?

                In this case, I should unlock some layers if they are and need to move them, I think.