Power Scripting Module

Hello,

I recently released a new Ignition module that provides advanced Python scripting capabilities. I recently wrote a blog post that explains in some detail the features and capabilities the module adds to Ignition.

You can see here: nickmudge.info/post/pa-power-scripting-module

I’d appreciate any thoughts about it.

Thanks,

Wow, very nice job Nick!

That looks like some very powerful stuff, I will have to spend some time and play around with it for a little bit. I’m still trying to wrap my head around what some of that can be used for. :thumb_left:

Thanks for your comments Doug!

For a limited time, anyone who gives an interesting or useful example of using the Power Scripting Module will receive a coupon code for a 100 discount for a Power Scripting Module license (so you get a free license).

Using muteable datasets, I can easily look for changes in a dataset, and update a tab strip accordingly.

[code]if event.propertyName==“LineList”:

Retrieve datasets

tabData=pa.dataset.toData(event.source.tabData) # Tab styles
lineList=pa.dataset.toData(event.source.LineList) # Current line list
prevLineList=pa.dataset.toData(event.source.PreviousLineList) # Previous line list
blankRows=pa.dataset.toData(event.source.BlankRow) # Blank tab styles (Red, Yellow, Green)
if lineList != prevLineList: # Compare line lists
tabData.clearRows() # Clear Out Tab Styles
for row in lineList:
newRow=blankRows.copy().popRow(row[‘Status’]) # Copy blank line styles and pop out the one we want.
newRow[0]=row[‘Line’] # Edit in Line Number and Description
newRow[1]=""+str(row[‘Line’])+"
"+str(row[‘Station_Desc’])
tabData.addRow(newRow) # Add to tab styles
event.source.tabData=tabData.toDataSet() # Update tabs
event.source.PreviousLineList=lineList.toDataSet() # Update previous line list.
[/code]

Awesome Jordan :thumb_left:

It is nice to be able to compare if two datasets are equal or not using: “==” and “!=”, as you did with lineList != prevLineList. As you mentioned, that that can be used to see if a dataset has changed or not.

Nice use of the various methods of MutablePyDataSet.

Best,

I’m ressurecting this thread for a bit, as @nmudge has been wanting me to post a common usage for MutablePyDataSets. I’m not sure about common, but this is one that I just finished up, except for some date ranges. This does a lot of work with columns, so MutablePyDataSets seemed to be good fit. Also, Nick pays me a nickel every time I mention MutablePyDataSets, so I’m going for broke! :wink:

One of the metrics around here is cycle time. In assembly work, there are two types, and people seem to want to use them interchangeably (much to my annoyance). The two types are:

  • Machine cycle time: The time from the beginning of a process to the end of the process.

  • Takt time: The time from the beginning of a machine cycle to the beginning of the next machine cycle. This is to include things like part transfer, anything else done to the part that can’t be monitored by the machine, etc.

As each type of cycle time is completed at a machine station, a transaction group logs it into a table:

This script queries the database for all the entries, converting to a MutablePyDataSet. Then for each station the list, we perform a findrows()-- giving us a new mutable dataset-- and grab the column with the times. This end up with a list of data.

We can use this list to create a Stats datatype using the Statistics Expansion for Ignition. The Stats datatype has a built-in histogram function, which-- after adding a couple of header names-- is converted into yet another MutablePyDataSet. The bin count column values are copied into the MutablePyDataSets storing our chart data.

I think I’m up to 30¢ now…

The chart data is complete, but I have users that want the data rotated, so that the station names are in the rows, with the histogram bins as the column names. Sheesh, everybody’s a critic. Two more MutablePyDataSets it is!

We already have a list of station names, so that gets added as the first column. The remaining items are reading the rows in each of the chartable MutablePyDataSets and adding it as a column in the new MutablePyDataSets.

That’s the overview of it. This has certainly made working with columns a lot simpler.

Oh. MutablePyDataSets. That makes it an even 50¢. :smirk:

Jython 2.5.3 (v2.5.3:3d2dbae23c52+, Nov 17 2012, 11:51:23) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_151

