Highlighted

How can i merge these scripts?

Advocate ,
Aug 05, 2020

Copy link to clipboard

Copied

How can i merge these scripts? what i'm trying to do is make a layer named (dieline) and a Text frame named (Dieline) i want the text frame to be but in the Dieline layer. i can do each one separate minus the moving from one layer to another. but I would like it if i could have it all in one script.

function addDLf(doc, layer, name){      
            var mynBlendingSettings = { blendMode : BlendMode.OVERLAY };            
            var mynTransparencySettings = { blendingSettings : mynBlendingSettings };   
            var tfn = doc.textFrames.itemByName(name);      
            if(tfn && tfn.isValid) {            
                tfn.exit ();      
        }      
            var orignUnit = app.scriptPreferences.measurementUnit;           
            app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;    
            tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Dieline", fillTint: 40, transparencySettings : mynTransparencySettings});  
            tfn.geometricBounds = [doc.pages[0].bounds[2] + 0,0, doc.pages[0].bounds[2] + 0,0]  
            app.scriptPreferences.measurementUnit = orignUnit;          
            return tfn;  
            
        }   
    function doDLm(event){       
            
            var doc = event.target;     
            if(!(doc && doc.constructor.name == "Document")) {  
                return;  
        }  
            
            var myLayern = addLayer(doc, "Dieline");  
            var tfn = addTextFramen(doc, myLayern, "Dieline"); 
        } 

 

var doc = app.documents[0];
var page = doc.pages[0];

page.textFrames.add 
(
	{
		
        geometricBounds : page.bounds ,


		fillColor : "None" ,
		strokeColor : "Diecut" , 
		strokeWeight : "1pt" ,
		strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
        overprintStroke : true,
        
        	
		topLeftCornerRadius : "3.175mm", 
        topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
        bottomLeftCornerRadius : "3.175mm", 
        bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
        topRightCornerRadius : "3.175mm", 
        topRightCornerOption : CornerOptions.ROUNDED_CORNER,
        bottomRightCornerRadius : "3.175mm", 
        bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
		
  

        
	}
 );   
Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

There is some conflicting properties in the two scripts. Using the props of the first script, a simple illustration of the task you asked is: 

 

 

 

 

 

var doc = app.documents[0];
var dieStr = "Dieline";
var mynBlendingSettings = { blendMode : BlendMode.OVERLAY };            
var mynTransparencySettings = { blendingSettings : mynBlendingSettings }
var dieLayer = doc.layers.add();
dieLayer.name = dieStr;
tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {
    name: "dieline", 
    fillTint: 40, 
    transparencySettings: mynTransparencySettings, 
    fillColor : "None" ,
    strokeColor : "Diecut" , 
    strokeWeight : "1pt" ,
    strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
    overprintStroke : true,
    topLeftCornerRadius : "3.175mm", 
    topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
    bottomLeftCornerRadius : "3.175mm", 
    bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
    topRightCornerRadius : "3.175mm", 
    topRightCornerOption : CornerOptions.ROUNDED_CORNER,
    bottomRightCornerRadius : "3.175mm", 
    bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
    geometricBounds : doc.pages[0].bounds
});  

 

 

 

 

 

Not sure if you need the event handler too, in the first script. 

Topics

Scripting

Views

114

Likes

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

How can i merge these scripts?

Advocate ,
Aug 05, 2020

Copy link to clipboard

Copied

How can i merge these scripts? what i'm trying to do is make a layer named (dieline) and a Text frame named (Dieline) i want the text frame to be but in the Dieline layer. i can do each one separate minus the moving from one layer to another. but I would like it if i could have it all in one script.

function addDLf(doc, layer, name){      
            var mynBlendingSettings = { blendMode : BlendMode.OVERLAY };            
            var mynTransparencySettings = { blendingSettings : mynBlendingSettings };   
            var tfn = doc.textFrames.itemByName(name);      
            if(tfn && tfn.isValid) {            
                tfn.exit ();      
        }      
            var orignUnit = app.scriptPreferences.measurementUnit;           
            app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;    
            tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Dieline", fillTint: 40, transparencySettings : mynTransparencySettings});  
            tfn.geometricBounds = [doc.pages[0].bounds[2] + 0,0, doc.pages[0].bounds[2] + 0,0]  
            app.scriptPreferences.measurementUnit = orignUnit;          
            return tfn;  
            
        }   
    function doDLm(event){       
            
            var doc = event.target;     
            if(!(doc && doc.constructor.name == "Document")) {  
                return;  
        }  
            
            var myLayern = addLayer(doc, "Dieline");  
            var tfn = addTextFramen(doc, myLayern, "Dieline"); 
        } 

 

var doc = app.documents[0];
var page = doc.pages[0];

page.textFrames.add 
(
	{
		
        geometricBounds : page.bounds ,


		fillColor : "None" ,
		strokeColor : "Diecut" , 
		strokeWeight : "1pt" ,
		strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
        overprintStroke : true,
        
        	
		topLeftCornerRadius : "3.175mm", 
        topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
        bottomLeftCornerRadius : "3.175mm", 
        bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
        topRightCornerRadius : "3.175mm", 
        topRightCornerOption : CornerOptions.ROUNDED_CORNER,
        bottomRightCornerRadius : "3.175mm", 
        bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
		
  

        
	}
 );   
Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

