2 Replies Latest reply on Jun 19, 2017 12:23 PM by Cleber Sant'aa

    Is there a way to store page elements for later use by script?

    Cleber Sant'aa

      I need to do a book catalog redesign, all the entries from the previous editions will be in the new edition.
      I've designed a new layout, and now I have to copy a lot of text from the previous edition to the new structure, as in the image below


      Screen Shot 2017-06-19 at 12.24.43 PM.png

      I have already made a script to find text by paragraph style, create text frames for the new layout and move the found text to its place on the new frames. It already helps a lot, but I wanted to go one step further and add other elements to the output of my script. These elements, however, are not simple text frames. They include text frames and vector shapes. Something I don't know how to include in the page by script. (The elements I'm talking about are the orange ones in the image)


      So, my question is: Is there a way to store indesign elements somewhere I can retrieve them from, edit them and place them in the page programatically?



      Here's my script. (Note how i have hardcoded the frames ObjectStyles and GeometricBounds)


      function rediagramar() {
      function separarSelecao(selecao){
        for (var i = selecao.length - 1; i >= 0; i--){
          // para cada item da seleção
          if (selecao[i].constructor.name == "TextFrame"){
            // se o item da seleção for uma caixa de texto
            var paragraphs = selecao[i].parentStory.paragraphs;
            for (var j = paragraphs.count() - 1; j >= 0; j--){  
              // para cada parágrafo da caixa de texto
              paragraph = paragraphs.item(j);
              if (paragraph.appliedParagraphStyle.name == "APIS-readers-livros-titulo") {
                //conteudo.titulo = paragraph;
                paragraph.duplicate(LocationOptions.after, frame_a.insertionPoints[0] );
              if (paragraph.appliedParagraphStyle.name == "APIS-readers-livros-autor") {
                //conteudo.autor = paragraph;
                a = paragraph.duplicate(LocationOptions.after, frame_a.insertionPoints[0] );
                //Dirty fix: Limpar a quebra de parágrafo depois do autor para que o frame dê o fit corretamente
                app.findGrepPreferences.findWhat = "\r$";
                app.changeGrepPreferences.changeTo = "";
              if (paragraph.appliedParagraphStyle.name == "APIS-readers-livros-pagina-genero") {
                //conteudo.genero = paragraph;
                paragraph.duplicate(LocationOptions.after, frame_d.insertionPoints[0] );
              if (paragraph.appliedParagraphStyle.name == "APIS-readers-livros-texto") {
                paragraph.duplicate(LocationOptions.after, frame_c.insertionPoints[0] );
      function criarTextFrame (a, b, c, d, style) {
        var newTextFrame = page.textFrames.add();  
        if(!doc.objectStyles.item(style).isValid) {doc.objectStyles.add({name:style});}
        newTextFrame.properties = {
          geometricBounds: [a,b,c,d],
          appliedObjectStyle: doc.objectStyles.item(style)
        return newTextFrame
      frame_a = criarTextFrame(4.8, 7.0, 21.1,76.8, "APIS-readers-titulo");
      frame_b = criarTextFrame(21.1, 0, 63.4, 28.0, "APIS-readers-capa");
      frame_c = criarTextFrame(21.1, 28.0, 74.1, 76.8, "APIS-readers-sinopse");
      frame_d = criarTextFrame(63.4,7.0,74.1, 28.0, "APIS-readers-genero");
      app.activeWindow.activePage.groups.add([frame_a,frame_b,frame_c, frame_d]);