Layers getByName() issue?

I'm using CS4 and I'm curious about a particular issue I'm having when I use getByName() to return a layer. It works fine unless the named layer is in a group. Using the following simple code it runs fine until I choose a layer that is within a group. Then it returns an error: No such element.
#target photoshop
n=app.activeDocument.activeLayer.name;
alert(n);
lay=app.activeDocument.artLayers.getByName(n);
alert(lay.name);
Am I doing something wrong? Is there another way other than coding a step-through function to do this so it will return the layer whether it's in a group or not without an error?

I apologize, X. I guess I'll have to back up a bit and explain more. The script is part of an Events Script that runs when I select a layer so all the Event passes to the script is a string containing the layer's name. I use this to automatically select a specific tool for certain layers. The trouble starts when the script takes too long to process. Then, for some reason, my keyboard shortcuts for some tools acts strangely and it turns into more of a hindrance than help.
Here is the actual script I'm using. Again, I apologize for the misinformation.
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
try {
    if (arguments.length >= 2) {
        var desc = arguments[0];
        var event = arguments[1];
        if (event == cTID('slct')) {
            var ref = desc.getReference(cTID('null'));
            var cls = ref.getDesiredClass();
            var nam=ref.getName();
//            alert(ref.getDesiredClass());
            if (nam=="P2P Copyright") {
                lay.visible=true;
                selectTool('moveTool');
            if (nam && ref.getDesiredClass() == 1283027488 && lay=app.activeDocument.layers.getByName(nam)) {
                function selectTool(tool) {
                    var desc9 = new ActionDescriptor();
                    var ref7 = new ActionReference();
                    ref7.putClass( app.stringIDToTypeID(tool) );
                    desc9.putReference( app.charIDToTypeID('null'), ref7 );
                    executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO );
                if (lay.kind == LayerKind.SMARTOBJECT);
                else if (cls == cTID('Chnl') || lay.kind != LayerKind.NORMAL) {
                    selectTool('paintbrushTool');
                    doAction('Reset Swatch','Tools');
                else if (cls == cTID('Lyr ')) {
                    doAction('RGB Color Select','Tools');
                    switch (nam) {
                        case "Details":
                            selectTool('magicStampTool');
                            break;
                        case "Dodge/Burn":
                            selectTool('paintbrushTool');
                            doAction('Dodge/Burn','Tools');
                            doAction('Reset Swatch','Tools');
                            doAction('Reverse Swatch','Tools');
                            break;
                        case "Touchup":
                        case "Color Correct":
                        case "Tone Correct":
                            selectTool('paintbrushTool');
                            doAction('Touchup','Tools');
                            break;
                        case "Spot Sharpen":
                            selectTool('paintbrushTool');
                        case "Cloning":
                            selectTool('cloneStampTool');
                            break;
                        case "P2P Copyright":
                            lay.visible=true;
                            selectTool('moveTool');
catch (e) {
    if (!e.line.indexOf("element")) alert( "Error: " + e + ":" + e.line );
As you can see in the "catch" section, I'm bypassing the error for this to get around it. The layer that is in a group is the "P2P Copyright" layer and as you can see, I had to add an extra if-then check just for that layer as it doesn't work in the switch section and throws an error.

Similar Messages

  • CS4 - Layers Display Issue and more

    I am running XP64 and have CS4-32 and CS4-64bit installed (using the updated and correct master collection installer)
    CS4-32 is basically unusable to me because I cannot see what I am doing as changes are being made to layers. It does it does not display updates to a layer on the screen until I click on the photo. For example, I have a psd file with a background layer and a Gaussian blur layer. A layer mask was used to mask out portions of the blur. IF I simply click the eyeball off on the blur layer, I see no changes to the photo until I click inside the photo. Disabling/enabling the layer mask as the same issue.
    If I use the brush tool to make adjustments to the mask, I can no longer see the mask in the layers pallet. The mask is displayed as tiny black and white dots and has no representation of my actual mask. As I brush changes onto the mask, I can see the effects in real time on the photo. But I still cannot see the normal B&W representation of the mask in the layers pallet. If I use the brush tool on the blur layer (not the mask), the photographic thumbnail representation normally displayed in the layer's palette also turns into displaying tiny black and white dots.
    b What is causing this issue? Is it a setting that I can change or a bug?
    The above issue(s) do NOT happen with CS4-XP64.
    Upon startup in CS4-64, I get a GPU disabled message. in CS4-32, I do not. But in CS4-32, my CPU settings are dimmed out and openGL is NOT checked. I have the latest drivers for my video cards installed. In CS3, enable 3D acceleration is checked. IN AE CS3 and AE CS4, it lists that my openGL is 2.1.2 and all features of AE are supported. What open-GL version does PS-CS4 need?

    Who was asking for sympathy? I was only asking for help, which a few people were kind enough to provide. I see no reason for people to make posts on other people's threads that do not offer any help. If you think that I am stupid for using an unsupported OS, then just don't post and keep those feelings to yourself. How are posts like this constructive? I even stated in my last post that I knew that I was not going to get any help from Adobe. So why reiterate that? What is the purpose of your and these types of posts? I am as baffled by them as you apparently are about why I am using XP64.
    But if you must know why I do not go to another OS, it is because back when I built this computer, XP64 was the only 64 bit OS around. I have this computer in a dual boot with XP PRo 32 bit and XP64. XP64 has, up to this point, been the most stable platform for me to run the adobe suite of products on. I can clearly say this since I have installed (and since deactivated) them on the same hardware under the XP32 boot. But XP64 has, again, been very stable. I have had many iterations of Adobe software on everything from Win 200 to several on XP and on Vista. And without a doubt this XP64 machine has been the most stable for what I do.
    The other reason why I continue to use XP64 is because I cannot upgrade to Vista 64 without a totally new computer. The MB drivers have not been developed for Vista.
    And lastly, 64 bit allows me to run more programs at once by utilizing more total memory, even with 32 bit applications. I could install the suite on my XP32 version of the same machine but I'd rather continue to use XP64 with CS3 than not having the stability and ability of running more applications simultaneously that I can with XP64.
    So yea, my living depends on my software working correctly too and PS CS3 will work just as well today as it worked before I installed CS4. It is just not worth it for me to spend thousands of dollars on a new PC just so that I have say that my computer is run under a supported OS. As we have seen here, a supported OS is not a guarantee that the software does not have bugs in it. This issue will not affect my ability to make a living. It is only a minor inconvenience that will undoubtedly be fixed in time.

  • Naming merged layers, Adjustment Issue

    I'm using PS CS5 for Mac.
    When I highlight and then merge 2 layers, the new layer takes the name of the top layer. Is there a way to have it take the name of the bottom of two layers?  For instance, if I put a Hue and Saturation Adjustment layer on a layer, I end up with my merged layer name "Hue and Saturation". 
    Also sometimes, when I'm working on a photo and click on the Create new fill or adjustment layer Icon and then choose an adjustment, the Mini Bridge panel opens up. It doesn't happen all the time but is very annoying when it does. Any ideas?
    Also, this is a general question, back in CS or CS2 I could right click on the gray bar above my photo and bring up a small list that included File Info. That feature was gone in CS4 and CS5. Is there a shortcut to get to that info?  Thanks in advance for your assistance.

    Thanks for the shortcut info.
    On the naming merged layers, I should have been more specific, I'm applying the adjustment just to a selection so I have the selection (on it's layer) selected, apply the adjustment, then when I select both layers and do a Ctrl+E to merge, it takes the name of the top layer. Maybe there's a newer way to do this and I'm just not thinking correctly.

  • Video Frames to Layers window issues

    hi
    im having this problem with the "File > Import > Video Frames to Layers" the box comes up like this:
    as you can see the box is white, the file i have imported if MP4 and iv tryed this with 2 files now, and get the smae thing, iv also tryed ans mov file the which dose show a preview but it still showd the black bar at the bottom and no time bar and such
    iv uninstalled the and reinstalled Photoshop and have the latest version of Quik time installed
    it's Photshop CS5 that im useing running on 64bit windows 8, i was priviously runing 32bit windows 8 and and this worked fine, then upgraded to 64bit and now this problem has occoured
    can some one help please

    I cannot import video files.
    Mylenium

  • Layers visibility issues

    The top three layers as shown have information completed but it seems that I must have turned off the visibilty in these layers yet they still display that the information is still there in the layers panel. And the work document is now in wireframe. I hope its not erased. Any ideas? Thanks for your time!!

    Hey Jacob,
    how are you doing my friend
    sharif's screenshot shows that the other layers are not in outline view. And regardless if they are or not Ctrl/Cmad + Y will toggle all on or off which is the fastest solution for sharif but my first reply was intended to help sharif with understanding the reason for the situation.
    edit: Oh, actually you could be right Jacob, they are nested layers

  • Adjustment layers playback issue

    With Fast Color Corrector on an adjustment layer above an image track there is blotchy playback. Part of the frames have the effect applied and others don't. I've tried other effects and similar results are evident.
    Suggestions?

    Hi Alex,
    Thanks for contacting adobe forums,
    need few information about the system ..
    What is the OS and version ?
    What is the Graphics Card installed on the system ?
    How much Ram do you have ?
    Do you use any external Hard Drive ?
    one more thing, if you are using mercury playback engine, try to use this on the software mode only
    Please let us if it works or not.
    Happy Editing,
    Sandeep

  • Export multiple images with random layers

    I have this texture file that has many different variations to it. (3 different kinds of pants, different hairpieces, some optional items, etc...)
    What i want to do, is export it with random layers selected. (there are also folders inside, it's fine if i have to merge the folder into a single layer, but it would be better if it could treat the folders as a layer)
    There are 2 layers that must always be on,
    then there are 6 other layers that can be mixed and matched completely at random.
    Finally: there are 3 layers that only one of them can be active at one time (if one is active, the other 2 cannot be). Those last 3 layers I wouldn't mind if i had to go through manually and remove the combinations that couldn't work, but it would be much better to have it automatic.
    Is there any way to script this so that it exports all of these textures as *filename*_*variation#*.png

    -the first 8 lines just make sure there is a valid document open, and if there is, find out the file path and everything
    Correct.
    But I cut corners, if I were more diligent I would also check for the existence of more than one layer and that the file has been saved at all (otherwise it has no path and an error occurs) etc.
    -line 14 just makes sure it outputs no more than 20 images (which i find odd. the texture files are extremely small ~6.82 kb each, so loading them won't be a problem. it would be good if it got stuck in an infinite loop)
    Feel free to change it to a higher number.
    To create 100 files change to
    for (var p = 1; p < 101; p++) {
    Why is thearray2 put in thearray, but then never used separately?
    The function RandomShow checks if the elements in the Array are Arrays themselves
    if (theObject.constructor != Array) {
    and just assumes it is a Layer if it is not an Array.
    But when it is an Array the function RandomShow is run with that Arrays elements as arguments.
    This is intended to enable the various rules – for example if you have two or more Layers of which only one may be visible you could put them in such an Array with minimal and maximal set to 1, which should only make one visible.
    But – and again I should have included checks for this – you should not put a Layer in more than one Array.
    In the example changing theArray2 to
    var theArray2 = [[theLayers[0], theLayers[1], theLayers[2]], 1, 1, "no"];
    would mean that 7, 8 and 9 would only be visible individually.
    But as theArray2 is itself part of theArray it may be visible or not unless it is set as the baseLayer.
    Or rather it would if I had not forget to check the baseLayer item for being an Array itself …
    So please change the affected if-clause (should be about line 34) to
    // show the baselayer;
    if (baseLayer.constructor == Number) {
              var theObject = theArray[baseLayer];
    // show baselayer if layer;
              if (theObject.constructor != Array) {
                        theObject.visible = true;
    // run function if baselayer is an array;
              else {
                        RandomShow (theObject[0], theObject[1], theObject[2], theObject[3])
              maximal--
    -baselayer is defined (but i can't find out where to input what it is, do i put it in place of the "no" on line 15?)
    The function takes four arguments,
    • the Array
    • the minimum number of visible elements
    • the maximum number of visible elements
    • a layer that should always be visible identified by its place in the Array
    So when invoking the function RandomShow and wanting the first layer in the Array to be visible it would be:
    RandomShow (theArray, 1, 5, 0);
    -for the layer array do I put in the actual layer names?
    If you want to address a layer with teh name »Layer 1« by name (top level layers that is, layers in Groups are filial to the Group) you can use
    myDocument.layers.getByName("Layer 1")
    -If I currently have layers hidden, how would i tel it to not add those to be randomly shuffled and made visible (it was randomizing the texturemap and the other layer that is there for future reference into the compiled pngs)
    Whether a Layer is visible or not is irrelevant in the curren tform of the Script, the Layers are addressed in the Array.
    Introducing a check for visibility would be possible, but make the function a bit more convoluted as this would also affect the maximum number for example.
    I don’t think I answered all questions, but maybe you’ve made progress on your own already and you can always post again if matters are still unclear.
    Maybe the function is more complicated than it would need to be or maybe it will not be able to accomodate all your needs currently, but one could for example extend the baseLayer argument to an Array itself to have more than one element (either Layer or another Array) that will always be visible … there are still possibilities but the issue might be a bit complicated.

  • Photoshop (CS4)-Saving out layers & names?

    I was wondering if someone can help me out.  I am trying create an action-script and can't seem to make it happen.  Specifically, I have a Photoshop file with five layers. Each layer having it's own name. Is there a way to save out each layer with that layers name? I tried to incorporate a copy and paste but didn't work.
    Any ideas how to do this?
    Thank you in advance!
    ~e

    Please try this...
    #target photoshop
    var doc = activeDocument;
    var oldPath = activeDocument.path;
    for(var a=0;a<doc.layerSets.length;a++){
    activeDocument.activeLayer = activeDocument.layers.getByName(doc.layerSets[a].name);
    dupLayers();
    var saveFile= File(oldPath +"/"+doc.layerSets[a].name +".jpg");
    SaveJPEG(saveFile,8);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    function dupLayers() {
        var desc143 = new ActionDescriptor();
            var ref73 = new ActionReference();
            ref73.putClass( charIDToTypeID('Dcmn') );
        desc143.putReference( charIDToTypeID('null'), ref73 );
        desc143.putString( charIDToTypeID('Nm  '), activeDocument.activeLayer.name );
            var ref74 = new ActionReference();
            ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
        desc143.putReference( charIDToTypeID('Usng'), ref74 );
        executeAction( charIDToTypeID('Mk  '), desc143, DialogModes.NO );
    function SaveJPEG(saveFile, jpegQuality){
    jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = jpegQuality; //1-12
    activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

  • Saving Adj. Layers In a Group

    Hello
    I am trying to create a sctipt that will save all of the adjustement layers in a group to a tiff. The group would always have the same name, somthing like "colors". I am hoping that one adj layer could be turned on, saved as a tif, the adj layer would be turned off and the next adj layer would be turned on, saved as a tif, and turned off then the next and the next etc. We would also need the name of the layer saved in the final tif file name.
    If anyone has anything like this or could please help me with this, I would greatly appreciat it.
    Thank you.

    You really should describe what you want more exactly right away.
    Could you give this a try:
    // thanks to xbytor for regexp;
    // 2012, use it at your own risk;
    #target photoshop
    if (app.documents.length > 0) {
    var myDoc = app.activeDocument;
    var docName = myDoc.name;
    try {var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    var docPath = myDoc.path}
    catch (e) {var basename = docName;
    var docPath = "~/Desktop"};
    // try to get set »colors« in »swatch worker«;
    try {
    var theSet = myDoc.layers.getByName("Swatch Worker").layers.getByName("colors");
    for (var n = 0; n < theSet.layers.length; n++) {
    theSet.layers[n].visible = false;
    // process;
    for (var m = 0; m < theSet.layers.length; m++) {
    var thisLayer = theSet.layers[m];
    thisLayer.visible = true;
    var layerName = thisLayer.name;
    while (layerName.indexOf("/") != -1) {layerName = layerName.replace("/", "_")};
    saveFlattenedTiff (myDoc, basename + "_" + layerName, docPath)
    thisLayer.visible = false;
    catch (e) {alert ("can’t locate folder")};
    ////// function to save the flattened tiff from copy //////
    function saveFlattenedTiff (myDoc, basename, docPath) {
    tifOpts = new TiffSaveOptions();
    tifOpts.embedColorProfile = true;
    tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
    tifOpts.alphaChannels = false;
    tifOpts.byteOrder = ByteOrder.MACOS;
    tifOpts.layers = false;
    myDoc.saveAs((new File(docPath+"/"+basename+".tif")),tifOpts,true)

  • Illustrator script to select multiple layers

    I have about 74 layers in illustrator and i want to run a script to select combination of layers at a time.
    For e.g. I want 5 layers to be selected and save them as one .jpg. Then say i need to select other 3 layers to save it as a seperate .jpg file. If i do it manually it comes upto 300,000 images.
    I can create a csv file with all layers to be selected presented in a row. I need help with the command to select 4 or more layers at a time, say if i have layer1, layer2, layer3, layer4 then a command to select those 4 layers and save them as a .jpg file.
    Any help will be greatly appreciated.
    Thanks
    H Patel
    CEO
    Data Entry India

    Create a csv or .text file ( i used "test.txt"  and place it at any location say C:\\)
    Enter the layer names to be exported in each row separated by ";"  like
    Layer 1;Layer 2
    Layer 4;Layer 5;Layer 7      // you can type in the names of as many layers you wanted to export in a single jpeg
    Open your main .Ai file in Illustrator and run the following script
    var count;
    count =1;
    var f = new File ("C:\\test.txt");
    f.open("r");
    while(!f.eof)
    c=f.readln();
    var arr = c.split(";");
    var len= arr.length;
    for(i=0;i<len;i++)
       lay= app.activeDocument.layers.getByName(arr[i]);
       lay.hasSelectedArtwork=true;
    app.copy();
    app.documents.add();   
    app.paste();
       var exportOptions = new ExportOptionsJPEG();
       var type = ExportType.JPEG
       var fileSpec = new File("c:\\"+count+".jpg");
        app.activeDocument.exportFile( fileSpec, type, exportOptions );
    app.activeDocument.close();
    for(i=0;i<len;i++)
        app.activeDocument.layers.getByName(arr[i]).hasSelectedArtwork=false;
    count ++;
    What this script is doing is
    it is reading a line from the .txt file (c:\\test.txt in this case)  and pushing the layers to be exported in an array
    then selecting the objects on the layers to be exported
    copying the selected contents
    pasting the contents on the new doc
    exporting as jpeg
    closing the doc
    deselecting the selected objects
    Hope this will solve your problem ...

  • Loop through all layers and sublayers

    is there a way that I can loop through all layers and sublayers looking for a name of a layer? I have one that loops through only top level layers. I am thinking I have to somehow incorperate all pathItems, groupItems and the like to incorperate all types of "layers" there might be, since a group is technically not a layer but a groupItem.
    this is what I am doing so far:
    for (var i = 0; i < numberOfLayers; i++) {
        var customName = "div structure";
        var myLayer = app.activeDocument.layers[i];
        var myLayer = myLayer.name;
        alert(myLayer);
        //alert (myLayer);
        if (customName == myLayer) {
            alert("layer matches");
        else { break; }
    any ideas?

    Sorry I don't understand what it is you are trying to achieve… Most collections offer a getByName() method if you know what you are looking for eg…
    doc.layers.getByName( 'fluff' );
    This should return you the first found or error so you need to try & catch when using this…

  • (NOT SOLVED) Duplicate layers into another document

    Hello, honorabe participants of Photoshop Scripting forum!
    I have a problem - how to implement in action/script duplication of two linked layers from one document to another already opened document? Linked layers is a specially formatted text, so I can't just copy-paste them into opened document. Already opened document is a CR2-file.
    When I record action, PS also record name of the reciever-document. But this name changes when I open another file so all acation breaks.
    PS can record 'Select next document' and 'Select previous document', but cant' record 'Duplicate layers into previous document'.
    Please, help me to solve my problem.

    Hi Borizzzed!,
    Try this.... one...!!!
    if ( app.documents.length >0 ) {
            var docRef = app.activeDocument
            var layerIndex = 0
            var visiblelayerCount = 0
            var activelayers = app.activeDocument.activelayers;
            var myLayers = docRef.layers;
            var selAlpha, Lname
            var Fname=prompt("Enter The file name with extension ...!","","Do Smart") // like temp1.jpg, yajiv.psd
            if (Fname!="")
            for (var layerIndex = visiblelayerCount; layerIndex < myLayers.length; layerIndex++) {
                selAlpha=docRef.layers.getByName(myLayers[layerIndex].name);
                Lname=myLayers[layerIndex].name; // Selected current layer name
                //alert(Lname);   
                DpLayer(Lname,Fname); // duplicate layer name to other Photoshop Document.
        function DpLayer(Lname,fname)
                var id766 = charIDToTypeID( "slct" );
                var desc45 = new ActionDescriptor();
                var id767 = charIDToTypeID( "null" );
                    var ref9 = new ActionReference();
                    var id768 = charIDToTypeID( "Lyr " );
                    ref9.putName( id768, Lname );
                desc45.putReference( id767, ref9 );
                var id769 = charIDToTypeID( "MkVs" );
                desc45.putBoolean( id769, false );
            executeAction( id766, desc45, DialogModes.NO );
            // =======================================================
            var id770 = charIDToTypeID( "Dplc" );
                var desc46 = new ActionDescriptor();
                var id771 = charIDToTypeID( "null" );
                    var ref10 = new ActionReference();
                    var id772 = charIDToTypeID( "Lyr " );
                    var id773 = charIDToTypeID( "Ordn" );
                    var id774 = charIDToTypeID( "Trgt" );
                    ref10.putEnumerated( id772, id773, id774 );
                desc46.putReference( id771, ref10 );
                var id775 = charIDToTypeID( "T   " );
                    var ref11 = new ActionReference();
                    var id776 = charIDToTypeID( "Dcmn" );
                    ref11.putName( id776, fname );
                desc46.putReference( id775, ref11 );
                var id777 = charIDToTypeID( "Vrsn" );
                desc46.putInteger( id777, 2 );
            executeAction( id770, desc46, DialogModes.NO );

  • How to create an action to insert hundreds of different numbers for limited edition prints?

    Hi,
    I sell limited edition prints of a run of between 350 and 500.
    I am trying to get it set up so that my signature and the print number is included as part of the print. Here is an example:
    You'll see at bottom left there is my signature and underneath is is the print number e.g. 110/350 (this is legible when printed at 18x12" size).
    Inserting the signature and the "/350" is easy since it only needs to be done once per image.
    The difficulty comes with inserting the actual print number e.g. "110"
    At the moment I have 0 to 9 written out and scanned in as separate numbers. So to make "110" I use the "1" digit twice, plus the "0" digit. I.e. I haven't written out 1 to 500 and scanned them in all as separate numbers, I've just done the 10 digits and use those 10 digits to make all the different numbers I need.
    Is there a way to create an action that will create say 350 JPEG copies of the original file, each one with its own unique print number inserted? (And ideally automatically saved with the print number as its file name!)
    Many thanks in advance

    This Script might be able to do some of what you wanted (the startNumber and endNumber would have to be set in the Script).
    It needs a Layer Group named »numbers« to contain layers for the numbers named »0«, »1«, …
    (script edited)
    // this script saves jpg copies with numbers created from number-layers in a layer group;
    // use it at your own risk;
    #target photoshop;
    if (app.documents.length > 0) {
    // define the numbers to create;
    var startNumber = 290;
    var endNumber = 310;
    // set to pixels;
    var originalRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    // get doc;
    var myDocument = app.activeDocument;
    // getting the name and location;
    var docName = myDocument.name;
    var baseName = docName.match(/(.*)\.[^\.]+$/)[1];
    //getting the location;
    var docPath = myDocument.path;
    // duplicate the image;
    var thecopy = myDocument.duplicate (thecopy, false);
    // jpg options;
    var jpgopts = new JPEGSaveOptions();
    jpgopts.embedProfile = true;
    jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgopts.matte = MatteType.NONE;
    jpgopts.quality = 9;
    // get number layers;
    var numberSet = thecopy.layers.getByName("numbers");
    // collect in an array;
    var theNumbers = [numberSet.layers.getByName("0"), numberSet.layers.getByName("1"), numberSet.layers.getByName("2"),
    numberSet.layers.getByName("3"), numberSet.layers.getByName("4"), numberSet.layers.getByName("5"),
    numberSet.layers.getByName("6"), numberSet.layers.getByName("7"), numberSet.layers.getByName("8"), numberSet.layers.getByName("9")];
    numberSet.visible = true;
    // proceed if all numbers have been found;
    if (theNumbers.length == 10) {
    // hide layers;
    for (var n = 0; n < numberSet.layers.length; n++) {
    numberSet.layers[n].visible = false
    var theState = thecopy.activeHistoryState;
    // process the numbers;
    for (var m = startNumber; m < endNumber + 1; m++) {
    // the position;
    var theHor = 500;
    // create an array for the new numbers;
    var theArray = new Array;
    // the number;
    var thisString = String(m);
    // duplicate layers to create the numbers;
    for (var o = 0; o < thisString.length; o++) {
    var theNumberLayer = theNumbers[Number(thisString[o])];
    // create copy;
    var theLayer = duplicateMoveRotateScale (theNumberLayer, theHor - Number(theNumberLayer.bounds[0]), 0, 100, 100, 0);
    theNumberLayer.visible = false;
    //alert (m+"_"+o+"\n"+theNumberLayer+"\n"+theLayer);
    // set the hor to edge of the new layer;
    var theHor = theLayer.bounds[2];
    theArray.push(theLayer);
    // get the number for the file name;
    var theNumber = bufferNumberWithZeros(m, String(endNumber).length);
    //save jpg;
    thecopy.saveAs((new File(docPath+"/"+baseName+"_"+theNumber+".jpg")),jpgopts,true);
    // remove copied layers;
    //for (var p = theArray.length - 1; p >= 0; p--) {theArray[p].remove()};
    thecopy.activeHistoryState = theState;
    // close copy;
    thecopy.close(SaveOptions.DONOTSAVECHANGES);
    // reset ruler;
    app.preferences.rulerUnits = originalRulerUnits
    //that’s it; thanks to xbytor;
    ////// buffer number with zeros //////
    function bufferNumberWithZeros (number, places) {
              var theNumberString = String(number);
              for (var o = 0; o < (places - String(number).length); o++) {
                        theNumberString = String("0" + theNumberString)
              return theNumberString
    ////// duplicate layer and move, rotate and scale it //////
    function duplicateMoveRotateScale (theLayer, theX, theY, theScaleX, theScaleY, theRotation) {
    app.activeDocument.activeLayer = theLayer;
    try{
    // =======================================================
    var idTrnf = charIDToTypeID( "Trnf" );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref6 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref6.putEnumerated( idLyr, idOrdn, idTrgt );
        desc10.putReference( idnull, ref6 );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc10.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc11 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc11.putUnitDouble( idHrzn, idPxl, theX );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc11.putUnitDouble( idVrtc, idPxl, theY );
        var idOfst = charIDToTypeID( "Ofst" );
        desc10.putObject( idOfst, idOfst, desc11 );
        var idWdth = charIDToTypeID( "Wdth" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc10.putUnitDouble( idWdth, idPrc, theScaleX );
        var idHght = charIDToTypeID( "Hght" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc10.putUnitDouble( idHght, idPrc, theScaleY );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc10.putUnitDouble( idAngl, idAng, theRotation );
        var idIntr = charIDToTypeID( "Intr" );
        var idIntp = charIDToTypeID( "Intp" );
        var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
        desc10.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
        var idCpy = charIDToTypeID( "Cpy " );
        desc10.putBoolean( idCpy, true );
    executeAction( idTrnf, desc10, DialogModes.NO );
    return app.activeDocument.activeLayer
    } catch (e) {}
    Edit: This Script just uses the layers’ horizontal bounds for orientation, so it does not address the issue I referred to earlier reagrding aesthetically pleasing spacing of the elements.

  • Move a Spot color to a layer

    I am very new to this, but am excited to unlock the power of scripting Adobe products. I have search through the forum for a similar issue but couldn't quite find the answer. This is my problem:
    I am trying to grab specific spot colors and move them to separate layers for our cutting software. In this case I am trying to grab "perimeter cut" and move it to a layer called "tc 1"
    I get the following error when I try to run the script.
    #target Illustrator
    var idoc = app.activeDocument;
    var ipath = idoc.pathItems;
        if (ipath.typename == "SpotColor") {
            if (ipath.spot.name == "perimeter cut") {
                        ipath.move(tc 1, ElementPlacement.PLACEATBEGINNING).

    Sure, try this alternative (sorry for not checking the previous script before posting):
    #target Illustrator
    var doc = app.activeDocument;
    var paths = doc.pathItems;
    var destLayer = doc.layers.getByName ("tc 1");
    var spotItems = new Array();
    for (var g=0; g<paths.length;g++){
        if (paths[g].fillColor.typename == "SpotColor" && paths[g].fillColor.spot.name == "perimeter cut") {
            spotItems.push(paths[g]);
    for (g=0; g<spotItems.length;g++){
         spotItems[g].move(destLayer, ElementPlacement.PLACEATBEGINNING);

  • How do I make a symbol from selection?

    I've got the below script, but it's not working. I'm trying to select all the art in the document on different layers, and create a symbol. So far I have the first part down, but can't figure out how to reference what is selected. actDoc.selection comes out as undefined. I've also tried to use "actDoc.PageItem.selected = true" and a few other variants, but I'm coming up empty. Anyone have recommendations for this?
    actDoc = app.activeDocument
    var layerCount = actDoc.layers.length;
    if(layerCount > 1) {
        for(i=0;i<layerCount;i++) {
        actDoc.layers[i].hasSelectedArtwork = true // selects all layers
       actDoc.symbols.add(actDoc.selection); // <---------- Here's where the error is thrown

    Thanks! That makes sense! Now I'd like to put a layer with sublayers into a symbol to maintain any effects that are on the sub layers. I have an action that runs, that does this with nested layers like this. I used to just let it group everything, but then found some effects were falling off. I tried the below, but it didn't work, and states that it's an illegal argument. Is there any way to acheive this?
                            layer = actDoc.layers.getByName('Editorial'); //get a reference to the newly created raster item 
                            newsymbol = actDoc.symbols.add(layer); //add the raster item to the symbols  

Maybe you are looking for

  • Data entry in the table

    Hi All, I havae a scenario.. I have one ztable with the foloowing fields: 1. enum 2. Ecnum 3. Add 4. Date 5. erole what I did is I made enum and ecnum fields as the key fields in the table and rest I didn't make as key fields. Now when I tried to ent

  • Pkgcheck - Check your PKGBUILDs for upstream releases

    Hey, I wrote a small Python script which checks my PKGBUILD repository (usually several directories, one for every package containing the PKGBUILD) for upstream releases. One could use it like this: It parses the PKGBUILDs and compares their versions

  • Finding the avg value of the KF

    Hi experts, i have a KeyFigure called vehicles. and the records look something like this: Model yr   vehicle name  part#  #vehicles  KF1 KF2 2005        xyz          abc        100     1   2 2005        xyz          123        100     3  4 2005      

  • CS4 premiere Imported .avi files play too fast

    Hi Guys I have a problem. I'm new to CS4 having used Adobe Premiere 6.0 in the past and I have never had this issue when importing .AVI files. What happens is that the file play fine in my windows enviroment and on all my players VLC,DIVX, Windows me

  • Low Signal Strneght after installing 6.0.2 update

    Hi, I am recieving low signal strneght after installing 6.0.2 update.Any fixes ? or anybody