2 Replies Latest reply on Mar 6, 2014 4:41 AM by oddgames

    Why doesn't this code work in my extension? Retrieving generator settings from meta data

    oddgames Level 1

      Using the code below in my host.jsx file within my html 5 extension this code doesnt work:

       

      $._photoshop.setDocumentData('project.isXUI','true');

      alert($._photoshop.getDocumentData('project.isXUI'));

       

       

      Here's the error I get:

       

      Error: The requested property does not exist.

       

       

      It works perfectly from ExtendScript but the same lines of code do not work when called via "window.__adobe_cep__.evalScript". What am I missing?

       

       

       

      $._photoshop = {

       

       

      setDocumentData: function(key,value)

          {

       

       

              try

              {

       

                  var classProperty = charIDToTypeID('Prpr');

                  var propNull = charIDToTypeID( 'null' );

                  var classNull = charIDToTypeID( 'null' );

                  var typeOrdinal = charIDToTypeID('Ordn');

                  var enumTarget = charIDToTypeID('Trgt');

                  var classDocument = charIDToTypeID('Dcmn');

                  var classLayer = charIDToTypeID('Lyr ');

                  var propProperty = stringIDToTypeID("property");

                  var propGeneratorSettings = stringIDToTypeID("generatorSettings");

                  var propProperty = stringIDToTypeID(key); //unique name for the setting

       

       

                  var keyTo = charIDToTypeID( 'T   ' );

                  var actionSet = charIDToTypeID( "setd" );

       

       

                  //Make a property reference to generator settings for active layer.

                  //(use classDocument for the active document)

                  //NOTE: putProperty needs to come before putEnumerated

       

       

                  var theRef = new ActionReference();

                  theRef.putProperty(classProperty, propGeneratorSettings );

                  theRef.putEnumerated(classDocument, typeOrdinal, enumTarget);

       

       

                  //Build descriptor for your plugin settings, with 2 example settings, a boolean and a string

       

       

                  var mySettingsDesc = new ActionDescriptor();

                  mySettingsDesc.putString(propProperty,value);

       

       

                  //Execute the set action, setting the descriptor into the property reference,

                  //setting just the plugin's settings (propProperty == strMySettings)

       

       

                  var setDescriptor = new ActionDescriptor();

                  setDescriptor.putReference(propNull,theRef);

                  setDescriptor.putObject(keyTo,classNull,mySettingsDesc);

                  setDescriptor.putString(propProperty, "au.com.oddgames.xui");

                  executeAction( actionSet, setDescriptor, DialogModes.NO );

       

                  return true;

       

              }

              catch (e)

              {

       

                  var exception = {};

                  exception.target = "setDocumentdata";

                  exception.message = e.toString();

                  return exception;

       

              }

       

       

       

          },

       

       

          getDocumentData: function(key)

          {

       

              try

              {

       

       

                  var classProperty = charIDToTypeID('Prpr');

                  var propNull = charIDToTypeID( 'null' );

                  var classNull = charIDToTypeID( 'null' );

                  var typeOrdinal = charIDToTypeID('Ordn');

                  var enumTarget = charIDToTypeID('Trgt');

                  var classDocument = charIDToTypeID('Dcmn');

                  var classLayer = charIDToTypeID('Lyr ');

                  var propProperty = stringIDToTypeID("property");

                  var propGeneratorSettings = stringIDToTypeID("generatorSettings");

                  var propProperty = stringIDToTypeID(key); //unique name for the setting

       

       

                  var actionGet = charIDToTypeID( "getd" );

       

       

                  //Make a property reference to generator settings for active layer.

                  //(use classDocument for the active document)

                  //NOTE: putProperty needs to come before putEnumerated

       

       

                  var theRef = new ActionReference();

                  theRef.putProperty(classProperty, propGeneratorSettings );

                  theRef.putEnumerated(classDocument, typeOrdinal, enumTarget);

       

       

                  //Execute the get action, getting the descriptor for the property reference,

                  //getting just the plugin's settings (propProperty == strMySettings)

       

       

                  var getDescriptor = new ActionDescriptor();

                  getDescriptor.putReference(propNull,theRef);

                  getDescriptor.putString(propProperty, "au.com.oddgames.xui");

       

                  var actionResult = executeAction( actionGet, getDescriptor, DialogModes.NO );

       

       

                  //Extract the settings

       

       

                  var mySettingsDesc = actionResult.getObjectValue(propGeneratorSettings);

       

       

                  return mySettingsDesc.getString(propProperty);

       

               }

              catch (e)

              {

       

                  var exception = {};

                  exception.target = "getDocumentData";

                  exception.message = e.toString();

                  return exception

       

              }

       

          }

       

      }

        • 1. Re: Why doesn't this code work in my extension? Retrieving generator settings from meta data
          oddgames Level 1

          Ok the setting is only being saved for the last property, if I do this:

           

          $._photoshop.setDocumentData('project.isXUI','true');

          $._photoshop.setDocumentData('project.name','hello');

           

          Only the project.name property will be saved when I try using getDocumentData so I guess I'm somehow overwriting something.

          • 2. Re: Why doesn't this code work in my extension? Retrieving generator settings from meta data
            oddgames Level 1

            Ok got it, I have to make sure I pull the descriptor back then save my settings over the top:

             

            $._photoshop = {

             

             

                setDocumentData: function(keys,values)

                {

             

             

                    try

                    {

                       

                        var classProperty = charIDToTypeID('Prpr');

                        var propNull = charIDToTypeID( 'null' );

                        var classNull = charIDToTypeID( 'null' );

                        var typeOrdinal = charIDToTypeID('Ordn');

                        var enumTarget = charIDToTypeID('Trgt');

                        var classDocument = charIDToTypeID('Dcmn');

                        var classLayer = charIDToTypeID('Lyr ');

                        var propProperty = stringIDToTypeID("property");

                        var propGeneratorSettings = stringIDToTypeID("generatorSettings");

                        var strMySettings = "xui";

                        var keyTo = charIDToTypeID( 'T   ' );

                        var actionSet = charIDToTypeID( "setd" );

                        var actionGet = charIDToTypeID( "getd" );

             

             

                        var theRef = new ActionReference();

                        theRef.putProperty(classProperty, propGeneratorSettings );

                        theRef.putEnumerated(classDocument, typeOrdinal, enumTarget);

             

             

                        var getDescriptor = new ActionDescriptor();

                        getDescriptor.putReference(propNull,theRef);

                        getDescriptor.putString(propProperty, strMySettings);

                        var actionResult = executeAction( actionGet, getDescriptor, DialogModes.NO );

                        var mySettingsDesc = actionResult.getObjectValue(propGeneratorSettings);

             

             

                        if (keys.indexOf(",") > 0)

                        {

                            keys = keys.split(',');

                            values = values.split(',');

                        }

                        else

                        {

                            keys = [keys];

                            values = [values];

                        }

                   

                        for (var x =0; x < keys.length; x ++)

                        {

                           

                            var key = keys[x];

                            var value = values[x];

              

                            var propMyStringProperty = stringIDToTypeID(key);

             

             

                            mySettingsDesc.putString(propMyStringProperty,value);

             

             

                        }

             

             

                        var setDescriptor = new ActionDescriptor();

                        setDescriptor.putReference(propNull,theRef);

                        setDescriptor.putObject(keyTo,classNull,mySettingsDesc);

                        setDescriptor.putString(propProperty, strMySettings);

                        executeAction( actionSet, setDescriptor, DialogModes.NO );

             

             

                        return true;

                       

                    }

                    catch (e)

                    {

                       

                        var exception = {};

                        exception.target = "setDocumentdata";

                        exception.message = e.toString();

                        return JSON.stringify(exception);

                       

                    }

                    

             

             

                },

             

             

                getDocumentData: function(key)

                {

                            

                    try

                    {

                     

               

                       var classProperty = charIDToTypeID('Prpr');

                        var propNull = charIDToTypeID( 'null' );

                        var classNull = charIDToTypeID( 'null' );

                        var typeOrdinal = charIDToTypeID('Ordn');

                        var enumTarget = charIDToTypeID('Trgt');

                        var classDocument = charIDToTypeID('Dcmn');

                        var classLayer = charIDToTypeID('Lyr ');

                        var propProperty = stringIDToTypeID("property");

                        var propGeneratorSettings = stringIDToTypeID("generatorSettings");

                        var strMySettings = "xui"; //unique name for your settings/plugin

                        var propMyStringProperty = stringIDToTypeID(key); //unique name for the setting

             

             

                        var actionGet = charIDToTypeID( "getd" );

             

             

                        var theRef = new ActionReference();

                        theRef.putProperty(classProperty, propGeneratorSettings );

                        theRef.putEnumerated(classDocument, typeOrdinal, enumTarget);

             

             

                        var getDescriptor = new ActionDescriptor();

                        getDescriptor.putReference(propNull,theRef);

                        getDescriptor.putString(propProperty, strMySettings);

                        var actionResult = executeAction( actionGet, getDescriptor, DialogModes.NO );

             

             

                        var mySettingsDesc = actionResult.getObjectValue(propGeneratorSettings);

             

             

                        return mySettingsDesc.getString(propMyStringProperty);

                       

                     }

                    catch (e)

                    {

                       

                        var exception = {};

                        exception.target = "getDocumentData";

                        exception.message = e.toString();

                        return JSON.stringify(exception);

                       

                    }

                                   

                }

             

            }