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

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

Explorer ,
Sep 09, 2020 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 🙂

TOPICS
Scripting

Views

374

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

Community Expert , Sep 09, 2020 Sep 09, 2020

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

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

LATEST

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

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