Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runs but makes no changes #1

Closed
racherella opened this issue Mar 23, 2015 · 29 comments
Closed

Runs but makes no changes #1

racherella opened this issue Mar 23, 2015 · 29 comments

Comments

@racherella
Copy link

Hi seblavoie! Thanks so much for the much needed script.

I'm running AI CC 2014 on a mac and the script runs (1st pop up, 2nd pop up) but doesn't change the layer name as expected—it doesn't seem to do anything actually.

Any thoughts? Forgive me if I've not been clear enough.

Best, RB

@seblavoie
Copy link
Owner

Hi Rachella, I also run AI CC 2014 on mac. The script will rename the currently selected layers or layers to which belong selected objects in the active document, did you have a selection before starting the script? I have just added an error message if no layer is selected. f26d8ed

@racherella
Copy link
Author

Thanks for the response seblavoie!

New version pings as expected if no layer is selected, but I still can't seem to replace layer name as expected. In this example I'm trying to change the layer named "pink star" to "test replace". OMG I know you're not tech support...but I'm feeling dense here and could use a push in the right direction.

Best, RB

screen shot 2015-03-26 at 1 43 46 am
screen shot 2015-03-26 at 1 44 04 am
screen shot 2015-03-26 at 1 44 28 am

@seblavoie
Copy link
Owner

That is very strange… Do you have the Adobe Extendscript Toolkit? It comes with the CC subscription. If you do, you could try to open the file Rename Layers.jsx and run it (+R). It should then point you where the errors are happening.

@racherella
Copy link
Author

Thanks again for the script and the response.
I didn't have any more luck with it, but I didn't try that hard.

::rolls up sleeves, sets in for the task of renaming layers the old fashioned way::

@seblavoie
Copy link
Owner

Alright then, I wish you good luck! 👌

@SheepDomination
Copy link

Does this script work with CS5 ? I have a few suggestions, if so.

@seblavoie
Copy link
Owner

It hasn't been tested in cs5. I've only used it in CC and CC 2014. I don't have cs5 so that will be hard for me to make it work…

@SheepDomination
Copy link

I could test for you, couldn't you reference the Illustrator CS5 Scripting guide and compare ? :)

@seblavoie
Copy link
Owner

The layer object in cs5 guide (http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/illustrator_scripting_guide_cs5.pdf) isn't as well described but I am pretty sure it has a name attribute. Anyway you can test it and tell me if it works.

@SheepDomination
Copy link

When I select a layer, any layer for that matter, I get the error "Select the layer you would like to be renamed". It doesn't appear as though the script doesn't work, it's a matter of having the script understand Illustrator CS5 layers, that is my guess.

@seblavoie
Copy link
Owner

Okay, so the problem comes from if(app.activeDocument.selection.length > 0). app.activeDocument probably doesn't have a selection property. Again, I cannot test it, but I can suggest you to remove the lines 7, 10, 11, 12 from Rename Layers.jsx and change on line 9

this.renameLayers(app.activeDocument.selection);

for

this.renameLayers(app.activeDocument.layers);

@seblavoie seblavoie reopened this Apr 17, 2015
@SheepDomination
Copy link

Same error :(

@seblavoie
Copy link
Owner

Could you run it through ExtendScript Toolkit? It would flag the errors.

@SheepDomination
Copy link

The only error I get after running the script in ExtendScript Toolkit is; illustrator-18 is undefined, although there is no line mentioned.

@seblavoie
Copy link
Owner

You need to change the version you are targeting.

2015-04-18 at 14 09

@SheepDomination
Copy link

I always had the target on Adobe Illustrator CS5. There are no debugging errors, except for the error I mentioned.

@seblavoie
Copy link
Owner

Okay that was my bad, Illustrator-18 was hardcoded as the target. You might want to delete line 2 or pull the latest version. I have just corrected it.

@SheepDomination
Copy link

I downloaded the latest version; same problem; same error.

@seblavoie
Copy link
Owner

Well… This will be hard for me to continue the follow-up without CS5. I think we'll have to consider the script not compatible with CS5 and lower unless you can fix the bug from your side.

@SheepDomination
Copy link

Can I share your code so I can hopefully get it working with CS5 ?

@seblavoie
Copy link
Owner

Sure, that’s why it’s open-sourced ;)

@racherella
Copy link
Author

SheepDomination you will be my hero if you get it working!

Sebastien...you will continue to be awesome too!

*Rachel Borengasser */ Chief Operating Officer
281.468.6477 | [email protected]

••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

LUMINARE
Medical Quality Improvement

On Mon, Apr 20, 2015 at 8:40 PM, Sébastien Lavoie [email protected]
wrote:

Sure, that’s why it’s open-sourced ;)


Reply to this email directly or view it on GitHub
#1 (comment)
.

@SheepDomination
Copy link

I have good news, thanks to some help.

This code will rename the layers in illustrator, with the ability to add prefix and suffix to the layer names.

var doc = app.activeDocument, lays = [];  
for(var i = 0; i < doc.layers.length; i++){  
    lays.push(doc.layers[i].name);  
}  
var w = new Window('dialog',"Layer Name Editor");  
var list = w.add('group');  
list.orientation = "Column";  
var head = list.add('group');  
head.alignment = "left";  
var p = head.add('statictext', undefined, "Prefix");  
var n = head.add('statictext', [0,0,165,20], "            Layer Name");  
var s = head.add('statictext', undefined, "Suffix");  
var  pre = [], nam = [], suf = [];  
for(var i = 0; i < lays.length; i++){  
    newLine(i,"item" + i);  
}  
function newLine(num,item){  
    item = list.add('group');  
    item.alignment = "left";  
    pre[num] = item.add('checkbox', undefined,"");  
    nam[num] = item.add('edittext', [0,0,200,20], lays[i]);  
    nam[num].characters = 50;  
    suf[num] = item.add('checkbox', undefined, "");  
}  
var sep1 = list.add("panel");  
sep1.alignment = ["fill","fill"];  
sep1.minimumSize.height = sep1.maximumSize.height = 2;  
var prefixt = list.add('statictext', undefined, "Prefix to add to checked layers");  
var prefix = list.add('edittext', [0,0,250,20], "");  
var sep2 = list.add("panel");  
sep2.alignment = ["fill","fill"];  
sep2.minimumSize.height = sep2.maximumSize.height = 2;  
var prefixt = list.add('statictext', undefined, "Suffix to add to checked layers");  
var suffix = list.add('edittext', [0,0,250,20], "");  
var sep3 = list.add("panel");  
sep3.alignment = ["fill","fill"];  
sep3.minimumSize.height = sep3.maximumSize.height = 2;  
var ButtonGroup = w.add("group");  
  ButtonGroup.margins = [0,-10,0,-8];  
  ButtonGroup.alignment = "right";  
  var go = ButtonGroup.add ("button", undefined, "OK");  
  var stop = ButtonGroup.add ("button", undefined, "Cancel");  
  stop.onClick = function(){  
  w.close();  
  }  
    go.onClick = function(){  
        var validatePre = false, validateSuf = false, validateMessage = "";  
        for(var i = 0; i < lays.length; i++){  
            if(pre[i].value == true && prefix.text == ""){validatePre = true}  
            if(suf[i].value == true && suffix.text == ""){validateSuf = true}  
        }  
        if(validatePre == true){validateMessage = "Layers have been marked for Prefix, but no Prefix entered\n"}  
        if(validateSuf == true){validateMessage = validateMessage + "Layers have been marked for Suffix, but no Suffix entered"}  
        if(validateMessage != ""){  
            alert(validateMessage);  
        }else{  
            w.close();  
            goTime();  
        }  
  }  
w.show();  


function goTime(){  
    for(var i = 0; i < lays.length; i++){  
        var na = nam[i].text;  
        var pr = "";  
        var su = "";  
        if(pre[i].value == true){pr = prefix.text + " - "}  
        if(suf[i].value == true){su = " - " + suffix.text}  
        doc.layers[i].name = pr + na + su;  
    }  
}  

I was informed that seblavoie script works on renaming artboards ? That wasn't my goal, if that is even correct, hopefully seblavoie can verify this ? Either way this script will do what we all want.

@racherella
Copy link
Author

Whoa! Thanks! I'll test and let y'all know how it works for me. 

Sent from a mobile.

Thursday, May 14, 2015, 10:30 PM -0500 from SheepDomination [email protected]:

I have good news, thanks to some help.
This code will rename the layers in illustrator, with the ability to add prefix and suffix to the layer names.
var doc = app.activeDocument, lays = [];
for(var i = 0; i < doc.layers.length; i++){
lays.push(doc.layers[i].name);
}
var w = new Window('dialog',"Layer Name Editor");
var list = w.add('group');
list.orientation = "Column";
var head = list.add('group');
head.alignment = "left";
var p = head.add('statictext', undefined, "Prefix");
var n = head.add('statictext', [0,0,165,20], " Layer Name");
var s = head.add('statictext', undefined, "Suffix");
var pre = [], nam = [], suf = [];
for(var i = 0; i < lays.length; i++){
newLine(i,"item" + i);
}
function newLine(num,item){
item = list.add('group');
item.alignment = "left";
pre[num] = item.add('checkbox', undefined,"");
nam[num] = item.add('edittext', [0,0,200,20], lays[i]);
nam[num].characters = 50;
suf[num] = item.add('checkbox', undefined, "");
}
var sep1 = list.add("panel");
sep1.alignment = ["fill","fill"];
sep1.minimumSize.height = sep1.maximumSize.height = 2;
var prefixt = list.add('statictext', undefined, "Prefix to add to checked layers");
var prefix = list.add('edittext', [0,0,250,20], "");
var sep2 = list.add("panel");
sep2.alignment = ["fill","fill"];
sep2.minimumSize.height = sep2.maximumSize.height = 2;
var prefixt = list.add('statictext', undefined, "Suffix to add to checked layers");
var suffix = list.add('edittext', [0,0,250,20], "");
var sep3 = list.add("panel");
sep3.alignment = ["fill","fill"];
sep3.minimumSize.height = sep3.maximumSize.height = 2;
var ButtonGroup = w.add("group");
ButtonGroup.margins = [0,-10,0,-8];
ButtonGroup.alignment = "right";
var go = ButtonGroup.add ("button", undefined, "OK");
var stop = ButtonGroup.add ("button", undefined, "Cancel");
stop.onClick = function(){
w.close();
}
go.onClick = function(){
var validatePre = false, validateSuf = false, validateMessage = "";
for(var i = 0; i < lays.length; i++){
if(pre[i].value == true && prefix.text == ""){validatePre = true}
if(suf[i].value == true && suffix.text == ""){validateSuf = true}
}
if(validatePre == true){validateMessage = "Layers have been marked for Prefix, but no Prefix entered\n"}
if(validateSuf == true){validateMessage = validateMessage + "Layers have been marked for Suffix, but no Suffix entered"}
if(validateMessage != ""){
alert(validateMessage);
}else{
w.close();
goTime();
}
}
w.show();

function goTime(){
for(var i = 0; i < lays.length; i++){
var na = nam[i].text;
var pr = "";
var su = "";
if(pre[i].value == true){pr = prefix.text + " - "}
if(suf[i].value == true){su = " - " + suffix.text}
doc.layers[i].name = pr + na + su;
}
}

I was informed that seblavoie script works on renaming artboards ? That wasn't my goal, if that is even correct, hopefully seblavoie can verify this ? Either way this script will do what we all want.

Reply to this email directly or view it on GitHub .

@seblavoie
Copy link
Owner

That is indeed a very cool script. More refined than my solution. Although it does not really act the same way. I really needed in my case to replace stuff in layer names. Usually Layer to something. I like the idea of prefix and suffixes though. I'll try to somewhat merge both scripts eventually, and point out to this issue in the readme for people experiencing issues with the script as you were. Thanks!

@SheepDomination
Copy link

Seblavoie - If you can expand your script with this script, you'll have a more flexible and powerful script :)

@orodrigodacosta
Copy link

Hi! Sevlavoie's solution still works! I tested no.ai 24.2.1. but I couldn't change the original layer suffix number.
The SheepDomination solution no longer works. Any perspective for updating?
Thx!

@jdietrick
Copy link

Hi! This script worked like a dream in Illustrator, but when I import the .ai file into After Effects, it shows the old layer names. :(

Any thoughts?

@seblavoie
Copy link
Owner

I am not really using this script anymore and don't have much time developing it, sorry. But if someone wants to take a jab at fixing the issue, I will gladly test and merge a pull request :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants