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

Deleting hidden sublayers in specific layer

Explorer ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Hi, I need help with a small issue. I tried several delete hidden layer scripts I found but none of them worked.

I wan to delete the hidden layers in Layer "Text" before I export the file.

 

delete-hidden.jpg

 

I am using this to make changes to the layers beforehand:

 

if (bks.layers.getByName("Text")){
bks.layers.getByName("Text").locked = false;
var text = bks.layers.getByName("Text"); 

 

...

}

TOPICS
Scripting

Views

769

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 ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Hi @ellipirelli,

it seems you don't have sublayers in your layer "Text" - but text frame items and path items instead.

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 ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Hi,

As explained by pixxxel_schubser  Text layer do not have sublayers, Text  layer have pageItems inside that and that can be either textframes, file, rectangle, path or any other object. If you want to delete hidden items from layer "Text" try following snippet

 

var layer = app.activeDocument.layers.getByName('Text');
var pageItems = layer.pageItems;
for (var i = pageItems.length - 1; i >= 0; i--) {
  if (pageItems[i].hidden)
    pageItems[i].remove();
}

 

Let us know if this works for you.

Best regards

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 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

Hi,

it worked when exporting the eps and svg files but not with the ai files. Any idea?


Kind regards,

 

Elli

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 ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

Well, this is not something related to format of the file. Could you please share the screenshot of Layers panel when ai file is open or share the ai file in which it is not working. There must be something how you have created items in ai files.

Best regards

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 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

I think I need to explain in more detail. The script is changing things in the file and then exporting it into the formats ai, eps, svg and png. In the exported ai file the hidden pageItems inside are simply not removed. 

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 ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

I am still not clear. So, please confirm are you trying to do following steps.

  • You created file in Illustrator
  • Save as in eps, svg and ai format
  • Also you export the illustrator file into png file.
  • Now you run the above script in all exported files?

If yes, after that you are trying to run the above script to delete hidden items from ai, eps and svg and png files. But it will not delet from png file because png is an image file not left as vector. May be I am not able to understand the scenario clearly, but it should work for ai format. May be you can share somescreen shoyt or video to show your steps and we can help you out more.

 

 

Best regards

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 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

Hi,

sorry this is so late.

I have created icons and 4 different Scripts that export then in different ways, for instance several different colors, sizes, with a circle in the background or without a circle. Every script saves or exports the icons as ai, eps, svg and png into folders.

 

The above script is a part of each export and not an extra script that runs at the end. 

 

Right now it looks like this:

 

