3 Replies Latest reply on Aug 3, 2011 6:04 AM by Paul Riggott

    Create Layer Mask from csv

    mselbach2 Level 1

      Hi,

       

      I want to create a layer mask via extendscript. I have a csv file with all the x,y coordinates and a radius value. For each coordinate I want to draw an black spot onto a layer mask. But unfortunatly the brush tool seems not to be scriptable (neither DOM nor ScriptingListener). The only solution I found is combining several circular selections into one big and fill it black. This works good but takes quite long (several minutes!!!).

       

      Any ideas how to efficiently create layermasks via script?

       

      Regards,

      Markus

        • 1. Re: Create Layer Mask from csv
          JJMack Most Valuable Participant

          Do you have to use the csv file. How was it created.  Could you create a path instead these could be made into a custom shape or into a grayscale image file these could be used in Actions and scripts and used to make a mask.

           

          What part of your script is taking a long time. Putting some alerts in you script may help you find where the time is being spent.  If its one section try to reduce the path length or figure a different way to do that part.

          • 2. Re: Create Layer Mask from csv
            mselbach2 Level 1

            The heavy part is adding thousands of little circular selections. I use the following scripting listener code for placing a single dot:

             

                var idsetd = charIDToTypeID( "AddT" );

                    var desc86 = new ActionDescriptor();

                    var idnull = charIDToTypeID( "null" );

                        var ref44 = new ActionReference();

                        var idChnl = charIDToTypeID( "Chnl" );

                        var idfsel = charIDToTypeID( "fsel" );

                        ref44.putProperty( idChnl, idfsel );

                    desc86.putReference( idnull, ref44 );

                    var idT = charIDToTypeID( "T   " );

                        var desc87 = new ActionDescriptor();

                        var idTop = charIDToTypeID( "Top " );

                        var idPxl = charIDToTypeID( "#Pxl" );

                        desc87.putUnitDouble( idTop, idPxl, top);

                        var idLeft = charIDToTypeID( "Left" );

                        var idPxl = charIDToTypeID( "#Pxl" );

                        desc87.putUnitDouble( idLeft, idPxl, left);

                        var idBtom = charIDToTypeID( "Btom" );

                        var idPxl = charIDToTypeID( "#Pxl" );

                        desc87.putUnitDouble( idBtom, idPxl, bottom);

                        var idRght = charIDToTypeID( "Rght" );

                        var idPxl = charIDToTypeID( "#Pxl" );

                        desc87.putUnitDouble( idRght, idPxl, right);

                    var idElps = charIDToTypeID( "Elps" );

                    desc86.putObject( idT, idElps, desc87 );

                    var idFthr = charIDToTypeID( "Fthr" );

                    var idPxl = charIDToTypeID( "#Pxl" );

                    desc86.putUnitDouble( idFthr, idPxl,smooth);

                    var idAntA = charIDToTypeID( "AntA" );

                    desc86.putBoolean( idAntA, true );

                executeAction( idsetd, desc86, DialogModes.ALL );

             

             

            Unfortunally the masks allready exist in csv files (they were generated from a very old custom software) and need to be reapplied.

             

            Regards,

            markus

            • 3. Re: Create Layer Mask from csv
              Paul Riggott Level 6

              Performance might be dependant on how you are reading the csv file. It should be quicker if you read the whole file in rather than line by line.

              I am not sure which would be faster created the dots/circles how you are doing or by creating a path then adding to it, then do the selection and fill.

              You could try the following functions and see if there is a difference in performance?

               

              // Use this function for the first circle only
              addPathCircle(20,500,300);
              // Use this function for subsequent circles
              addToPathCircle(1900,1520,50);
              var doc = activeDocument;
              //Get work path
              var workPath = doc.pathItems.getByName("Work Path");
              //Select work path
              workPath.makeSelection();
              workPath.remove();
              var Colour = new SolidColor;
              Colour.rgb.hexValue = '000000'; 
              doc.selection.fill(Colour);
              doc.selection.deselect();
              
              function addPathCircle(X,Y,Radius) {
                  var desc13 = new ActionDescriptor();
                      var ref9 = new ActionReference();
                      ref9.putProperty( charIDToTypeID('Path'), charIDToTypeID('WrPt') );
                  desc13.putReference( charIDToTypeID('null'), ref9 );
                      var desc14 = new ActionDescriptor();
                      desc14.putString( charIDToTypeID('Nm  '), "Circle" );
                      desc14.putUnitDouble( charIDToTypeID('Top '), charIDToTypeID('#Pxl'), Y );
                      desc14.putUnitDouble( charIDToTypeID('Left'), charIDToTypeID('#Pxl'), X);
                      desc14.putUnitDouble( charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), (Y+Radius) );
                      desc14.putUnitDouble( charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), (X+Radius) );
                  desc13.putObject( charIDToTypeID('T   '), stringIDToTypeID('customShape'), desc14 );
                  executeAction( charIDToTypeID('setd'), desc13, DialogModes.NO );
              };
              function addToPathCircle(X,Y,Radius) {
                  var desc16 = new ActionDescriptor();
                      var ref10 = new ActionReference();
                      ref10.putEnumerated( charIDToTypeID('Path'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                  desc16.putReference( charIDToTypeID('null'), ref10 );
                      var desc17 = new ActionDescriptor();
                      desc17.putString( charIDToTypeID('Nm  '), "Circle" );
                      desc17.putUnitDouble( charIDToTypeID('Top '), charIDToTypeID('#Pxl'), Y );
                      desc17.putUnitDouble( charIDToTypeID('Left'), charIDToTypeID('#Pxl'), X );
                      desc17.putUnitDouble( charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), (Y+Radius) );
                      desc17.putUnitDouble( charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), (X+Radius) );
                  desc16.putObject( charIDToTypeID('T   '), stringIDToTypeID('customShape'), desc17 );
                  executeAction( charIDToTypeID('AddT'), desc16, DialogModes.NO );
              };