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

Bulk artboard renamer in photoshop

New Here ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

So I have a platform where I click "send to photoshop" and the artboards are created automaticaly based on what clients asked for. 

 

And in order to deliver what the clients asked I am using templates created before. Naming is very important, so what I do is to drag the templates in the new document created by the platform and rename every each template from the new document just created. 

 

What I am looking is to this with a script, and I have created this code below but I get an error. 

 

// Get active document and artboards
var docRef = app.activeDocument;
var artboards = docRef.artboards;

// Check if there are multiple artboards in the document
if (artboards.length > 1) {
  // Loop through each artboard
  for (var i = 0; i < artboards.length; i++) {
    var currentArtboard = artboards[i];
    var currentArtboardWidth = currentArtboard.artboardRect[2] - currentArtboard.artboardRect[0];
    var currentArtboardHeight = currentArtboard.artboardRect[1] - currentArtboard.artboardRect[3];
    
    // Loop through each artboard again to find artboards with same size
    for (var j = i + 1; j < artboards.length; j++) {
      var nextArtboard = artboards[j];
      var nextArtboardWidth = nextArtboard.artboardRect[2] - nextArtboard.artboardRect[0];
      var nextArtboardHeight = nextArtboard.artboardRect[1] - nextArtboard.artboardRect[3];
      
      // If artboards have same size, rename them
      if (currentArtboardWidth == nextArtboardWidth && currentArtboardHeight == nextArtboardHeight) {
        var nextArtboardName = nextArtboard.name;
        nextArtboard.name = currentArtboard.name;
        currentArtboard.name = nextArtboardName;
      }
    }
  }
} else if (artboards.length === 1) {
  alert("There is only one artboard in the document.");
} else {
  alert("There are no artboards in the document.");
}


primesc eroare asta:
Error 21: undefined is not an object.
Line: 6
->  if (artboards.length > 1) {

And the error is this:

mariang89846507_0-1679408393318.png

 

What I am doing wrong? 

 

Thanks!

 

Views

217

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
Adobe
Community Expert ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Hi @mariang89846507 , looks like you are trying to run the script from Photoshop—Photoshop documents don’t have an .artboards property. I think you would have to create an action descriptor in order to get at Photoshop art boards:

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document.html

 

Also, you’ve posted in the InDesign forum, so you might want to repost in the Photoshop forum. An InDesign script can communicate with Photoshop, but you have to setup a BridgeTalk object in order to open Photoshop from InDesign. If you need help with that I can post a sample.

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
New Here ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Hi and thank you! 

 

I was so obsessed to get an answer to this that I did not pay enough attention to where I am posting to. 

 

Thank you for your reply. 

 

I'll make sure to repost it.

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 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

LATEST

You’ll probably get an answer in the Photoshop forum, but your artboards variable returns as undefined in Photoshop—you’ll need to reference the Photoshop API, not Illustrator’s.

 

var docRef = app.activeDocument;
var artboards = docRef.artboards;
$.writeln(artboards)
//returns undefined

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 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Also, it looks like you are referencing the Illustrator API, which isn’t going to work with Photoshop

 

https://www.indesignjs.de/extendscriptAPI/illustrator-latest/#Artboard.html#d1e63472

 

In Photoshop you can get a layer’s .typename, and Artboard layers (as well as layer groups) return as "LayerSet":

 

var d = app.activeDocument.layers;
var al = []
for (var i = 0; i < d.length; i++){
    if (d[i].typename == "LayerSet") {
        al.push(d[i])
    } 
}

$.writeln(al)
//returns [LayerSet Group 1],[LayerSet Artboard 2],[LayerSet Artboard 1]

 

Screen Shot 45.png

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