3 Replies Latest reply on Jul 12, 2011 9:03 AM by John Hawkinson

    [CS5][JS] Script will not always produce expected behavior

    JohnDevlon Level 1

      Hi,

       

      With this post I would like an experts opinion on some problems i'm having writing and using scripts.

       

      When I write a script, I do many test and at first, they work fine. After some time problems may occure.

      The reason for that is I didn't set all properties for the objects i'm using.

       

      An example: I've written a script that creates a textframe and places text into it. The script creates a new textframe, sets the geometric bounds, adds a border and adds text into it. When running the script, It works  fine. After using the script for some time in my own documents, I've used it in a file from someone else. The person changed the default left margin in the document from 0 to 5 mm and now the script creates a textframe identical to the other ones, but also using the specs from the file and added the left margin of 5 mm, not what i had in mind.

       

      Another example: I've created a script that adds some extra colors in a file. Everything worked fine in my own files. When I used it in a file from someone else, I've received an error. Apparently I did not specify to create a CMYK color, I defined the values, not the colorspace. It worked great but in the problem file, the last color created was an RGB color. I've added a color value to mutch for an rgb color and an error occured.

       

      Other examples can be: someone changed the default language to something else.

       

      How to I prevent this behavior? When I create or use an object, do I set every parameter (and there can be many) ? Or can I clear/remove any overrides and use default settings? How can I be sure that my script will produce the exact same result in every file, on every machine, every time? Is there some function to clear any overrides in a file?

       

      Any feedback or inside would be nice and appreiciated.

       

      Kind regards

       

      John