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

How to export object with hidden or locked layer as png?

Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hello,
This topic is a bit complex, but I will try to explain my problem as well as I can.
I'm trying to export selected assets as .png images with extendscript but some of my art pieces have locked/hidden layers/pageitems which prompts me this message:

JojjeS_0-1624348167197.png

Some notes on this:

  • I am able to recursively walk through my objects and unlock/unhide them. But unhiding certain art makes the artwork look wrong
  • I think clipping masks interfere here as well, prompting this error.
  • I read this post about the same kind of problem, but their solution was either to unlock the layers and lock them again after, or to use some operator overwriting which seems too complex for what I want to achive.

This is a part from the code which exports the selected asset as an image:

 

  for (var i=0, len=selected_art.length; i < len ; i++) {
    var item = selected_art[i]
    item.selected = true
    doc.fitArtboardToSelectedArt(doc.artboards.length-1)
    if(os == WINDOWS){
      file_path = OsSpecificFolderPath(immage_trimmer_path + "/" + item.name + ".png")
    }
    else{
      file_path = immage_trimmer_path + "/" + item.name + ".png"
    }
    var file = new File(file_path);
    
    doc.exportFile(file, ExportType.PNG24, options);
    item.selected = false
  };

 

The line that prompts this error is the

doc.fitArtboardToSelectedArt(doc.artboards.length-1)

which is slightly surprising. I would expect item.selected = true to be the culprit..

 

In the end all I want is the same functionality as File -> Export selected... without the prompt, is there any way to work around this?
Thanks in advance

TOPICS
Import and export , Scripting , Tools

Views

698

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

Guide , Jun 22, 2021 Jun 22, 2021

I don't understand your code. What is selected_art? Is it the "selection" collection, i.e. the items selected manually? But then locked and invisible items cannot be selected manually. Is is the collection of the members of a selected group? But then the length of such collections is undefined if members are locked or invisible and a loop never begins.  So, I'm unble to replicate the error you get. 

 

Anyway, it seems to me that your problem is that you're trying to select items specifically to us

...

Votes

Translate

Translate
Adobe
Guide ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

I don't understand your code. What is selected_art? Is it the "selection" collection, i.e. the items selected manually? But then locked and invisible items cannot be selected manually. Is is the collection of the members of a selected group? But then the length of such collections is undefined if members are locked or invisible and a loop never begins.  So, I'm unble to replicate the error you get. 

 

Anyway, it seems to me that your problem is that you're trying to select items specifically to use fitArtboardToSelectedArt(). Why not fit the artboards to the items without selecting them? For example:

 

var items = app.activeDocument.pageItems;
var AB = app.activeDocument.artboards[0];
for (var  i = 0; i < items.length; i++) {
    AB.artboardRect = items[i].controlBounds;
};

 

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
Explorer ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

LATEST

Hello Femkeblanco,
Thank you so much for your reply! To clarify; Selected art is indeed the array of manually selected art.

var selected_art = doc.selection;

The locked or hidden art is not on the topmost object, so the user is able to select it, but once I try to fit the artboard too the selected art it notices the hidden/locked child objects of the group.

 

I never thought about fitting the artboard manually with the bounds! This might be a good solution.

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