There is some conflicting properties in the two scripts. Using the props of the first script, a simple illustration of the task you asked is: 

 

 

 

 

 

var doc = app.documents[0];
var dieStr = "Dieline";
var mynBlendingSettings = { blendMode : BlendMode.OVERLAY };            
var mynTransparencySettings = { blendingSettings : mynBlendingSettings }
var dieLayer = doc.layers.add();
dieLayer.name = dieStr;
tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {
    name: "dieline", 
    fillTint: 40, 
    transparencySettings: mynTransparencySettings, 
    fillColor : "None" ,
    strokeColor : "Diecut" , 
    strokeWeight : "1pt" ,
    strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
    overprintStroke : true,
    topLeftCornerRadius : "3.175mm", 
    topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
    bottomLeftCornerRadius : "3.175mm", 
    bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
    topRightCornerRadius : "3.175mm", 
    topRightCornerOption : CornerOptions.ROUNDED_CORNER,
    bottomRightCornerRadius : "3.175mm", 
    bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
    geometricBounds : doc.pages[0].bounds
});  

 

 

 

 

 

Not sure if you need the event handler too, in the first script. 

Topics

Scripting

Views

115

Likes

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
Advocate ,
Aug 05, 2020

Copy link to clipboard

Copied

if theres a better way to do it than those 2 scripts i'm up for that as well. thanks in advance.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

There is some conflicting properties in the two scripts. Using the props of the first script, a simple illustration of the task you asked is: 

 

 

 

 

 

var doc = app.documents[0];
var dieStr = "Dieline";
var mynBlendingSettings = { blendMode : BlendMode.OVERLAY };            
var mynTransparencySettings = { blendingSettings : mynBlendingSettings }
var dieLayer = doc.layers.add();
dieLayer.name = dieStr;
tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {
    name: "dieline", 
    fillTint: 40, 
    transparencySettings: mynTransparencySettings, 
    fillColor : "None" ,
    strokeColor : "Diecut" , 
    strokeWeight : "1pt" ,
    strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
    overprintStroke : true,
    topLeftCornerRadius : "3.175mm", 
    topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
    bottomLeftCornerRadius : "3.175mm", 
    bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
    topRightCornerRadius : "3.175mm", 
    topRightCornerOption : CornerOptions.ROUNDED_CORNER,
    bottomRightCornerRadius : "3.175mm", 
    bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
    geometricBounds : doc.pages[0].bounds
});  

 

 

 

 

 

Not sure if you need the event handler too, in the first script. 

Likes

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
Reply
Loading...
Advocate ,
Aug 05, 2020

Copy link to clipboard

Copied

Thank you much i'll give it a try.

Likes

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
Reply
Loading...
Advocate ,
Aug 05, 2020

Copy link to clipboard

Copied

i can get it to add the Layer but it will not add the text frame with the Radius on it. and on a side not it keeps adding layers. Here's what i have and maybe the scripts i'm using arent the correct ones to do it with. I have a Script UI script and on that i have a Checkbox that exicutes this script. What i'm trying to do is When i click the ok button (It creates the layer (Dieline) if its not already there, Then Creates and adds the text frame (dieline) to that layer if its not already there. to answer above also i did have eventlisteners added to the origional script.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 05, 2020

Copy link to clipboard

Copied

I updated my original post to add the corner radius options. Can you post your full script so we can troubleshoot further for the other issues? 

Likes

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
Reply
Loading...
Advocate ,
Aug 06, 2020

Copy link to clipboard

Copied

Thanks for your reply it turned out that i had a very simple / stupid mistake. i forgot to type my closing bracket. The current code is as follows. I do have one issue. It keeps creating layers every time i hit save. Probably due to the eventlistener do you see how to stop this?

 

  //  #targetengine "session" 
  
    app.addEventListener( "beforeSave" , DlL );  
      
    function doLayer(){
    var _d = app.documents[0];  
    var _allStories = _d.stories;  
    for(var n=_allStories.length-1;n>=0;n--){  
    var _storyAllTextFrames = _allStories[n].textContainers;  
        for(var m=_storyAllTextFrames.length-1;m>=0;m--){  
            if(_storyAllTextFrames[m].contents === ""){  
                _storyAllTextFrames[m].select();  

                };  
            };  
        };  

    var _tempTextFrame = _d.textFrames.add();  
    _tempTextFrame.select();  
    _tempTextFrame.remove();  
       }

    function addLayer(doc, name){  
    try{  
            var layer = doc.layers.itemByName(name);  
            if(layer && layer.isValid) {  
                     return layer;  
                } else {  
            var dieStr = doc.layers.add();  
             dieStr.name = name; 
             dieStr.layerColor = [100,30,30]
                return dieStr;  
        }  
      } catch(e) {  
     }  
    }  

    function DlL(doc, layer, name){      
    var doc = app.documents[0];
    var dieStr = "Dieline";
    var mynBlendingSettings = { blendMode : BlendMode.NORMAL };            
    var mynTransparencySettings = { blendingSettings : mynBlendingSettings }
    var dieLayer = doc.layers.add();
        dieLayer.name = dieStr;
        tfn = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {
            name: "Dieline", 
            fillTint: 100, 
            transparencySettings: mynTransparencySettings, 
            fillColor : "None" ,
            strokeColor : "Diecut" , 
            strokeWeight : "1pt" ,
            strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
            overprintStroke : true,
            topLeftCornerRadius : "3.175mm", 
            topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
            bottomLeftCornerRadius : "3.175mm", 
            bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
            topRightCornerRadius : "3.175mm", 
            topRightCornerOption : CornerOptions.ROUNDED_CORNER,
            bottomRightCornerRadius : "3.175mm", 
            bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
            geometricBounds : doc.pages[0].bounds
      });
            
    }   

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 06, 2020