>>> 
machChartData
row | bin 110 120 130 135  140 150  155 160
-------------------------------------------
 0  | 0   0   0   0   0    4   1245 506 521
 1  | 10  0   0   0   0    1   0    72  2  
 2  | 11  0   0   0   0    0   0    73  0  
 3  | 12  0   0   0   0    0   0    47  0  
 4  | 13  0   0   0   0    0   0    43  3  
 5  | 14  0   0   0   0    0   0    50  1  
 6  | 15  0   0   0   0    158 0    50  0  
 7  | 16  22  26  7   0    183 0    36  0  
 8  | 17  182 205 14  0    56  0    33  0  
 9  | 18  229 261 68  0    52  0    35  0  
 10 | 19  215 254 106 1231 65  0    24  1  
 11 | 20  95  130 160 11   56  0    16  0  
 12 | 21  77  115 163 0    52  0    20  0  
 13 | 22  43  71  153 0    65  0    11  0  
 14 | 23  19  39  119 0    47  0    16  0  
 15 | 24  17  35  110 0    49  0    8   1  
 16 | 25  9   23  59  0    42  0    15  0  
 17 | 26  9   19  58  0    44  0    18  0  
 18 | 27  7   13  47  0    29  0    15  0  
 19 | 28  2   10  48  0    34  0    12  0  
 20 | 29  1   5   33  0    35  0    12  0  
 21 | 30  0   1   11  0    19  0    11  0  
 22 | 31  2   5   24  0    17  0    9   0  
 23 | 32  0   0   13  0    15  0    16  0  
 24 | 33  3   2   8   0    18  0    10  0  
 25 | 34  0   0   5   0    18  0    11  1  
 26 | 35  1   3   4   0    19  0    4   0  
 27 | 36  86  0   4   0    11  0    4   0  
 28 | 37  24  0   4   0    15  0    7   0  
 29 | 38  13  2   0   0    11  0    8   0  
 30 | 39  11  3   2   0    11  0    1   0  
 31 | 40  11  0   1   0    6   0    4   0  
 32 | 41  9   0   2   0    10  0    2   0  
 33 | 42  12  1   1   0    13  0    6   0  
 34 | 43  6   2   1   0    5   0    2   0  
 35 | 44  8   2   2   0    7   0    5   0  
 36 | 45  9   2   0   0    7   0    2   0  
 37 | 46  6   1   0   0    4   0    3   0  
 38 | 47  4   0   1   0    4   0    0   0  
 39 | 48  9   1   1   0    2   0    1   0  
 40 | 49  9   0   0   0    4   0    0   0  
 41 | 50  8   0   0   0    0   0    1   0  
 42 | 51  8   0   0   0    2   0    1   1  
 43 | 52  3   0   0   0    5   0    1   0  
 44 | 53  4   0   0   0    2   0    0   0  
 45 | 54  6   0   0   0    3   0    0   0  
 46 | 55  3   0   0   0    2   0    0   0  
 47 | 56  0   0   0   0    2   0    0   0  
 48 | 57  2   0   1   0    3   0    0   0  
 49 | 58  2   1   0   0    1   0    0   0  
 50 | 59  2   0   0   0    0   0    0   0  
 51 | 60  38  8   6   0    28  0    8   0  

------------------
taktChartData
row | bin 110 120 130 135 140 150 155  160
------------------------------------------
 0  | 0   69  0   32  0   4   0   1251 0  
 1  | 10  1   0   0   0   0   0   2    0  
 2  | 11  0   0   2   0   0   1   0    0  
 3  | 12  0   0   182 0   0   0   2    0  
 4  | 13  4   0   131 0   0   0   0    0  
 5  | 14  3   0   69  0   0   0   4    0  
 6  | 15  1   0   60  0   0   0   17   0  
 7  | 16  15  0   48  0   0   0   5    0  
 8  | 17  15  0   38  0   0   0   8    0  
 9  | 18  8   0   31  0   2   0   9    0  
 10 | 19  5   0   40  0   2   0   58   0  
 11 | 20  9   0   34  0   0   0   44   0  
 12 | 21  6   0   28  0   0   0   32   0  
 13 | 22  8   0   17  0   1   0   12   0  
 14 | 23  8   0   17  0   0   0   16   0  
 15 | 24  10  0   14  0   1   0   17   0  
 16 | 25  2   0   10  0   2   0   17   0  
 17 | 26  6   0   8   0   0   0   13   0  
 18 | 27  4   0   9   0   1   1   20   0  
 19 | 28  5   0   8   0   0   0   18   0  
 20 | 29  5   0   4   0   5   0   12   0  
 21 | 30  3   0   9   4   3   0   16   0  
 22 | 31  4   0   4   23  21  23  20   22 
 23 | 32  5   1   7   42  38  18  81   3  
 24 | 33  6   1   4   39  36  15  54   1  
 25 | 34  3   0   7   28  22  13  37   2  
 26 | 35  34  12  12  63  69  72  13   44 
 27 | 36  333 336 105 123 129 172 21   110
 28 | 37  131 140 36  81  97  92  20   66 
 29 | 38  51  52  17  60  48  50  26   23 
 30 | 39  40  43  15  54  51  43  14   9  
 31 | 40  35  33  14  53  60  68  14   16 
 32 | 41  30  32  13  59  54  72  19   24 
 33 | 42  34  35  19  46  44  49  15   19 
 34 | 43  17  24  8   32  17  22  11   8  
 35 | 44  31  28  10  30  35  32  10   16 
 36 | 45  32  34  13  27  30  37  8    13 
 37 | 46  33  28  20  27  30  29  15   15 
 38 | 47  23  24  9   26  28  27  10   9  
 39 | 48  24  29  12  31  30  33  10   7  
 40 | 49  20  31  7   29  26  20  9    8  
 41 | 50  35  27  13  25  29  24  8    10 
 42 | 51  21  24  7   25  20  24  8    8  
 43 | 52  8   17  5   15  19  18  2    5  
 44 | 53  20  16  10  14  17  15  6    4  
 45 | 54  15  22  7   22  16  12  5    4  
 46 | 55  20  20  7   21  23  19  4    5  
 47 | 56  9   16  6   17  25  19  4    6  
 48 | 57  16  14  11  18  13  14  4    8  
 49 | 58  11  13  3   18  13  11  3    3  
 50 | 59  0   10  1   7   9   13  5    3  
 51 | 60  140 162 40  166 167 169 58   56 

