2 Replies Latest reply on Feb 22, 2012 9:55 AM by Diego_Pro_Imagem

    Select items, add to library and rename - Javascript/Windows

    Diego_Pro_Imagem Level 1

      Hey all!

       

      I've done some basic scripting but I'm really new at this, just saw some examples and modified them for my workspace, so please forgive me for any "dumb questions"...

       

      What I'm trying to do is something like this:

      I have "X" files opened and in each one of them I want to select all the items inside the page, whats outside the border I don't want to add to the library, after the selection is made I want to group this objects and add them to a library that is opened. This library changes, but I will always have just one library opened. After that, the item on the library has to be renamed to the filename.

       

      That's it, any tips of how should I start?

       

      Thanks guys, and please forgive for any grammatical errors, I'm brazilian.

       

      Cya!

        • 1. Re: Select items, add to library and rename - Javascript/Windows
          absqua Level 4

          There are probably things I'm not thinking of, but this should get you started:

           

          var lib = app.libraries[0],
              i, doc, group;
          
          for (i = 0; i < app.documents.length; i++) {
              doc = app.documents[i];
              group = doc.spreads[0].groups.add(doc.pages[0].pageItems.everyItem().getElements());
              lib.store([group], {name: doc.name});
              doc.undo();
          }
          

           

          This assumes that the page whose items you want to add to your library is the first page of each of your open documents.

           

          Jeff

          1 person found this helpful
          • 2. Re: Select items, add to library and rename - Javascript/Windows
            Diego_Pro_Imagem Level 1

            Here's the result that I built:

             

             

            // VARIÁVEIS
            var d=app.activeDocument;
            if (app.documents.length == 0) { exit(); }
            
            
            // QUESTÃO
            if (confirm("Deseja criar uma nova Library?"))
            
            
            {
            // ADICIONA LIBRARY
            var library = prompt("Insira o NOME da Library onde os arquivos serão salvos.","Ex.: ''zzz-summer12''");
            if (library == null) { exit(); }
            var Pasta = Folder.selectDialog("Selecione a PASTA onde a Library será salva.");
            if (Pasta == null) { exit(); }    
            
            
            var libraryext = (library + ".indl")
            app.libraries.add(Pasta.fsName+"/"+libraryext)
            var libraryfn = app.libraries.item(libraryext);
            
            
            // LOOP SALVAR ARQUIVOS
            while (app.documents.length)  {
                var doc = app.documents[0];
                var Ref = doc.textFrames.itemByName("Modelo").contents;
            
            
                var selecao =  app.documents.item(0).pages.item(0).pageItems;
                app.activeWindow.activePage.groups.add(selecao);
                libraryfn.store(selecao, {name: Ref});
                app.activeDocument.close(SaveOptions.no);
            }
            }
            else
            {
            //PERGUNTA NOME DA LIBRARY ABERTA
            var library = prompt("Insira o NOME da Library que está aberta.","Ex.: ''zzz-summer12''");
            if (library == null) { exit(); }
            var libraryext = (library + ".indl")
            var libraryfn = app.libraries.item(libraryext);
            
            
            // LOOP SALVAR ARQUIVOS
            while (app.documents.length)  {
                var doc = app.documents[0];
                var Ref = doc.textFrames.itemByName("Modelo").contents;
            
            
                var selecao =  app.documents.item(0).pages.item(0).pageItems;
                app.activeWindow.activePage.groups.add(selecao);
                libraryfn.store(selecao, {name: Ref});
                app.activeDocument.close(SaveOptions.no);
            }
            }