6 Replies Latest reply on Apr 22, 2014 7:26 AM by natrev

    Its possible to change text frame contents inside group...???

    natrev Level 3

      Hi Everyone,

       

      I'm newbibe to Indesign forums.

       

      I had grouped image placed on rectangle and text frame. now i need change text frame content using indesign Javascript

       

      Its possible to change text frame contents inside group..?

       

       

      -yajiv

        • 1. Re: Its possible to change text frame contents inside group...???
          BEGINNER_X Level 3

          Hi natrev,

           

          Welcome to Indesign Scripting Forum....

           

          May the below code will helpful for you...

           

          var pg = app.activeDocument.pageItems.everyItem().getElements()
          alert(pg.length)
          
          for(i=0; i<pg.length; i++)
          {
             if(pg[i].constructor.name == "Group")
              {
                  app.select(pg[i].textFrames[0])
                  alert("textFrame selected")
                 app.selection[0].insertionPoints[0].contents = "Text Inserted";     
                      }
              }
          
          //~ if(app.selection[0].constructor.name == "Group")
          //~ {
              //~     app.select(app.selection[0].textFrames[0])
          //~     }
          

           

          Thanks

          Siraj

          1 person found this helpful
          • 2. Re: Its possible to change text frame contents inside group...???
            natrev Level 3

            Hi Siraj,

             

            Thank you very much for your assistance.This script moved me as next step to scripting.

             

            I need one more help. It is possible to get all elements in Group?

             

            Thanks in advance.

             

             

            -yajiv

            • 3. Re: Its possible to change text frame contents inside group...???
              BEGINNER_X Level 3

              Hi Yajiv,

               

              May the below code should be helpful for you:

               

              Option 1:
              
              var pg = app.activeDocument.pageItems.everyItem().getElements()
              alert(pg.length)
              
              for(i=0; i<pg.length; i++)
              {
                 if(pg[i].constructor.name == "Group")
                  {
                     var mySelect = app.select(pg[i].rectangles[0])
                     alert("Graphics frame selected")
                     
                      var mySelect = app.select(pg[i].textFrames[0])
                      alert("TextFrame Selected")
                      
                      app.selection[0].insertionPoints[0].contents = "Text Inserted";
                      
                          }
                  }
              
              Option 2:
              
              var pg = app.activeDocument.pageItems.everyItem().getElements()
              alert(pg.length)
              
              for(i=0; i<pg.length; i++)
              {
                 if(pg[i].constructor.name == "Group")
                  {
                          var mySelect = app.select(pg[i])
                          var mySelection = app.selection[0].pageItems.everyItem().getElements();
                          alert("selected page items length:  " + mySelection.length);
                          }
                  }
              

               

              Thanks

              Siraj

              1 person found this helpful
              • 4. Re: Its possible to change text frame contents inside group...???
                natrev Level 3

                Hi Siraj,

                 

                Thank you very much for your assistance...

                 

                Actually I need swap both group of image and text frame to another group of image box and text frame.

                 

                I wrote code use of you advice and i struct with errors. can you rectify this code if possible...

                 

                Thanks in advance

                 

                -yajiv..

                 

                 

                Code:

                 

                  if (app.documents.length != 0){
                     if (app.selection.length != 1){
                          if(app.selection[0].constructor.name == "Group"){
                               app.select(app.selection[0].allGraphics[0]);
                               var myGr1 = app.selection[0].itemLink;
                               app.select(app.selection[0].textFrames[0]);
                               var selText1 =app.selection[0].contents; 
                           }                  
                     if(app.selection[1].constructor.name == "Group"){
                          app.select(app.selection[1].allGraphics[0]);
                          var myLink2 = File(app.selection[1].graphics[0].itemLink.filePath);
                          app.select(app.selection[1].textFrames[0]);
                          var selText2 =app.selection[0].contents; 
                          }
                          myGr1.relink (myLink2);
                          myGr1.update();
                          myGr2.relink (myLink1);
                          myGr2.update();
                          app.selection[0].contents=selText2;
                          app.selection[1].contents=selText1;
                          }
                     else{alert("Please select the two selection....!!!");}
                }


                    

                • 5. Re: Its possible to change text frame contents inside group...???
                  Kai Rübsamen Adobe Community Professional

                  Hi,

                   

                  try the following lines.

                   

                   

                  main();
                  
                  function main() {
                  
                      if  (app.documents.length != 0  &&  app.selection.length == 2 ) {
                          if( app.selection[0].constructor.name == "Group" && app.selection[1].constructor.name == "Group" ) {
                              var sel1 = app.selection[0];
                              var graphics1 = sel1.allGraphics[0].itemLink;
                              var text1 = sel1.textFrames[0].contents;
                                  
                              var sel2 = app.selection[1];
                              var graphics2 = sel2.allGraphics[0].itemLink;
                              var text2 = sel2.textFrames[0].contents;
                                  
                              sel1.textFrames[0].contents = text2;
                              sel2.textFrames[0].contents = text1;
                              
                              var fP1 = File( graphics1.filePath );
                              var fP2 = File( graphics2.filePath );
                          
                              graphics1.relink( fP2 ); 
                              graphics2.relink( fP1 );
                          } // if
                          else {
                              alert ( "Select 2 groups!" );
                          } // else
                      } // if
                      else {
                          alert ( "Wrong selection!" );
                      } // else
                  } // main
                  

                   

                  Allthough this maybe will work for you, it is surely not good practice, because, if you apply another contents to the frame, you change the contents, but not the formatting. Same with relinking of the images.

                   

                  So a better solution might be, to ungroup the frames, move them and group them back.

                  • 6. Re: Its possible to change text frame contents inside group...???
                    natrev Level 3

                    Fabulous, Kai!

                     

                    You make it look so easy. Much appreciated!

                     

                    Actually I worked in Photoshop platform. just few months before I moved to Indesign platform.

                     

                    That's the reason I struggled with these coding like these....

                     

                    once again much appreciated.

                     

                    -yajiv...