2 Replies Latest reply on Mar 24, 2015 3:08 AM by c.pfaffenbichler

    How can I reference a custom shape's name?

    RamoCole

      When you create a custom shape you are allowed to give that custom shape a name. I want to create a script that alerts a custom shape's name. How can I therefore store a custom shapes name in a variable or in any way reference this name?


      The intended procedure is to reference the custom shape name so I can manipulate it upon creation of said custom shape.

      I activated script listener and I can see that when I create a custom shape that is named scissors 2 the log file records this code in relation with the name:

       

          var desc41 = new ActionDescriptor();

          var idNm = charIDToTypeID( "Nm  " );

           desc41.putString( idNm, """Scissors 2""" );

      ===============================================================================

       

      This other, is all the code that is created in the log file when I create a custom shape:

       

      var idslct = charIDToTypeID( "slct" );

          var desc36 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref14 = new ActionReference();

              var idcustomShapeTool = stringIDToTypeID( "customShapeTool" );

              ref14.putClass( idcustomShapeTool );

          desc36.putReference( idnull, ref14 );

          var iddontRecord = stringIDToTypeID( "dontRecord" );

          desc36.putBoolean( iddontRecord, true );

          var idforceNotify = stringIDToTypeID( "forceNotify" );

          desc36.putBoolean( idforceNotify, true );

      executeAction( idslct, desc36, DialogModes.NO );

       

       

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

      var idMk = charIDToTypeID( "Mk  " );

          var desc37 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref15 = new ActionReference();

              var idcontentLayer = stringIDToTypeID( "contentLayer" );

              ref15.putClass( idcontentLayer );

          desc37.putReference( idnull, ref15 );

          var idUsng = charIDToTypeID( "Usng" );

              var desc38 = new ActionDescriptor();

              var idType = charIDToTypeID( "Type" );

                  var desc39 = new ActionDescriptor();

                  var idClr = charIDToTypeID( "Clr " );

                      var desc40 = new ActionDescriptor();

                      var idRd = charIDToTypeID( "Rd  " );

                      desc40.putDouble( idRd, 0.000000 );

                      var idGrn = charIDToTypeID( "Grn " );

                      desc40.putDouble( idGrn, 0.000000 );

                      var idBl = charIDToTypeID( "Bl  " );

                      desc40.putDouble( idBl, 0.000000 );

                  var idRGBC = charIDToTypeID( "RGBC" );

                  desc39.putObject( idClr, idRGBC, desc40 );

              var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

              desc38.putObject( idType, idsolidColorLayer, desc39 );

              var idShp = charIDToTypeID( "Shp " );

                  var desc41 = new ActionDescriptor();

                  var idNm = charIDToTypeID( "Nm  " );

                  desc41.putString( idNm, """Scissors 2""" );

                  var idTop = charIDToTypeID( "Top " );

                  var idRlt = charIDToTypeID( "#Rlt" );

                  desc41.putUnitDouble( idTop, idRlt, 89.000019 );

                  var idLeft = charIDToTypeID( "Left" );

                  var idRlt = charIDToTypeID( "#Rlt" );

                  desc41.putUnitDouble( idLeft, idRlt, 232.000049 );

                  var idBtom = charIDToTypeID( "Btom" );

                  var idRlt = charIDToTypeID( "#Rlt" );

                  desc41.putUnitDouble( idBtom, idRlt, 131.000028 );

                  var idRght = charIDToTypeID( "Rght" );

                  var idRlt = charIDToTypeID( "#Rlt" );

                  desc41.putUnitDouble( idRght, idRlt, 293.000062 );

              var idcustomShape = stringIDToTypeID( "customShape" );

              desc38.putObject( idShp, idcustomShape, desc41 );

          var idcontentLayer = stringIDToTypeID( "contentLayer" );

          desc37.putObject( idUsng, idcontentLayer, desc38 );

      executeAction( idMk, desc37, DialogModes.NO );

       

       

      --------------------------------------------------

      Thanks & hope you can help

        • 1. Re: How can I reference a custom shape's name?
          JJMack Most Valuable Participant

          The problem I had when defining custom shapes had more to do with deleting defined custom shapes.  While it was easy to define a custom shape and name it.  The name does not have to be unique.  So if a shape was already defined with the name when yow went to add a shape with the  name you just defined you would add the other shape.   Shaped are deleted by an index into the defined  shapes the users has loaded not by name.  I also did not want to delete a shaped I did not define.  So I added a timestamp suffix to the shape names I defined to make the unique. So I could use the name I defined this run.    This is good and bad If you define X you actually define XTimestamp so every time you define X you define the next version of X.  Is useable but users does not know the version name they can select  last X in the pull-down menu and the can delete prior X in in the pull-down menu.   Its not a problem if you only define one X for you select the shape from the icon in the pull-down menu no by name.

           

          Here is a link the the script I wrote that uses a stand alone application to trace a black and white  grayscale image into a Black and transparent file which I select its transparency and define a custom shape and I add a shape layer over the original black and white grayscale image for comparison.

          http://www.mouseprints.net/old/dpr/potrace.jsx

           

          Photoshop Script  Black and White Raster to Vector

          • 2. Re: How can I reference a custom shape's name?
            c.pfaffenbichler Level 9

            I’m still not sure what you are trying to achieve ultimately …

            // create custom shape and alert chosen name;

            // 2015, use it at your own risk;

            #target photoshop

            if (app.documents.length > 0) {

            alert (customShape ())

            };

            function customShape () {

            try {

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

            var idMk = charIDToTypeID( "Mk  " );

                var desc4 = new ActionDescriptor();

                var idnull = charIDToTypeID( "null" );

                    var ref2 = new ActionReference();

                    var idcustomShape = stringIDToTypeID( "customShape" );

                    ref2.putClass( idcustomShape );

                desc4.putReference( idnull, ref2 );

                var idUsng = charIDToTypeID( "Usng" );

                    var ref3 = new ActionReference();

                    var idPrpr = charIDToTypeID( "Prpr" );

                    var idfsel = charIDToTypeID( "fsel" );

                    ref3.putProperty( idPrpr, idfsel );

                    var idDcmn = charIDToTypeID( "Dcmn" );

                    var idOrdn = charIDToTypeID( "Ordn" );

                    var idTrgt = charIDToTypeID( "Trgt" );

                    ref3.putEnumerated( idDcmn, idOrdn, idTrgt );

                desc4.putReference( idUsng, ref3 );

                var idNm = charIDToTypeID( "Nm  " );

                desc4.putString( idNm, "x1" );

            var aaa = executeAction( idMk, desc4, DialogModes.ALL );

            // evaluate name;

            var theName = aaa.getString (charIDToTypeID( "Nm  " ));

            return theName

            } catch (e) {}

            };