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

Script to make multiple layers in one task

Engaged ,
Mar 15, 2009 Mar 15, 2009
From time to time I find the need to make many empty layers named A-Z. I use this when preparing a font drawn in Illustrator for moving to FontLab.

I have not found any ready made script to do this and would like a little help to make one. Or, if somebody would like to make this script it would be even more helpful.

The situation is this:
A full set of glyphs is ready in Illustrator and all are on Layer 1.
Artboard is set according to: http://font.is/?p=48
Glyphs are aligned to left on top of each other.
Need to make empty layers, A-Z and even more. Tedious by hand.
Then each glyph is moved from the sublayers to their own new layers. I could continue doing this part by hand.

I could of course make these layers in one file and copy them each time to each project but a script would be soooo much cooler.

Any help with this? Hints?

Thanks in advance.
TOPICS
Scripting
9.2K
Translate
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
Guest
Mar 16, 2009 Mar 16, 2009
Hello Sigurdur,

With the follow JavaScript you can create layers in Illustrator.

layerIniName -> Put here first ASCII code (A=65, a=97)
numberOfLayers -> Put here how many layer do you need

Code:
//Apply to myDoc the active document
var myDoc = app.activeDocument;
//define firts caracter and how many layers do you need
var layerIniName =65;
var numberOfLayers=25;

//Create the layers
for(var i=0; i<=numberOfLayers; i++) {
var layerName = String.fromCharCode(layerIniName)
var myLayer = myDoc.layers.add();
myLayer.name = layerName
layerIniName++
}

I hope it will be usefully for you. Sorry for my english

Santiago
Translate
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
Engaged ,
Mar 16, 2009 Mar 16, 2009
Awww... really cool. Thanks so much.
I'll try it later on, just stuck in a major stress project right now.

You English is about the same quality as mine. (not native language).

I'll report, probably tonight when I have tried this.

Thanks again.
Translate
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
Engaged ,
Mar 16, 2009 Mar 16, 2009
Hi again.

I have copied the code and saved as a little .js file. I can not get Illustrator to run the file. It is grayed out.

The file looks like this:

//Apply to myDoc the active document

var myDoc = app.activeDocument;
//define first character and how many layers do you need

var layerIniName =65;
var numberOfLayers=25;

//Create the layers

for(var i=0; i<=numberOfLayers; i++) {
var layerName = String.fromCharCode(layerIniName)
var myLayer = myDoc.layers.add(); myLayer.name = layerName layerIniName++
}

Am I doing something wrong?
Translate
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 16, 2009 Mar 16, 2009
You can either run it manually by pressing Ctrl+F12 and then selecting the file or by placing it in the Scripts folder, which is typically:
C:\Program Files\Adobe\Adobe Illustrator CSx\Presets\Scripts\

If you choose the latter option the script will appear in the Scripts menu under File, but you will need to re-start Illustrator in order to see it.
Translate
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
Engaged ,
Mar 16, 2009 Mar 16, 2009
@try67. That is what I have done. Ctrl+F12 or like on my mac: Cmd+F12 shows me the scripts I have which are not in the ... /Presets/Scripts.

I was wondering if the script was missing some vital part in the header. I tried to compare it to other scripts that I can see and run in Illustrator but I am such a noob I can't figure it out.

Oh well. I'll keep on trying.

But thanks anyway. Any help is welcomed. Hate to waste others time on such a basic stuff.
Translate
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 16, 2009 Mar 16, 2009
You were missing some semicolons. Use this instead:

//Apply to myDoc the active document

var myDoc = app.activeDocument;
//define first character and how many layers do you need

var layerIniName =65;
var numberOfLayers=25;

//Create the layers

for(var i=0; i<=numberOfLayers; i++) {
var layerName = String.fromCharCode(layerIniName);
var myLayer = myDoc.layers.add();
myLayer.name = layerName;
layerIniName++ }
Translate
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 16, 2009 Mar 16, 2009
PS - I don't see the need for this:
layerIniName++
Just change the first line in the loop to:
var layerName = String.fromCharCode(layerIniName+i);
Translate
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
Engaged ,
Mar 16, 2009 Mar 16, 2009
Thank you both for all the help.

The script is fully working now. The problem was my fault I guess. I was using Smultron to make the script file but when I used TextEdit everything worked fine.

This is sooo nice. Fast and nice.
Translate
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
Guest
Mar 17, 2009 Mar 17, 2009
Hello Sigurdur,

I tried this script in my PC.

If you want to try script, you can use the tool from Adobe.

system drive:Aplications:Utilities:Adobe Utilities:ExtendedScript Toolkit CS4

I think, in the main windows, You need to select Adobe Illustrator in the ObjectModelViewer
Translate
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
Engaged ,
Mar 17, 2009 Mar 17, 2009
Yes, why not? At least I want to get a better understanding of the scripting.

Thank you for pointing this out. The program is in the same place on the mac.

I'll check it out.
Translate
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
LEGEND ,
Mar 17, 2009 Mar 17, 2009
> A full set of glyphs is ready in Illustrator and all are on Layer 1.

> Then each glyph is moved from the sublayers to their own new layers.

Sigurdur,

As I read it, the script above creates and names empty layers, but does not move the glyphs to them. I would think moving them more tedious than naming the layers.