------------------
machTableData
row | Sta 0    10 11 12 13 14 15  16  17  18  19   20  21  22  23  24  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0  | 110 0    0  0  0  0  0  0   22  182 229 215  95  77  43  19  17  9  9  7  2  1  0  2  0  3  0  1  86 24 13 11 11 9  12 6  8  9  6  4  9  9  8  8  3  4  6  3  0  2  2  2  38
 1  | 120 0    0  0  0  0  0  0   26  205 261 254  130 115 71  39  35  23 19 13 10 5  1  5  0  2  0  3  0  0  2  3  0  0  1  2  2  2  1  0  1  0  0  0  0  0  0  0  0  0  1  0  8 
 2  | 130 0    0  0  0  0  0  0   7   14  68  106  160 163 153 119 110 59 58 47 48 33 11 24 13 8  5  4  4  4  0  2  1  2  1  1  2  0  0  1  1  0  0  0  0  0  0  0  0  1  0  0  6 
 3  | 135 0    0  0  0  0  0  0   0   0   0   1231 11  0   0   0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
 4  | 140 4    1  0  0  0  0  158 183 56  52  65   56  52  65  47  49  42 44 29 34 35 19 17 15 18 18 19 11 15 11 11 6  10 13 5  7  7  4  4  2  4  0  2  5  2  3  2  2  3  1  0  28
 5  | 150 1245 0  0  0  0  0  0   0   0   0   0    0   0   0   0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
 6  | 155 506  72 73 47 43 50 50  36  33  35  24   16  20  11  16  8   15 18 15 12 12 11 9  16 10 11 4  4  7  8  1  4  2  6  2  5  2  3  0  1  0  1  1  1  0  0  0  0  0  0  0  8 
 7  | 160 521  2  0  0  3  1  0   0   0   0   1    0   0   0   0   1   0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  0  0 

------------------
taktTableData
row | Sta 0    10 11 12  13  14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  37  38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 0  | 110 69   1  0  0   4   3  1  15 15 8  5  9  6  8  8  10 2  6  4  5  5  3  4  5  6  3  34 333 131 51 40 35 30 34 17 31 32 33 23 24 20 35 21 8  20 15 20 9  16 11 0  140
 1  | 120 0    0  0  0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1  1  0  12 336 140 52 43 33 32 35 24 28 34 28 24 29 31 27 24 17 16 22 20 16 14 13 10 162
 2  | 130 32   0  2  182 131 69 60 48 38 31 40 34 28 17 17 14 10 8  9  8  4  9  4  7  4  7  12 105 36  17 15 14 13 19 8  10 13 20 9  12 7  13 7  5  10 7  7  6  11 3  1  40 
 3  | 135 0    0  0  0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  4  23 42 39 28 63 123 81  60 54 53 59 46 32 30 27 27 26 31 29 25 25 15 14 22 21 17 18 18 7  166
 4  | 140 4    0  0  0   0   0  0  0  0  2  2  0  0  1  0  1  2  0  1  0  5  3  21 38 36 22 69 129 97  48 51 60 54 44 17 35 30 30 28 30 26 29 20 19 17 16 23 25 13 13 9  167
 5  | 150 0    0  1  0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  1  0  0  0  23 18 15 13 72 172 92  50 43 68 72 49 22 32 37 29 27 33 20 24 24 18 15 12 19 19 14 11 13 169
 6  | 155 1251 2  0  2   0   4  17 5  8  9  58 44 32 12 16 17 17 13 20 18 12 16 20 81 54 37 13 21  20  26 14 14 19 15 11 10 8  15 10 10 9  8  8  2  6  5  4  4  4  3  5  58 
 7  | 160 0    0  0  0   0   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  22 3  1  2  44 110 66  23 9  16 24 19 8  16 13 15 9  7  8  10 8  5  4  4  5  6  8  3  3  56 

>>