Copy link to clipboard

Copied

In the Dll function, change: 

var dieLayer = doc.layers.add();
        dieLayer.name = dieStr;

To:

var dieLayer = doLayer(doc, dieStr);

 

Also, in the next line where you are setting the tfn variable, I think you want to change "layer" in your argument to "dieLayer"

Likes

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
Reply
Loading...
Advocate ,
Aug 06, 2020

Copy link to clipboard

Copied

I'm going to try this. However i'm also going to mark the first reply as correct since that was my origional Question. I'll get back to you once i've tried the other edit.  Thanks for your help on this!

Likes

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
Reply
Loading...
Advocate ,
Aug 06, 2020

Copy link to clipboard

Copied

Ok this one just keeps placing text frame (dieline) over and over after saving every time. I have a work around for it might not work for ever but for now might work. I did a few things. 1 changed doLayer(doc, dieStr); to addLayer(doc, dieStr); I also did what you recommended and put "dieLayer" in place of "layer"(now it creates the layer). then the second thing is i lock the layer right away so that it wont keep creating extra layers or text frames.

//  #targetengine "session" 
  
    app.addEventListener( "beforeSave" , DlL );  
    app.addEventListener( "beforeSave" , doLl );  
  
    function doLayer(){
    var _d = app.documents[0];  
    var _allStories = _d.stories;  
    for(var n=_allStories.length-1;n>=0;n--){  
    var _storyAllTextFrames = _allStories[n].textContainers;  
        for(var m=_storyAllTextFrames.length-1;m>=0;m--){  
            if(_storyAllTextFrames[m].contents === ""){  
                _storyAllTextFrames[m].select();  

                };  
            };  
        };  

    var _tempTextFrame = _d.textFrames.add();  
    _tempTextFrame.select();  
    _tempTextFrame.remove();  
       }

    function addLayer(doc, name){  
    try{  
            var layer = doc.layers.itemByName(name);  
            if(layer && layer.isValid) {  
                     return layer;  
                } else {  
            var dieStr = doc.layers.add();  
             dieStr.name = name; 
             dieStr.layerColor = [100,30,30]
                return dieStr;  
        }  
      } catch(e) {  
     }  
    }  

    function DlL(doc, layer, name){      
    var doc = app.documents[0];
    var dieStr = "Dieline";
    var mynBlendingSettings = { blendMode : BlendMode.NORMAL };            
    var mynTransparencySettings = { blendingSettings : mynBlendingSettings }
    var dieLayer = addLayer(doc, dieStr);        
        // dieLayer.name = dieStr;        
        tfn = doc.textFrames.add(dieLayer, LocationOptions.UNKNOWN, {
            name: "Dieline", 
            fillTint: 100, 
            transparencySettings: mynTransparencySettings, 
            fillColor : "None" ,
            strokeColor : "Diecut" , 
            strokeWeight : "1pt" ,
            strokeAlignment : StrokeAlignment.CENTER_ALIGNMENT , 
            overprintStroke : true,
            topLeftCornerRadius : "3.175mm", 
            topLeftCornerOption : CornerOptions.ROUNDED_CORNER, 
            bottomLeftCornerRadius : "3.175mm", 
            bottomLeftCornerOption : CornerOptions.ROUNDED_CORNER,
            topRightCornerRadius : "3.175mm", 
            topRightCornerOption : CornerOptions.ROUNDED_CORNER,
            bottomRightCornerRadius : "3.175mm", 
            bottomRightCornerOption : CornerOptions.ROUNDED_CORNER,
            geometricBounds : doc.pages[0].bounds
      });
            
    }
    
function doLl(){
        app.activeDocument.layers.item("Dieline").locked = true;

       }

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 07, 2020

Copy link to clipboard

Copied

You can check if a textframe named dieline exists on the layer and create the frame if not: 

if (doc.textFrames.itemByName("Dieline").isValid) { return; }

Add this line right after you call you addLayer function.  

Likes

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
Reply
Loading...