Passing kwargs into objectScript

I have seen @pturmel post about using Simulation Aids “objectScript” in place of runScript. I have been able to use the objectScript. So, I modified my original function to have keyworded arguments, like this:

objectScript(“shared.WorkOrder.SumCounters(*args,**kwargs)”,{[.]…/WE10602/Part_CNT/Raw Reject},EnableOffset=1)

I was hoping to pass keyworded arguments, but this seems to fail. I was just wondering if this function was not designed to handle keyworded arguments. My function works in the script console. I was hoping that I could feed it into “objectScript”.

I didn’t see the documentation mention support for keyworded arguments.

There’s no support for keyword arguments because the expression language provides no hooks to expose the names of arguments like you’ve shown. However, you can explicitly assign values from the args tuple to specific keywords. There’s no reason you can’t embed the keyword like so:

objectScript("shared.WorkOrder.SumCounters(*args, EnableOffset=1)",{[.]../WE10602/Part_CNT/Raw Reject})

Or dynamically with something like this:

objectScript("shared.WorkOrder.SumCounters(*args[:-1], EnableOffset=args[-1])",{[.]../WE10602/Part_CNT/Raw Reject}, {Root Container......some Enable Property})

I have tried the first script, I can’t seem to get this to work.

SyntaxError: (“mismatched input ‘EnableOffset’ expecting DOUBLESTAR”, (‘expression:objectScript’, 1, 45, ‘__retv = shared.WorkOrder.SumCounters(*args, EnableOffset=1)\n’))

The second script generates the same error. Is there something that I am missing?

I am using Ignition v7.9.7.

Whoops! Wildcard parameters must be last in the function call. Try this syntax:

shared.WorkOrder.SumCounters(EnableOffset=1, *args)
1 Like

That worked! Thank you!.

The “objectScript” function is awesome!