RunScript Condition Weird Results

Posted by: Ken Stulce

RunScript Condition Weird Results - 09/22/17 11:37 AM

Hello All,

I'm getting some odd results when using a RunScript Condition for the "Script.ReturnValue = 1" and wanted to have another set of eyes look at it. I have a dummy test at the very beginning of the script that I copied from the forums to force a True result and it will not return True, only keeps running through the rest of the script. I do get my ShowMessage pop-ups though to tell me of the condition results. Look for the code directly after the line "# Force test for True".

I forgot to mention that I added a secondary RunScript condition, but only containing the dummy test lines and it worked, but I have no idea why it will not work in the full script below. My question is for understanding purposes, as it should return true no matter what scenario. Also, I have not run this live, only through the debugger, if that makes a difference.

The script is coded in Python and it works with the rest of my conditioning, but I'm totally baffled why the dummy True test is not returning. Thoughts?

In a nutshell, the script is looking for mostly empty pages that only contain control characters like "\n", etc., that are the results of a Splitter. I'm still testing this, so it's not complete. Long story based on a recent finding and this script will help me figure out what is really happening on our HUGE workflow.

import os
import string

# Get PPWatch Job Filename
jfn = Watch.GetJobFileName()
ofn = Watch.GetOriginalFileName()

Watch.ShowMessage("The job filename is: " + jfn)
Watch.ShowMessage("The original filename is: " + ofn)

# Force test for True
everythingOK = True
Watch.ShowMessage("eOK value: \"{0}\".".format(everythingOK))
if (everythingOK):
    Watch.ShowMessage("eOK If Test True!")
    Script.ReturnValue = 1
    Watch.ShowMessage("eOK If Test False!")
    Script.ReturnValue = 0

# Get file size
filsize = os.path.getsize(jfn)
filtype = type(filsize)
Watch.ShowMessage("File size is: \"{0}\".".format(filsize))
Watch.ShowMessage("filsize type = \"{0}\".".format(filtype))

# Check for file sizes greater than 100b
if (filsize < 100):
    Watch.ShowMessage("Filesize is less than 100b: \"{0}\".".format(filsize))
    Watch.Log("LOG: File is less than 100 bytes!  Do not process!", 2)
    Script.ReturnValue = 1
    Watch.ShowMessage("Filesize is greater than 100b: \"{0}\".".format(filsize))

with open(jfn, 'r') as myfile:
    prtdata =
    #Test for printable character (whitespace is considered printable)
    printable_char_test = all(c in string.printable for c in prtdata)
    count = 0
    for char in prtdata:
        count += 1

    #Test for file character length
    if (count <= 10):
        Watch.ShowMessage("Character count is <= 10: \"{0}\".".format(count))
        Watch.Log("LOG: File contains less than 10 characters!  Do not process!", 2)
        Script.ReturnValue = 1
        Watch.ShowMessage("Character count is > 10: \"{0}\".".format(count))
        Script.ReturnValue = 0

Secondary Questions:
Also, is Python v3 supported with PlanetPress Suite 7? I'm still running v2.7 on our server, but I'm planning a server upgrade next year.

Is Windows Server 2016 supported for PP Suite 7 too? I'll only saw Server 2012 R2 listed on a recent update specs listing, but no mention of Server 2016. Same question for PP Connect? I'll eventually make that leap.

Thank you.
Posted by: Jean-Cédric

Re: RunScript Condition Weird Results - 09/22/17 12:01 PM

I'm not sure but looking at your explanation, you seems to expect the script to stop once you have applied a value to Script.Value. If that is the case, try to see Script.Value as a variable...not an action that stops the script.

The script will go on to the end and will remain with the last value applied to Script.Value. Again, I can be mistaken...
Posted by: Ken Stulce

Re: RunScript Condition Weird Results - 09/22/17 01:06 PM

Hi Jean-Cédric. You are correct. I was thinking of Script.ReturnValue similarly to a Function-like Return, which would usually stop the script and return the specified value. This helps a lot! Thank you.
Posted by: Ken Stulce

Re: RunScript Condition Weird Results - 09/22/17 01:33 PM

Is there a preferred method, or is it even possible, to hard return out of a condition RunScript back to PPWatch with the proper Script.ReturnValue?

From Python, I've tried "return", "quit()", "exit()", "sys.exit()", and a few other methods directly after setting Script.ReturnValue, but they all raise an error (W3602, W3603, W1603) in PPWatch Messages.


W3602 : Error 0 on line 40, column 0: Python ActiveX Scripting Engine: Traceback (most recent call last):
  File "<Script Block >", line 40, in <module>
  File "C:\Python27\Lib\", line 360, in __call__
    raise SystemExit(code)
SystemExit: 0
W3603 : Error running script.
Run Script: W1603 : Plugin failed - 12:17:41 (elapsed time: 00:00:03:789)

Thank you.
Posted by: Philippe F.

Re: RunScript Condition Weird Results - 09/25/17 08:45 AM

In Python, you should encapsulate your code inside a main() function. You can then use the return statement to exit from that function at any point. For instance:

def main():
  for x in range(0,5):
    if x == 3:
  Watch.Log("This will never get logged",3)


In this example, we interrupt the loop (and the entire function) after having logged the first 3 entries. Notice how that last Watch.Log() statement at the bottom of the main() function never gets called, because we returned from the function before ever reaching it.
Posted by: Ken Stulce

Re: RunScript Condition Weird Results - 09/26/17 10:07 AM

Thank you, Philippe. That makes total sense. I do that same technique with other Python scripts, but I was dabbling here at first and didn't take it to that extent. I will do that now.

I appreciate your feedback.

Best Regards,
Posted by: Ken Stulce

Re: RunScript Condition Weird Results - 09/26/17 10:41 AM

Hi Philippe,

One thing that I just discovered is that the normal Python syntax, below, for declaring the main method doesn't work with PlanetPress. Instead, I commented out the "if" statement, and it worked as you suggested. Just wanted to make a note about this for myself and others.

if __name__ == '__main__':
    Watch.ShowMessage("Start script - ReturnValue = \"{0}\".".format(Script.ReturnValue))
    Watch.ShowMessage("Finished with script - ReturnValue = \"{0}\".".format(Script.ReturnValue))

Thank you.
Posted by: Philippe F.

Re: RunScript Condition Weird Results - 09/26/17 03:32 PM

Hi Ken,

If you print out the value of the __name__ variable, you'll see it contains __ax_main__, which I guess is Windows' way of identifying ActivePython as opposed to regular Python.

I have to admit I didn't know that until I tested it out just now... :P