var app = app.activeDocument;
textlayer = app.layers.getByName("Text");

    if (textlayer.visible){
        textlayer.locked = false;

        var group = app.layers["Icon"].groupItems[0];
        var lastIndex = (group.pageItems.length) - 1;
        group.pageItems[lastIndex].remove();

        if (app.layers.getByName("icon")){
            app.layers.getByName("icon").locked = false;
            var icon = bks.layers.getByName("icon");
            icon.pageItems[0].pathItems.rectangle(-8.5*mm, 8.5*mm, 50.5*mm, 50.5*mm);
            for(var i = 0; i < icon.pageItems[0].pathItems.length; i++){
                var iconpath = icon.pageItems[0].pathItems[i];
                var iconobj = icon.pageItems[0];
                iconpath.strokeColor = swatch.color;
                var ab = bks.artboards[0];
                var artboardRight   = ab.artboardRect[2];
                var artboardBottom  = ab.artboardRect[3];
                var artboardX       = ab.artboardRect[0];
                var artboardY       = ab.artboardRect[1];
                var horziontalCenterPosition = (artboardRight - iconobj.width)/1.36;
                var verticalCenterPosition = (artboard + iconobj.height)/2;
                iconobj.position = [horziontalCenterPosition, verticalCenterPosition];
            }
            var place = icon.pageItems[0].pathItems[0];
            place.filled = false;
            place.stroked = false;
        }
        
        var text = app.layers.getByName("Text");

        for(var i = 0; i < text.textFrames[i].length; i++){
            textobj = text.textFrames[i];
            textobj.autoLeading = true;
        }

        text.textFrames[0].resize(24*px, 29*px);
        text.textFrames[1].resize(23*px, 29*px);
        text.textFrames[2].resize(25*px, 20*px);
        text.textFrames[3].resize(23*px, 29*px);
        text.textFrames[0].TextFrameItem = TextType.AREATEXT;
        text.textFrames[1].TextFrameItem = TextType.AREATEXT;
        text.textFrames[2].TextFrameItem = TextType.AREATEXT;
        text.textFrames[3].TextFrameItem = TextType.AREATEXT;
        text.textFrames[0].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[1].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[2].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[3].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[0].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[0].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[1].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[1].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[2].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[2].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[3].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[3].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[0].position = [40*px, 35*px];
        text.textFrames[1].position = [40*px, 35*px];
        text.textFrames[2].position = [40*px, 30*px];
        text.textFrames[3].position = [40*px, 27*px];
        text.textFrames[0].textRange.characterAttributes.size = 12;
        text.textFrames[1].textRange.characterAttributes.size = 12;
        text.textFrames[2].textRange.characterAttributes.size = 12;
        text.textFrames[3].textRange.characterAttributes.size = 9;
        text.textFrames[0].textRange.characterAttributes.leading = 9;
        text.textFrames[1].textRange.characterAttributes.leading = 9;
        text.textFrames[2].textRange.characterAttributes.leading = 10;
        text.textFrames[3].textRange.characterAttributes.leading = 7;
        text.textFrames[0].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 10;
        text.textFrames[1].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 12;
        text.textFrames[2].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 11;
        text.textFrames[3].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 8;
        text.textFrames[0].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[1].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[2].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[3].textRange.characterAttributes.fillColor = swatch.color;

        var pageItems = textlayer.pageItems;
        for (var i = pageItems.length - 1; i >= 0; i--) {
          if (pageItems[i].hidden)
            pageItems[i].remove();
        }
    }

    var param = app.name.split('.');
    realDocName = param[0];
    file = preffix+filepreffix+realDocName+'_grau'+suffix;
    folder = preffix+foldername;
    var f = new Folder(app.path + "/" + folder);
        if (!f.exists)
        f.create();
    var saveName = new File ( f + "/" + file );
    bks.saveAs( saveName, optionsEPS );
    bks.close(SaveOptions.DONOTSAVECHANGES);
    bks = null;
    app.open (fullDocName);
    app = app.activeDocument;

I'm sure my script is way too complimanted, but it works so far (for the most part) and it's my first time 🙂 

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 ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

Hi,

Well your script is not complicated, but it is not complete. Could you post complete script? Also app is an object that refers to the the application object. And in your first line of code

var app = app.activeDocument;

you are creating your own app object, which is not right way. You are overriding the actual app object that refecrs to an application with your variable app.

Correct way for this line will be as

var doc = app.activeDocument;

I mean you can use any name instead of doc but not app.  I am unable to run your script. I am not sure how this is working for you. Could you post working script so that we can help you out.

Best regards

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 24, 2020 Jun 24, 2020

Copy link to clipboard

Copied

Hey, first of all I'm not posting the entire script because it is long. I will just do one color with ai format.

 

var mm = 2.834645;
var px = 1;
var doc  = app.activeDocument;
var preffix = "";
var suffix = "";
var foldername = "foldername"
var filepreffix = "icon_"

fullDocName = doc.fullName;

var grey = new CMYKColor();
grey.cyan = 10;
grey.magenta = 0;
grey.yellow = 5;
grey.black = 60;

var optionsAI = new IllustratorSaveOptions();
optionsAI.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;

if (app.documents.length > 0) {
    doc.artboards[0].artboardRect = [0, 14.5*mm, 26*mm, 0];

    var swatch = doc.swatches.add();
    swatch.color = grey;
    swatch.name = "Grey CMYK";

    textlayer = doc.layers.getByName("Text");

    if (textlayer.visible){
        textlayer.locked = false;

        var group = doc.layers["Icon"].groupItems[0];
        var lastIndex = (group.pageItems.length) - 1;
        group.pageItems[lastIndex].remove();

        if (doc.layers.getByName("icon")){
            doc.layers.getByName("icon").locked = false;
            var icon = doc.layers.getByName("icon");
            icon.pageItems[0].pathItems.rectangle(-8.5*mm, 8.5*mm, 50.5*mm, 50.5*mm);
            for(var i = 0; i < icon.pageItems[0].pathItems.length; i++){
                var iconpath = icon.pageItems[0].pathItems[i];
                var iconobj = icon.pageItems[0];
                iconpath.strokeColor = swatch.color;
                var ab = doc.artboards[0];
                var artboardRight   = ab.artboardRect[2];
                var artboardBottom  = ab.artboardRect[3];
                var artboardX       = ab.artboardRect[0];
                var artboardY       = ab.artboardRect[1];
                var horziontalCenterPosition = (artboardRight - iconobj.width)/1.36;
                var verticalCenterPosition = (artboardY + iconobj.height)/2;
                iconobj.position = [horziontalCenterPosition, verticalCenterPosition];
            }
            var place = icon.pageItems[0].pathItems[0];
            place.filled = false;
            place.stroked = false;
        }
        
        var text = doc.layers.getByName("Text");

        for(var i = 0; i < text.textFrames[i].length; i++){
            textobj = text.textFrames[i];
            textobj.autoLeading = true;
        }

        text.textFrames[0].resize(24*px, 29*px);
        text.textFrames[1].resize(23*px, 29*px);
        text.textFrames[2].resize(25*px, 20*px);
        text.textFrames[3].resize(23*px, 29*px);
        text.textFrames[0].TextFrameItem = TextType.AREATEXT;
        text.textFrames[1].TextFrameItem = TextType.AREATEXT;
        text.textFrames[2].TextFrameItem = TextType.AREATEXT;
        text.textFrames[3].TextFrameItem = TextType.AREATEXT;
        text.textFrames[0].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[1].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[2].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[3].figureStyle = FigureStyleType.PROPORTIONAL;
        text.textFrames[0].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[0].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[1].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[1].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[2].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[2].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[3].textRange.characterAttributes.horizontalScale = 100;
        text.textFrames[3].textRange.characterAttributes.verticalScale = 100;
        text.textFrames[0].position = [40*px, 35*px];
        text.textFrames[1].position = [40*px, 35*px];
        text.textFrames[2].position = [40*px, 30*px];
        text.textFrames[3].position = [40*px, 27*px];
        text.textFrames[0].textRange.characterAttributes.size = 12;
        text.textFrames[1].textRange.characterAttributes.size = 12;
        text.textFrames[2].textRange.characterAttributes.size = 12;
        text.textFrames[3].textRange.characterAttributes.size = 9;
        text.textFrames[0].textRange.characterAttributes.leading = 9;
        text.textFrames[1].textRange.characterAttributes.leading = 9;
        text.textFrames[2].textRange.characterAttributes.leading = 10;
        text.textFrames[3].textRange.characterAttributes.leading = 7;
        text.textFrames[0].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 10;
        text.textFrames[1].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 12;
        text.textFrames[2].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 11;
        text.textFrames[3].paragraphs[0].paragraphAttributes.desiredLetterSpacing = 8;
        text.textFrames[0].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[1].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[2].textRange.characterAttributes.fillColor = swatch.color;
        text.textFrames[3].textRange.characterAttributes.fillColor = swatch.color;

        var pageItems = textlayer.pageItems;
        for (var i = pageItems.length - 1; i >= 0; i--) {
          if (pageItems[i].hidden)
            pageItems[i].remove();
        }
    }

    if (textlayer.visible == false){
        textlayer.visible = true;

        var group = doc.layers["Icon"].groupItems[0];
        var lastIndex = (group.pageItems.length) - 1;
        group.pageItems[lastIndex].remove();

        if (doc.layers.getByName("icon")){
            doc.layers.getByName("icon").locked = false;
            var icon = doc.layers.getByName("icon");
            icon.pageItems[0].pathItems.rectangle(-8.5*mm, 8.5*mm, 50.5*mm, 50.5*mm);
            for(var i = 0; i < icon.pageItems[0].pathItems.length; i++){
                var iconpath = icon.pageItems[0].pathItems[i];
                var iconobj = icon.pageItems[0];
                iconpath.strokeColor = swatch.color;
                var ab = doc.artboards[0];
                var artboardRight   = ab.artboardRect[2];
                var artboardBottom  = ab.artboardRect[3];
                var artboardX       = ab.artboardRect[0];
                var artboardY       = ab.artboardRect[1];
                var horziontalCenterPosition = (artboardRight - iconobj.width)/2;
                var verticalCenterPosition = (artboardY + iconobj.height)/2;
                iconobj.position = [horziontalCenterPosition, verticalCenterPosition];
            }
            var place = icon.pageItems[0].pathItems[0];
            place.filled = false;
            place.stroked = false;
        }

        textlayer.locked = false;
        textlayer.remove();

        var group = doc.layers["Icon"].groupItems[0];
        for (var i = (group.pageItems.length) - 1; i >= 0; i--) {
            if (group.pageItems[i].typename == "TextFrameItem") {
                group.pageItems[i].remove();
            }
        }
    }

    var item = doc.pageItems[0];
    var scale = 22;
    item.resize(
        scale , 
        scale ,
        true,
        true,
        true, 
        true,
        scale ,
        undefined);

    var param = doc.name.split('.');
    realDocName = param[0];
    file = preffix+filepreffix+realDocName+'_grey'+suffix;
    folder = preffix+foldername;
    var f = new Folder(doc.path + "/" + folder);
        if (!f.exists)
        f.create();
    var saveName = new File ( f + "/" + file );
    doc.saveAs( saveName, optionsAI );
    doc.close(SaveOptions.DONOTSAVECHANGES);
    doc= null;
    app.open (fullDocName);
    doc = app.activeDocument;
}

 

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 ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

LATEST

Sorry for the late reply, Still I am unable to run your script may be because it is not complete workflow. But I have gone through your script for the section where you are deleting or removing the  the item and I found one mistake that you have use typename for Textframe as "TextFrameItem".

 

Following line is wrong in above code, because typename of the text is "TextFrame" not "TextFrameItem"

if (group.pageItems[i].typename == "TextFrameItem") {

 

Correct version of this is

if (group.pageItems[i].typename == "TextFrame") {

 

I hope you are able to resolve this issue now. If not, let us know

 

 

Best regards

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 ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

If i understand the issue correctly, your script saves an EPS or SVG. Then when you open the EPS or SVG back in illustrator, there is still a bunch of artwork off the side of the artboard. Is this correct?

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 ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

Hallo @ellipirelli,

dein Englisch hört sich genau so an, wie meins auch.

😉

Liege ich richtig, dass du auch deutsch sprichst?

 

Wenn ja - es ist ziemlich schwierig zu sagen, wo der Fehler stecken könnte. Zumindest ohne eine Beispieldatei zum Testen zu bekommen oder den kompletten Code deines Skriptes analysieren zu können.

 

Vielleicht wäre es wirklich am Besten, wenn du in der *.ai alle Ebenen außer der Ebene „Text“ löscht und diese Datei dann unter anderem Namen als *.ai-Datei abspeicherst. Damit dürften dann eventuelle vertrauliche Daten ziemlich eliminiert sein und es sollte für dich kein Problem darstellen, wenn du diese Datei auf einen Hoster deiner Wahl (z.B. Dropbox oder xup.in) hochlädst und den Link zur Datei hier im Forum veröffentlichst.

 

Dann können wir mit deinem konkreten Dateiaufbau testen und kommen wahrscheinlich wesentlich schneller ans Ziel.

 

Viele Grüße

pixxxel_schubser

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