Are you aware that you can distribute the glyphs each to its own layer in the UI, without resorting to a script?:

1. SelectAll. Group.
2. Select the Group in the Layers Palette.
3. Layers Palette flyout menu: Release To Layers (sequence).

The layers will just be named sequentially (Layer 2, Layer 3, etc.)

JET
Translate
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
Engaged ,
Mar 17, 2009 Mar 17, 2009
Thanks James. Great point.

I should have mentioned this before, but I have tried this too. It works great and helps in many cases. But it's great to mention this here if others happen to read it.

However this has a little downside for me at least with the font designing:

1. Accented and not joined parts of characters or glyphs get split into individual layers. Like the bar of the letter Eth. Often the set of letters are made of parts that I want to move/copy between layers.

2. The script makes named layers which it a major advantage. Sometimes there are points not very close to the main glyph which makes the icon preview a bit distorted or smaller, so names are great.

3. It's not always that the glyphs are made/stacked in alphabetical order which would make me have to reorder the layers.

I am preparing to duplicate the script to be able to let it make first the A-Z glyphs and then another version make layers for accented glyphs etc. I guess it would be possible to add a feature to the script to do selected glyphs?

Anyway, nice to get your imput. Last Sunday when I was trying to find a solution to this matter I bumped into your site and downloaded everything I could find and I am going to look at your scripts at first chance. I asked a while ago on Mordy's site where I could find your stuff but got no answer.

Thanks all.
Translate
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
LEGEND ,
Mar 17, 2009 Mar 17, 2009
> 1. Accented and not joined parts of characters or glyphs get split into individual layers.

When drawing glyphs, I would make each glyph with multiple paths a Compound Path.

> 2. The script makes named layers which it a major advantage.

No argument there.

> 3. It's not always that the glyphs are made/stacked in alphabetical order which would make me have to reorder the layers.

If you:

1. Draw the glyphs, compounding those with counters or multiple paths.

2. Give them names as you go. (Name the path in the Layer's Palette.)

Then a script that creates and names the Layers could be made to also move the glyphs to the appropriately named Layer.

Which raises the question: Why aren't you drawing the glyphs on individual layers to begin with?

JET
Translate
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
Engaged ,
Mar 17, 2009 Mar 17, 2009
I have never thought about doing the glyphs that way, Compound Path at that stage and so forth. Interesting, and I will surely try that.

Doing that and naming the paths in the layers palette is also interesting idea and scripting the act of moving to layers is surely tempting too.

I always thought my work as a designer as one that didn't need scripting in any way and therefore I have not but any effort into learning how to script. All the same some scripting languages tempt me more than others as they look more useful for me directly, Java Script and Python to name the top ones. Unfortunately I am only at the stage of having collected a lot of material to read but that is about it.

The question: Why not draw the glyphs on individual layers to begin with? :

Well, you see, fast sketching a draft for a font dragging copies between glyphs on the same level makes one just think of the glyphs and no planning. Actually when I have the skeleton made up I start to organize and layers come in.

But as the knowledge of FontLab is not every ones I often get to help out with making a font for someone else and it has never been on more than one layer. Last time it was on Friday and then I started to think about a faster way to do this layer making.

twitter.com/sigurarm
Translate
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
Engaged ,
May 20, 2009 May 20, 2009

Thanks again all who helped me with this script. It's great and it's handy.

I have another need for a very similar script which I think many others would find useful. I have tried to find out how to change this script or make a new on my own but it's not easy to find out how. (JavaScripting Illustrator pdfs).

Here is what I would like to see:

A script that would make x number of layers with specific names.

One would be able to edit the names of the layers in the script to use the same setup over and over and have a few different scripts ready.

The idea is to make different layer sets for specific jobs.

One would maybe make layers called: Background, Pictures, Text, Guides

Another maybe: Background, Pictures, Text 1, Text 2, Headlines, Extras... all editable in the script.

Any help?

What I find frustrating, since I am not a scripter is to read in the manual that to make a new layer is: Add ()  What? Very few samples and much time needed to learn. I promise I will try to get better into this but making this little script is too much for me as a starter.

Thanks in advance.

Translate
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
Engaged ,
May 21, 2009 May 21, 2009

I played around with the ExtendScript Toolkit and cutted and pasted the previous script from here until I managed to get a script that actually works like I was thinking. I then added a code from the CS4 Reference Manual to move Layer1 to the top (just to see if it worked).

I have no idea yet if the the code includes something that does not belong, but at least I get no errors. The current code is like this now:

//Apply to myDoc the active document

var layerName = LayerOrderType;

var myDoc = app.activeDocument;

//define first character and how many layers do you need

var layerName

var numberOfLayers=0;

//Create the layers

for(var i=0; i<=numberOfLayers; i++)

{ var layerName = "Background";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }

{ var layerName = "Picture";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }

{ var layerName = "Text";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }

{ var layerName = "Guides";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }

// Moves the bottom layer to become the topmost layer

if (documents.length > 0) {

countOfLayers = activeDocument.layers.length;

if (countOfLayers > 1) {

bottomLayer = activeDocument.layers[countOfLayers-1];

bottomLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

}

else {

alert("The active document only has only 1 layer")

}

}

Translate
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 ,
Sep 09, 2014 Sep 09, 2014
LATEST

and if i wanna add and ai file in this same layer? can i do that?

Translate
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