• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help to stop this script from Creating New Text frame every time File is opened.

Advocate ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

Hi everyone.  How can i keep this Script from writing overtop of the Our Barcode Text frame i have being created?  What it does is the first time i open the Documnet It places OUR Barcode text frame where it needs to be.  Then I save the file close it.  WHen i reopen the FIle (Any FIle) It places another Text Frame over top of it.  I'm trying to get it to Make the Text frame and if it sees that its already made it will not create a new Frame.

   #targetengine "Indesign CC2017"

  

app.addEventListener( "afterOpen" , dotFOnPageOne ); 

app.addEventListener( "afterOpen", doMLyer );  

app.addEventListener( "beforeSave", doLLayer ); 

app.addEventListener( "beforeOpen", doULLayer );

function doULLayer(){

app.activeDocument.layers.item("OUR Barcode").locked = false;

       }

      

function doLLayer(){

app.activeDocument.layers.item("OUR Barcode").locked = true;

       }

      

    function doMLyer(){

        layers = app.documents[0].layers; 

    if (layers.item('OUR Barcode').isValid) { 

      layers.item('OUR Barcode').move (LocationOptions.AT_BEGINNING);

    }

}

 

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CREATE NEW layer<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\ 

    function doLyer(){

        var _d = app.documents[0]; 

        var _allStories = _d.stories; 

        for(var n=_allStories.length-1;n>=0;n--){ 

        var _storyAllTextFrames = _allStories.textContainers; 

            for(var m=_storyAllTextFrames.length-1;m>=0;m--){

                //If the contents of a text frame is an empty string: 

if(_storyAllTextFrames.contents === ""){ 

_storyAllTextFrames.select(); 

//Convert frame to "Unassigned": 

          /*      try{

app.scriptMenuActions.itemByID(11297).invoke(); 

}catch(e){};  */

}; 

}; 

            }; 

         

        //Trick to deselect the last selection 

        //Add a new textFrame, select and remove it: 

        var _tempTextFrame = _d.textFrames.add(); 

_tempTextFrame.select(); 

_tempTextFrame.remove(); 

       }

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>NEW layer Color Settings<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\ 

    function addlayer(doc, name){ 

        try{ 

            var layer = doc.layers.itemByName(name); 

            if(layer && layer.isValid) { 

return layer; 

                } else { 

            var mylayer = doc.layers.add(); 

mylayer.name = name;

mylayer.layerColor = [100,50,100]

                return mylayer; 

        } 

      } catch(e) { 

     } 

    } 

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CREATE TEXT FRAME<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\

     function addTextF(doc, layer, name){ 

// ************ how can I get the below to only allow me to select the **OUR Barcode** when its locked? ************* \\  

app.generalPreferences.preventSelectingLockedItems = false;

            

        var myBlendingSettings = { blendMode : BlendMode.NORMAL };       

        var myTransparencySettings = { blendingSettings : myBlendingSettings };  

        var tFR = doc.textFrames.itemByName(name);

       

        if(tFR && tFR.isValid) {       

tFR.remove(); 

        } 

        var origUnit = app.scriptPreferences.measurementUnit; 

        app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;

    tFR = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Paper", fillTint: 100, transparencySettings : myTransparencySettings, geometricBounds: ['.504in','.21in','.376in','-.21in'] });

    tFR.rotationAngle += -90;

// ************ Cant get the below to Fill my pictures Proportionally. ************* \\  

/*  

tFR.fit(FitOptions.FILL_PROPORTIONALLY);

    tFR.resize( 

CoordinateSpaces.innerCoordinates,

AnchorPoint.topLeftAnchor, 

ResizeMethods.MULTIPLYING_CURRENT_DIMENSIONS_BY, 

        [.40,.40] 

        ); 

     

tFR.fit(FitOptions.CENTER_CONTENT);

*/   

tFR.locked=true;

app.scriptPreferences.measurementUnit = origUnit;     

              return tFR; 

             

    } 

        // VERTICAL  geometricBounds: ['.65in','.062in','.23in','-.066'] });

        /* HORIZONTAL  geometricBounds: ['.333','.124','.46','-.296'] }); */

//geometricBounds: ['.333in','.21in','.20501in','-.296in'] });

        // geometricBounds: ['.504in','.21in','.376in','-.21in'] });

     

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MOVE TEXT FRAME TO layer<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\\

    function dotFOnPageOne(event){      

        var doc = event.target;    

        if(!(doc && doc.constructor.name == "Document")) { 

return; 

        } 

           

        var mylyer = addlayer(doc, "OUR Barcode"); 

        var tFR = addTextF(doc, mylyer, "OUR Barcode");

TOPICS
Scripting

Views

371

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Apr 11, 2017 Apr 11, 2017

I got this to work.  I just added an event listener to lock the Textbox before the document closes. 

Votes

Translate

Translate
Community Expert ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

Is this the exact same question as in your yesterday's Help with my Text frame Script ?

If so, please delete this one or the older one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 09, 2017 Mar 09, 2017

Copy link to clipboard

Copied

No its Same Script different problem.  I just noticed today it was adding that frame to every time i reopen a file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Can you delete your comment so i can delete this post?  I'm going simplify my question.  Or if you can delete this post that will work too.  Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

Sorry, I can't anymore ("No actions are available"). Ping a moderator with a personal message, that should do it.

And thanks for simplifying the problem! That should make it easier to answer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 13, 2017 Mar 13, 2017

Copy link to clipboard

Copied

ok thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 11, 2017 Apr 11, 2017

Copy link to clipboard

Copied

LATEST

I got this to work.  I just added an event listener to lock the Textbox before the document closes. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines