24 Replies Latest reply: Mar 19, 2014 12:12 PM by StrongBeaver RSS

    Duplicate Error

    StrongBeaver Community Member

      var doc = app.activeDocument

      var group = Layer.duplicate

      group.mergeVisibleLayers();

       

       

      What am I doing wrong, that the layers are not duplicating, then merging ?

        • 1. Re: Duplicate Error
          c.pfaffenbichler Community Member

          What makes you think »Layer« means something useable in this line?

          var group = Layer.duplicate

          In the three lines you have not defined which Layer is to be duplicated.

           

          And what about this?

          group.mergeVisibleLayers();

          »mergeVisibleLayers« is a method of Document, not LayerSet or Layer.

           

          Please start using the documentation, like ESTK’s Object Model Viewer, to verify if a Method or Property exists for the object you want to manipulate.

          • 2. Re: Duplicate Error
            StrongBeaver Community Member

            Layer.duplicate is in the Ps OMV List.  I'm not selecting all the visible layers, I assume ?

            • 3. Re: Duplicate Error
              c.pfaffenbichler Community Member

              »Layer« is a Class.

              So withing the Script »Layer« is basically no more informative than if someone were to tell you: »Noun is running.«

              You need to define which Layer it is that is to be duplicated (or whatever else).

              (edited)

              • 4. Re: Duplicate Error
                StrongBeaver Community Member

                I want all visible layers duplicated, while at the time time remain selected.  How do you know Layer is a class is it specified in the Ps OMV ?

                • 6. Re: Duplicate Error
                  JJMack Community Member

                  StrongBeaver wrote:

                   

                  I want all visible layers duplicated, while at the time time remain selected.  How do you know Layer is a class is it specified in the Ps OMV ?

                  In Photoshop you can stamp a composite of all visible layer into a new layer and that layer will be the current Photoshop target. There is a shortcut for this feature Shift+Alt+Ctrl+E. This feature does not always work it depends on the current Photoshop  target. Where the layer goes in the layer stack also depends on Photoshop current target. So I always add a new empty layer and move it to the top of the stack. Then use the short cut the stamp visible winds up in the layer I added and is the current target. I do this in many of my Photshop Actions. Stamp visible layers are great for many things. I do not understand what you mean by selected?  I don't understand many of your questions.

                   

                  If you want a script you can always use the Action Manager code for Shift+Alt+Ctrl+E

                   

                   

                  // =======================================================

                  var idMrgV = charIDToTypeID( "MrgV" );

                      var desc40 = new ActionDescriptor();

                      var idDplc = charIDToTypeID( "Dplc" );

                      desc40.putBoolean( idDplc, true );

                  executeAction( idMrgV, desc40, DialogModes.NO );

                  • 7. Re: Duplicate Error
                    StrongBeaver Community Member

                    ArtLayers.add (): ArtLayer

                    Adobe Photoshop CS5 Object Library

                    Adds an element.

                    If I want to add an artLayer to the document, instead of merging visible layers. The ArtLayers.add is an object, correct ?

                     

                     

                    var doc = app.activeDocument

                    doc.ArtLayers.add()

                     

                    The code above should add an ArtLayer, that is if it's an object.

                    • 8. Re: Duplicate Error
                      c.pfaffenbichler Community Member

                      But in this case it’s not written with a capitalized »A«.

                      • 9. Re: Duplicate Error
                        JJMack Community Member

                        StrongBeaver wrote:

                         

                        var doc = app.activeDocument

                        doc.ArtLayers.add()

                         

                         

                        var doc = app.activeDocument

                        var visible_layers = doc.artLayers.add()  //add new empty layer

                        • 10. Re: Duplicate Error
                          StrongBeaver Community Member

                          I'm not getting the order correct. Hrm !

                          • 11. Re: Duplicate Error
                            JJMack Community Member

                            What order?

                            • 12. Re: Duplicate Error
                              c.pfaffenbichler Community Member

                              Maybe you should, instead of trying to verbalize what you are after, show it with a mock-up/screenshots.

                              • 13. Re: Duplicate Error
                                StrongBeaver Community Member

                                The order of how to lay down the code without getting errors look at this code.

                                 

                                var note = prompt("hello");

                                var doc = app.activeDocument

                                var visible_layers = doc.artLayers.add()  //add new empty layer

                                visible_layers.backgroundColor();

                                I want to add a background color the current layer.  From my understanding after reading some of the docs yesterday I have to reference the active.Document ?

                                 

                                My main goal is a script that merges all visible layers into a smart object

                                • 14. Re: Duplicate Error
                                  c.pfaffenbichler Community Member

                                  Have you even bothered to check »backgroundColor« in the OMV?

                                  Is it a Method or a Property?

                                  And of what?

                                  • 15. Re: Duplicate Error
                                    StrongBeaver Community Member

                                    Of course I checked, why do you assume I didn't just because I don't write what I did in each mesage ?

                                     

                                    Application.backgroundColor  

                                    Data Type: SolidColor

                                    Adobe Photoshop CS5 Object Library

                                    The default background color (used to paint, fill, and stroke selections).

                                    • 16. Re: Duplicate Error
                                      JJMack Community Member

                                      You know the two color swatches the can be changed in the tools palette. foregroundColor and backgroundColor!..

                                      /* ======================================================================================
                                      // 2009  John J. McAssey (JJMack)  http://www.mouseprints.net/
                                      //  
                                      // This script is supplied as is. It is provided as freeware. 
                                      // The author accepts no liability for any problems arising from its use.
                                      //
                                      // This script is designed to be used by a Photoshop Action twice
                                      // A good pratice to use when creating an actions that use this scipt is for the action 
                                      // not to do a save or play some other action between its two useages of this Script.
                                      // 
                                      // The first time this script is used by an action Photoshops Current Forground 
                                      // and Background Colors are saved into the document's meta-data Info Instructions field.
                                      //
                                      // The second time this script used by the action the script retreives what was
                                      // saved in the meta-data during the first usage and these colors are set.
                                      // and the saved data is removed from the document's meta-data Info Instructions field.
                                      //
                                      // ===================================================================================== */
                                      
                                      
                                      /*
                                      <javascriptresource>
                                      <about>$$$/JavaScripts/SaveAndRestoreColors/About=JJMack's SaveAndRestoreColors.^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^rNOTE:Don't play other actions between runs!^r^rFirst Run records Photoshops foreground and background swatch colors.^rSecond Run restores the recorded colors and removes the recording.</about>
                                      <category>JJMack's Action Run Twice Utility</category>
                                      </javascriptresource>
                                      */
                                      
                                      
                                      if (app.documents.length > 0) { 
                                                if (app.activeDocument.info.instructions.indexOf("<Colorf>") == -1 ){ // no footprint fisrt useage 
                                                          //alert("first");
                                                          // Retreive Document information for Foot Print 
                                                          saveforeColor = new SolidColor;
                                                          saveforeColor.rgb.red = app.foregroundColor.rgb.red;
                                                          saveforeColor.rgb.green = app.foregroundColor.rgb.green;
                                                          saveforeColor.rgb.blue = app.foregroundColor.rgb.blue;
                                      
                                      
                                                          savebackColor = new SolidColor;
                                                          savebackColor.rgb.red = app.backgroundColor.rgb.red;
                                                          savebackColor.rgb.green = app.backgroundColor.rgb.green;
                                                          savebackColor.rgb.blue = app.backgroundColor.rgb.blue;
                                                     
                                      
                                      
                                                          // put footprint in metadata info instructions
                                      
                                      
                                                          app.activeDocument.info.instructions = app.activeDocument.info.instructions + "<Colorf>" + saveforeColor.rgb.red + "," + saveforeColor.rgb.green + "," + saveforeColor.rgb.blue + "</Colorf>" + "<Colorb>" + savebackColor.rgb.red + "," + savebackColor.rgb.green + "," + savebackColor.rgb.blue + "</Colorb>"; 
                                                          //alert( "Saved ="  + "<Colorf>" + saveforeColor.rgb.red + "," + saveforeColor.rgb.green + "," + saveforeColor.rgb.blue + "</Colorf>" + "<Colorb>" + savebackColor.rgb.red + "," + savebackColor.rgb.green + "," + savebackColor.rgb.blue + "</Colorb>"); 
                                      
                                      
                                      
                                      
                                                } 
                                                else { 
                                                          //alert("second");
                                      
                                      
                                                          // Retreive saved information
                                                          colorfOffset = app.activeDocument.info.instructions.indexOf("<Colorf>") + "<Colorf>".length;
                                                          colorfLength = app.activeDocument.info.instructions.indexOf("</Colorf") -colorfOffset; 
                                                          saveforeColor = app.activeDocument.info.instructions.substr(colorfOffset, colorfLength);
                                      
                                      
                                                          colorbOffset = app.activeDocument.info.instructions.indexOf("<Colorb>") + "<Colorb>".length;
                                                          colorbLength = app.activeDocument.info.instructions.indexOf("</Colorb") -colorbOffset;
                                                          savebackColor = app.activeDocument.info.instructions.substr(colorbOffset, colorbLength);
                                      
                                      
                                                          //alert("Colorf = " + saveforeColor + " Colorb = " + savebackColor );
                                      
                                      
                                                          // Restore Colors
                                      
                                      
                                                          app.foregroundColor.rgb.red = saveforeColor.substr(0,saveforeColor.indexOf(",")); 
                                                          saveforeColor = saveforeColor.substr(saveforeColor.indexOf(",") + 1,saveforeColor.length); 
                                                          app.foregroundColor.rgb.green = saveforeColor.substr(0,saveforeColor.indexOf(","));
                                                          saveforeColor = saveforeColor.substr(saveforeColor.indexOf(",") + 1,saveforeColor.length);
                                                          app.foregroundColor.rgb.blue = saveforeColor ;
                                      
                                      
                                                          app.backgroundColor.rgb.red = savebackColor.substr(0,savebackColor.indexOf(","));
                                                          savebackColor = savebackColor.substr((savebackColor.indexOf(",") + 1),savebackColor.length); 
                                                          app.backgroundColor.rgb.green = savebackColor.substr(0,savebackColor.indexOf(","));
                                                          savebackColor = savebackColor.substr(savebackColor.indexOf(",") + 1,savebackColor.length);
                                                          app.backgroundColor.rgb.blue = savebackColor ;
                                      
                                      
                                      
                                      
                                                          // Remove footprint from metadata info instructions
                                                          before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexOf("<Colorf>"));
                                                          afterOffset = app.activeDocument.info.instructions.indexOf("</Colorb>") + "</Colorb>".length;
                                                          after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);
                                                          //alert ("before = " + before + " after = " + after);
                                                          app.activeDocument.info.instructions = before + after;
                                                } 
                                      } 
                                      else { alert("You must have at least one open document to run this script!"); } 
                                      
                                      
                                      • 17. Re: Duplicate Error
                                        JJMack Community Member

                                        Does this help

                                         

                                         

                                        var doc = app.activeDocument;

                                        var new_layer = doc.artLayers.add();  //add new empty layer

                                        app.activeDocument.selection.selectAll();

                                        app.activeDocument.selection.fill(app.backgroundColor);

                                        new_layer.name="Background Color";

                                         

                                         

                                        But I think you want this

                                         

                                        var doc = app.activeDocument;

                                        var visible_layers = doc.artLayers.add();  //add new empty top layer

                                        visible_layers.name="Stamp Visible Layers";

                                          // = Stamp Visible Layers Shift+Ctrl+Alt+E Scriptlisener Code =

                                        var idMrgV = charIDToTypeID( "MrgV" );

                                            var desc15 = new ActionDescriptor();

                                            var idDplc = charIDToTypeID( "Dplc" );

                                            desc15.putBoolean( idDplc, true );

                                        executeAction( idMrgV, desc15, DialogModes.NO );

                                        • 18. Re: Duplicate Error
                                          c.pfaffenbichler Community Member
                                          Of course I checked, why do you assume I didn't just because I don't write what I did in each mesage ?

                                           

                                          Because of the way you use the items in your code.

                                           

                                          visible_layers.backgroundColor();

                                           

                                          »visible_layers« is a Layer and Layer does not have BackgroundColor, Application does.

                                          And BackgroundColor is a Property, not a Method, so what are the brackets supposed to achieve?

                                          • 19. Re: Duplicate Error
                                            JJMack Community Member

                                            StrongBeaver wrote:

                                             

                                            Of course I checked, why do you assume I didn't just because I don't write what I did in each mesage ?

                                             

                                            Humans normally learn from their mistakes.  However for them to do this they need to learn how to recognize that what the did  or realize what they think they  know is not correct.  You seem to have a problem with this.    Your a novice and your knowledge is not improving because of that.   Scripting requires knowledge and logic.  You lack basic knowledge about many things. 

                                             

                                            Photoshop also has a less powerful automation feature that uses the Action palette.  Actions are easy to record debug and edit. I suggest that you stop trying to learn scriping for now and switch for the time being to Actions. 

                                             

                                            Using actions you may learn how Photoshop does thing. How Photoshop works.  You will be able to use Photoshop better with this knowledge.  Though actions are easy to record. Recording well behaved actions that will work on just about all Photoshop documents. Requires you to know how Photoshop works, Know the limits of Actions and to able to design around these limits. Unlike scripting Actions can not use logic. They can not find out things about the document they are working on and act accordingly.  Actions need to be design to work in a way that what they do would be correct for any document.  Many actions fails because they have dependencies that some documents fail to meet.  Well Crafted actions require knowledge and planing. Most Actions I have download from the web have problems few are what I classify as well crafted actions.

                                             

                                            • 20. Re: Duplicate Error
                                              StrongBeaver Community Member

                                              Humans normally learn from their mistakes.  However for them to do this they need to learn how to recognize that what the did  or realize what they think they  know is not correct.  You seem to have a problem with this.    Your a novice and your knowledge is not improving because of that.   Scripting requires knowledge and logic.  You lack basic knowledge about many things. 

                                              How you come to the conclusion that my knowledge is not improving over a few questions, let alone "many things" that I'll never understand, you do contain the skill of belittling. There is an olde saying you should be familiar with considering your age; if you don't have anything nice to say don't say nothing at all and clearly some of the statments in your comments warrent this. Please don't tell me what I should and should not learn. I suppose you you tell people whether they should have a licence and belittle them if you witness them doing a wrong turn and that they should just take public transit.

                                               

                                              I understand help is a bi-directional path, you clearly cannot help; you can belittle, that I'll give you credit for, but it's not a skill I'd be proud of.

                                              • 21. Re: Duplicate Error
                                                c.pfaffenbichler Community Member

                                                How you come to the conclusion that my knowledge is not improving over a few questions

                                                You seem to have frequented this Forum for several years now and have started a couple of threads, so are the observations JJMack could have based his assessment on really that few?

                                                 

                                                The mistakes and disregard for the proper syntax in your recent Scripting seem to indicate that you have so far not strongly familiarized yourself with basic Photoshop/JavaScript Scripting concepts.

                                                 

                                                I think over the years many attempts have been made to help you with various Scripting issues; if you are willing to receive help I think you should also be ready to take criticism at times.

                                                • 22. Re: Duplicate Error
                                                  StrongBeaver Community Member

                                                  Once again, we all learn, stumbling along the way is nothing uncommon, you both should know that.  JJMack doesn't help he makes assumptions and belittles about ones own life, that is taking things a bit far. There is criticism and constructive crticism I think JJMack is bluring the lines between the two, you yourself haven't been the best at it either. 

                                                   

                                                  Lets just end things here !

                                                  • 23. Re: Duplicate Error
                                                    JJMack Community Member

                                                    You ask for help yet act like a child that know it all. That you don't really need the help your asking for. No one here is trying to belittle you.  We try to help you and make suggestion we think will help you learn. IMO you fail to understand many things posted here meant to help you. Instead your offended by what you read. 

                                                     

                                                    I feel that actions are a great learning  tool.  If you download actions and read them.  You will see how users use Photoshop to do things.  Action are nothing more then Photoshop step by step procedures to do some sort of processing one often does in Photoshop. 

                                                     

                                                    Photoshop ships with many Photoshop scripts and actions and many others can be downloaded from the web. Reading Photoshop scripts is harder then reading Actions for they contain logic and some of the syntax the is not all that readable. Still you can learn much from looking at others code.

                                                     

                                                    I just hack at Photoshop Scripting for I don't know javascript.  However I can search and find out how to do thing that I don't know how to do. For I realize what I don't know.  Using resources available on the web I can search for solution for what I want to do. I would rather do that then try to verbalize my problem for I do not do that well.

                                                     

                                                    Yes we all learn in our own way.  I think you can learn and that you should first address learning to automate Photoshop using Photoshop action feature for its easier to learn and do the scripting. IMO you should stop tackling scripting for you have been doing that for some time now and do not seem to be making much progress from what I observe from your appends here.    I'm not trying to belittle you I trying to give you some guidance I feel will help.  

                                                    • 24. Re: Duplicate Error
                                                      StrongBeaver Community Member

                                                      I never said once, I know it all, that is your perception.  No one knows it all.  You are referencing messages from a long time ago, at that stage yes, I didn't know exactly what I was doing, ignoring the past and speaking of the present.  I know how actions work as well as conditional actions. I will continue to work the way I have even if it's unconventional.