3 Replies Latest reply: Nov 12, 2014 7:29 AM by Kai Rübsamen RSS

    Save as existing file to add few letters

    Murali_Vetha Community Member

      Hi All,

       

      This below coding is open indesign file and flow word file then save as in the same name. But now I need to add "_Flowed" with the before .indd extension. See 16th line. But if I run this coding result is e.g. Indesign.indd_Flowed. Please advice.

       

      See my coding

       

      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
      var myIndFile = File.openDialog ("Select Indesign File");
      var myWordFile = File.openDialog ("Select Word File");
      
      app.open (myIndFile);
      
      var mydoc = app.activeDocument;
      
      mydoc.textPreferences.smartTextReflow = true;
      mydoc.textPreferences.limitToMasterTextFrames = false;
      mydoc.textPreferences.deleteEmptyPages = false;
      mydoc.textPreferences.addPages = AddPageOptions.endOfStory;
      
      mydoc.pages.item(0).textFrames.item(0).place(File(myWordFile));
      
      app.activeDocument.save(new File(myIndFile + "_Flowed"));
      
      
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;//This coding is not skipping of dialog boxes etc.
      

       

      Regards,

      Vetha

        • 1. Re: Save as existing file to add few letters
          vandy88 Community Member

          Replace the 16th line with the below code:

           

          app.activeDocument.save(new File(myIndFile.path + "/" + myIndFile.name.replace(".indd", "") + "_Flowed.indd")); 

           

          Vandy

          • 2. Re: Save as existing file to add few letters
            Murali_Vetha Community Member

            Superb vandy

            • 3. Re: Re: Save as existing file to add few letters
              Kai Rübsamen MeganK

              Hi Vetha,

               

              I’ve no idea, if this is good practice, but for me this works too:

               

              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
              
              var myDoc = app.open( File.openDialog( "Select InDesign File" ) );
              myDoc.properties = { textPreferences: { smartTextReflow: true, limitToMasterTextFrames: false, deleteEmptyPages: false, addPages: AddPageOptions.endOfStory } };
              
              myDoc.textFrames[0].place(File.openDialog ( "Select Word File" ));
              
              myDoc.save ( new File ( myDoc.fullName.toString().slice(0, -5) + "_Flowed.indd" ));
              
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
              
              
              
              
              

               

              Notice, that you get an error with your and my version, if you click cancel in the dialogs. That should be checked too.

              Notice also, that smart text reflow will not work, if the textfame on page 1 is not a primary textframe or a master text frame (in older version).

               

              If there exists better solutions, it would be great, if the advanced scripters share them with us.

               

              –Kai