Skip to main content
Participating Frequently
July 30, 2013
Question

How do you read a string larger than 255 characters to as a scripting parameter?

  • July 30, 2013
  • 2 replies
  • 1190 views

Is there any way to do this?

PIGetString uses a Str255, which has a 255 character limit.  I have tried PIGetAlias and PIGetText from within the plug-in, but both failed.  I primarily used putString from the script side for testing, but I messed around with trying to cast the string as a file also.

This topic has been closed for replies.

2 replies

drelidanAuthor
Participating Frequently
August 6, 2013

Just an update.  I have a theoretical workaround for this, though I have not implemented it yet.  It requires some changes on the side that sends the parameters and on the plug-in read parameters side.

There will need to be a new num_strings scripting parameter. (something like... 'numS')

There is also a variable scripting parameter on the receiving end, something like 'zz01' if you're using characters or "string_01" if you are using strings.

As a precondition, the scripting system must read in num_strings prior to reading in the long_string.

Before passing the variable long_string to Photoshop, the source of long_string will determine its length.

num_strings = (long_string.Length() >> 8) //divide by 256

Then, a loop could be used to fill in the appropriate parameters...

for(int i = 1; i <= num_strings; i++)

{    

     var idStr = charIDToTypeID ( "zz0" + i ); //Ideally, there would be logic here to to make this work for cases where i > 9.

     var begin_index = (i - 1) << 8; //multiply by 256

     var end_index = (i << 8) < long_string.Length() ? (i << 8) : long_string.Length() - 1; //The next 256 characters, or the end index as appropriate.

     desc3.putString (idStr, long_string.SubString(begin_index, end_index); //Assuming SubString(begin, end).

}

On the plug-in side, the globals struct will need a char* to hold the long string.

In the ReadScriptParams function, a couple of changes will need to be made.

case('numS'):

{

     int32 num_strings;

     PIGetInt(token, &num_strings);

     globals_num_strings = num_strings;

     globals_long_string = new char[num_strings << 8];

}

default:

{

     if(key > 'zz00')

     {

          int32 string_num = key - 'zz00' - 1; //subtracting 1 for zero indexing

          if(string_num < globals_num_strings)

          {

               Str255 temp_string;

               memset(temp_string, 0, 256);

               PIGetStr(token, &input_string);

               strcpy_s(globals_long_string + (string_num << 8), 256, (char*)temp_string); //Copy the received string to the proper location in the buffer.

          }

     }

}

This allows the key 'zz00' to be overloaded, and allows the plug-in to know which string in the series of strings has been passed in.  It also provides safety so that we will not try to get a string from any arbitrary key that is greater than 'zz00', only the keys that are passed in that are within the number of strings.

This isn't a perfect solution, but it's what I am going to attempt to use as a workaround for this problem.

Pedro Cortez Marques
Legend
August 1, 2013

Have the same problem here.

And still don't have the answer.

Ocasionaly happens that it blocks my save script because of that.

At least I would like to build a warning when that happens so I can redirect the code to another shorter string.

I want this precious help too as well.