Highlighted

Linked file name as text layer, or text layer with layer measurements

Explorer ,
Sep 09, 2020

Copy link to clipboard

Copied

I use a lot of scripts in Photoshop and I know that Illustrator is a very different software, so it isn't the end of the world if this isn't possible but I'd like to try 🙂

 

In Photoshop I have a script that takes the layer name and updates an existing text layer with some of that name, so 'FILENAME:12345' is the layer name and the text layer is just updated to show '12345'.

 

if (app.documents.length > 0) mainScript();      
      
function mainScript() {    
    try{    
        var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.artLayers.getByName("SIZEMEASUREMENTS");    
        myLayerText.kind = LayerKind.TEXT;    
        myLayerText.textItem.contents = myLayerName.match(/.{2}$/);
        myLayerText.textItem.contents = myLayerName.slice(-16,-9)+("mm(WxH)");
  
    }catch (errStr){    
        alert(errStr);    
    }    
}

 

 

Another script I use is where the script reads the layer size and updates another existing text layer with that information, this one in inches.

 

function run(){
    var layer = activeDocument.activeLayer;
 
app.preferences.rulerUnits = Units.INCHES;

    var length = Math.round((layer.bounds[2]-layer.bounds[0])*100)/100; 
    var width = Math.round((layer.bounds[3]-layer.bounds[1])*100)/100;

     var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.artLayers.getByName("SIZEMEASUREMENTS2");    
        myLayerText.kind = LayerKind.TEXT;    
        myLayerText.textItem.contents = length + "x" + width + "IN(WxH)"; 
}
run()

app.preferences.rulerUnits = Units.MM;

 

 

Is is possible to get Illustrator to do this? I use the first one because I have another script that resizes files and inputs the measurement in the file name, but even if Illustrator just had to use the second one that would also be fine, since I know layers work differently in Illustrator than in Photoshop. I want to use it in a template so existing text layers would always be there when the template is opened.

 

Many thanks in advance 🙂

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

PS and Illustrator have different sintax. The snippet below works in illustrator, I made minimal changes needed only. Hope that's what you need...

 

1st Script, activate Filename layer

Before

textContents.JPG

 

After 

textContents2.JPG

 

if (app.documents.length > 0) mainScript();      
      
function mainScript() {    
    try{    
        var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.layers.getByName("SIZEMEASUREMENTS");    
        myLayerText.textFrames[0].contents = myLayerName;
        
        //myLayerText.textItem.contents = myLayerName.match(/.{2}$/);
        //myLayerText.textItem.contents = myLayerName.slice(-16,-9)+("mm(WxH)");
  
    }catch (errStr){    
        alert(errStr);    
    }    
}

 

Carlos

TOPICS
Scripting

Views

35

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

Linked file name as text layer, or text layer with layer measurements

Explorer ,
Sep 09, 2020

Copy link to clipboard

Copied

I use a lot of scripts in Photoshop and I know that Illustrator is a very different software, so it isn't the end of the world if this isn't possible but I'd like to try 🙂

 

In Photoshop I have a script that takes the layer name and updates an existing text layer with some of that name, so 'FILENAME:12345' is the layer name and the text layer is just updated to show '12345'.

 

if (app.documents.length > 0) mainScript();      
      
function mainScript() {    
    try{    
        var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.artLayers.getByName("SIZEMEASUREMENTS");    
        myLayerText.kind = LayerKind.TEXT;    
        myLayerText.textItem.contents = myLayerName.match(/.{2}$/);
        myLayerText.textItem.contents = myLayerName.slice(-16,-9)+("mm(WxH)");
  
    }catch (errStr){    
        alert(errStr);    
    }    
}

 

 

Another script I use is where the script reads the layer size and updates another existing text layer with that information, this one in inches.

 

function run(){
    var layer = activeDocument.activeLayer;
 
app.preferences.rulerUnits = Units.INCHES;

    var length = Math.round((layer.bounds[2]-layer.bounds[0])*100)/100; 
    var width = Math.round((layer.bounds[3]-layer.bounds[1])*100)/100;

     var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.artLayers.getByName("SIZEMEASUREMENTS2");    
        myLayerText.kind = LayerKind.TEXT;    
        myLayerText.textItem.contents = length + "x" + width + "IN(WxH)"; 
}
run()

app.preferences.rulerUnits = Units.MM;

 

 

Is is possible to get Illustrator to do this? I use the first one because I have another script that resizes files and inputs the measurement in the file name, but even if Illustrator just had to use the second one that would also be fine, since I know layers work differently in Illustrator than in Photoshop. I want to use it in a template so existing text layers would always be there when the template is opened.

 

Many thanks in advance 🙂

Adobe Community Professional
Correct answer by CarlosCanto | Adobe Community Professional

PS and Illustrator have different sintax. The snippet below works in illustrator, I made minimal changes needed only. Hope that's what you need...

 

1st Script, activate Filename layer

Before

textContents.JPG

 

After 

textContents2.JPG

 

if (app.documents.length > 0) mainScript();      
      
function mainScript() {    
    try{    
        var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.layers.getByName("SIZEMEASUREMENTS");    
        myLayerText.textFrames[0].contents = myLayerName;
        
        //myLayerText.textItem.contents = myLayerName.match(/.{2}$/);
        //myLayerText.textItem.contents = myLayerName.slice(-16,-9)+("mm(WxH)");
  
    }catch (errStr){    
        alert(errStr);    
    }    
}

 

Carlos

TOPICS
Scripting

Views

36

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
Sep 09, 2020 0
Adobe Community Professional ,
Sep 09, 2020

Copy link to clipboard

Copied

PS and Illustrator have different sintax. The snippet below works in illustrator, I made minimal changes needed only. Hope that's what you need...

 

1st Script, activate Filename layer

Before

textContents.JPG

 

After 

textContents2.JPG

 

if (app.documents.length > 0) mainScript();      
      
function mainScript() {    
    try{    
        var myLayerName = activeDocument.activeLayer.name;            
        var myLayerText = activeDocument.layers.getByName("SIZEMEASUREMENTS");    
        myLayerText.textFrames[0].contents = myLayerName;
        
        //myLayerText.textItem.contents = myLayerName.match(/.{2}$/);
        //myLayerText.textItem.contents = myLayerName.slice(-16,-9)+("mm(WxH)");
  
    }catch (errStr){    
        alert(errStr);    
    }    
}

 

Carlos

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...
Sep 09, 2020 0
Resources