How to get these sub properties of a parameter with scripting?
I am able to get the parameters for the recipe but don't now which attribute of the MESObject contains these sub properties.
How to get these sub properties of a parameter with scripting?
I am able to get the parameters for the recipe but don't now which attribute of the MESObject contains these sub properties.
It looks like you are trying to reference a Recipe-level parameter's subparameter value.
Here is a page on referencing parameters:
https://help.sepasoft.com/docs/display/SEPA/Referencing+Parameters+in+Batch+Recipes
Here is an example:
order = '1697062972762'
bqe = system.mes.batch.queue.getEntry(order)
lotNumber = str(system.date.toMillis(system.date.now()))
system.mes.batch.queue.setParameterValue(bqe, '/{}.Material.Lot_No', lotNumber)
print system.mes.batch.queue.getParameterValue(bqe, '/{}.Material.Auto_Create_Lot')
If the control recipe already exists:
https://help.sepasoft.com/docs/pages/viewpage.action?pageId=51119648
https://help.sepasoft.com/docs/pages/viewpage.action?pageId=51118666
Okay figured it out.
filter=system.mes.object.filter.createFilter()
filter.setEnableStateName('ENABLED')
filter.setMESObjectTypeName('BatchMasterRecipeLogic')
filter.setMESObjectNamePattern('BS_Fill')
ret={}
for item in system.mes.searchMESObjects(filter):
print "{}:{}".format(item.MESObjectTypeName,item.getName())
for x in item.MESObjectLatest.parameters:
if str(x.getParamKind())=='USER_LOGIC':
ret[x.getFriendlyName()]={'value':str(x.getParamValueAsString()),'children':[]}
if str(x.getParamKind())=='SUB_PARAMETER':
parts=x.getFriendlyName().split('.')
parent=parts[0]
child=parts[1]
ret[parent]['children'].append({'name':child,'value':x.getParamValueAsString()})
@liam1 I would recommend a lighter approach using the getBOM function.
https://help.sepasoft.com/docs/pages/viewpage.action?pageId=91685134
https://help.sepasoft.com/docs/pages/viewpage.action?pageId=91685120
Here are examples of getting the BOM for both master and control recipes:
I only iterated through the recipe level params since your screenshot is showing a recipe level param. You can do the same for steps.
parentLink = system.mes.batch.recipe.getRecipeClassLink('Made To Order')
masterRecipeLink = system.mes.batch.recipe.getRecipeLink('MTO1000', parentLink)
masterRecipeBOM = system.mes.batch.recipe.getRecipeBOM(masterRecipeLink)
recipeParams = masterRecipeBOM['Parameters']
for param in recipeParams:
print param['Name']
if param.has_key('Entries'):
for item in param['Entries'][0]['SubParameters']:
print item['Name'].split('.')[1], item['Value']
batchID = 'MTO-111111'
controlRecipeBOM = system.mes.batch.queue.getBatchBOM(batchID)
controlRecipeParams = controlRecipeBOM['Parameters']
for param in controlRecipeParams:
print param['Name']
if param.has_key('Entries'):
for item in param['Entries'][0]['SubParameters']:
print item['Name'].split('.')[1], item['Value']
I'm not sure what you will be doing with this information but if you wanted to change a value via script, you can use the output of getBatchBOM to call setBatchBOM after modifying a value:
https://help.sepasoft.com/docs/pages/viewpage.action?pageId=91685157
Thank you for this @jesse.records , we are recreating the Batch Execution Component for custom functionality and control.
In the current implementation of the built in Batch Execution, the user is able to edit parameter values based on a selected parameter list when configuring a batch for creation.
This is the same functionality I am trying to replicate.
@jesse.records I have one more step to complete this component.
Just like the build-in parameter editor, I would also like to be able to update the parameter value process of creating a batch.
I have created the the same popup and passed in the parameters values.
While looking through the various properties on the parameter object, I noticed the setParamValue
.
Do I need to:
BatchMasterRecipeLogic
object which contains the parameter I want to edit.BatchMasterRecipeLogic
using the setParamValue
function.BatchMasterRecipeLogic
object back into the MES systemOr is there a much simpler method?
Are you wanting to set the default parameter value of the master recipe or set the param value of the queue entry when it is being created?
After discussion with a team member I realized this needs to be done on a queue entry not the default master recipe which you have already described the details of.
What is the best practice for doing this considering the user has not added the batch object to the queue yet? I do the creation of the batch queue object right at the end of the process.
I tried this method , but got an error which required the batch to be running in order to update the parameters.
So I am trying the second method of updating the bom on batch queue entry:
updateParameters={"MaterialName":"test","Material.Target_Quantity":1.0}
bom=system.mes.batch.queue.getBatchBOM('STU_01_11_01_1697447067410_BS_Fill')
print system.util.jsonEncode(bom,4)
for params in bom["Parameters"]:
parent=params["Name"]
if params.has_key('Entries'):
for subparam in params['Entries'][0]['SubParameters']:
if subparam['Name'] in updateParameters.keys():
subparam['Value']=updateParameters[subparam['Name']]
pass
else:
if updateParameters.has_key(parent):
params['Value']=updateParameters[parent]
'---*'*10
print system.util.jsonEncode(bom,4)
system.mes.batch.queue.setBatchBOM(batchQueueEntry, bom)
batchQueueEntry=system.mes.batch.queue.getBatchBOM('STU_01_11_01_1697447067410_BS_Fill')
I'm getting this error even though I providing the bqe as the first argument.
Traceback (most recent call last):
File "<input>", line 26, in <module>
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1548)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:130)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:82)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:40)
at com.sepasoft.production.script.BatchClientQueueScript.setBatchBOM(BatchClientQueueScript.java:317)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value '{u'Steps': [{u'Type': u'Unit Procedure', u'Phase': u'Unit Procedure', u'Step': u'Fill', u'Sublogic': {u'Steps': [{u'Type': u'Equipment Phase', u'Phase': u'Fill', u'Parameters': [{u'Value': False, u'DataType': u'BOOLEAN', u'Name': u'Interlocked'}, {u'Value': u'', u'DataType': u'STRING', u'Name': u'MaterialCode'}, {u'Value': u'', u'DataType': u'STRING', u'Name': u'MaterialName'}, {u'Value': None, u'MinValue': -3.4028234663852886e+38, u'DataType': u'FLOAT', u'MaxValue': 3.4028234663852886e+38, u'Name': u'ReqQty'}, {u'Value': None, u'MinValue': -2147483648, u'DataType': u'INTEGER', u'MaxValue': 2147483647, u'Name': u'SourceEq'}, {u'Value': u'EP_Fill', u'MinValue': u'-2147483648', u'DataType': u'ENUM', u'MaxValue': u'2147483647', u'Name': u'Task'}], u'Step': u'UP2'}], u'Parameters': [{u'Value': False, u'DataType': u'BOOLEAN', u'Name': u'ColourCorrect'}, {u'Value': u'', u'DataType': u'STRING', u'Name': u'MaterialCode'}, {u'Entries': [{u'SubParameters': [{u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Lot_Manifest'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Material_Name'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Material_Class'}, {u'Value': u'Invalid parameter value.', u'DataType': u'String', u'Name': u'MaterialIn.Lot_Status'}, {u'Value': u'Invalid parameter value.', u'DataType': u'String', u'Name': u'MaterialIn.Material_UOM'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Lot_Manifest_Class'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Lot_Equipment'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Lot_Equipment_Class'}, {u'Value': 0, u'MinValue': -2147483648, u'DataType': u'Int4', u'MaxValue': 2147483647, u'Name': u'MaterialIn.Alternate_Priority'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Lot_No'}, {u'Value': None, u'DataType': u'String', u'Name': u'MaterialIn.Alternate_Group'}, {u'Value': 0.0, u'MinValue': -1.7976931348623157e+308, u'DataType': u'Float8', u'MaxValue': 1.7976931348623157e+308, u'Name': u'MaterialIn.Target_Quantity'}, {u'Value': 0.0, u'MinValue': -1.7976931348623157e+308, u'DataType': u'Float8', u'MaxValue': 1.7976931348623157e+308, u'Name': u'MaterialIn.Actual_Quantity'}]}], u'Name': u'MaterialIn'}, {u'Value': u'', u'DataType': u'STRING', u'Name': u'MaterialName'}, {u'Value': False, u'DataType': u'BOOLEAN', u'Name': u'Pasteurizing'}, {u'Value': None, u'MinValue': -3.4028234663852886e+38, u'DataType': u'FLOAT', u'MaxValue': 3.4028234663852886e+38, u'Name': u'ReqQty'}, {u'Value': u'Tanker 1', u'DataType': u'ENUM', u'Name': u'SourceEq'}, {u'Value': u'EP_Fill', u'DataType': u'ENUM', u'Name': u'Task'}], u'LogicType': u'Unit Procedure', u'Name': u'Fill'}}], u'Parameters': [{u'Value': u'', u'DataType': u'STRING', u'Name': u'ActualQty'}, {u'Entries': [{u'SubParameters': [{u'Value': u'Invalid parameter value.', u'DataType': u'String', u'Name': u'Material.Material_UOM'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Lot_Manifest_Class'}, {u'Value': u'Production', u'DataType': u'String', u'Name': u'Material.Material_Class'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Alternate_Group'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Lot_Equipment'}, {u'Value': 0.0, u'MinValue': -1.7976931348623157e+308, u'DataType': u'Float8', u'MaxValue': 1.7976931348623157e+308, u'Name': u'Material.Actual_Quantity'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Lot_No'}, {u'Value': u'Invalid parameter value.', u'DataType': u'String', u'Name': u'Material.Lot_Status'}, {u'Value': u'2_01266_012 - Natural Flavouring (Pineapple)-KAN-25KG', u'DataType': u'String', u'Name': u'Material.Material_Name'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Lot_Manifest'}, {u'Value': None, u'DataType': u'String', u'Name': u'Material.Lot_Equipment_Class'}, {u'Value': 0.0, u'MinValue': -1.7976931348623157e+308, u'DataType': u'Float8', u'MaxValue': 1.7976931348623157e+308, u'Name': u'Material.Target_Quantity'}, {u'Value': 0, u'MinValue': -2147483648, u'DataType': u'Int4', u'MaxValue': 2147483647, u'Name': u'Material.Alternate_Priority'}]}], u'Name': u'Material'}, {u'Value': u'', u'DataType': u'STRING', u'Name': u'MaterialName'}, {u'Value': u'Tanker 1', u'DataType': u'ENUM', u'Name': u'SourceEq'}], u'LogicType': u'Procedure', u'Name': u'BS_Fill'}' into type: class com.sepasoft.production.gateway.manager.misc.BatchQueueEntry
@liam1 I'm not sure from this snippet where batchQueueEntry was first declared.
If it is not until the end, you may need to move this up a line.
Thanks for pointing that out.
I got a new error. Which I tried to resolve by setting Invalid parameter value
to None
.
The issue is, even if you call getBatchBOM
, make not changes to the object and then use setBatchBOM
it still gives and error.
This Error doesn't appear in the normal recipe editor on a validated recipe?
updateParameters={"MaterialName":"test","Material.Target_Quantity":1.0}
bom=system.mes.batch.queue.getBatchBOM('STU_01_11_01_1697459467689_BS_Fill')
print system.util.jsonEncode(bom,4)
for params in bom['Parameters']:
parent=params['Name']
if params.has_key('Entries'):
for subparam in params['Entries'][0]['SubParameters']:
if subparam['Name'] in updateParameters.keys():
subparam['Value']=updateParameters[subparam['Name']]
if subparam['Value']=="Invalid parameter value.":
subparam['Value']=None
else:
if updateParameters.has_key(parent):
params['Value']=updateParameters[parent]
if params['Value']=="Invalid parameter value.":
params['Value']=None
'After Edit*'*10
print system.util.jsonEncode(bom,4)
batchQueueEntry=system.mes.batch.queue.getEntry('STU_01_11_01_1697459467689_BS_Fill')
system.mes.batch.queue.setBatchBOM(batchQueueEntry, bom)
inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Enum (Lot_Status) option with name (Invalid parameter value.) not found
{
"LogicType": "Procedure",
"Name": "BS_Fill",
"Parameters": [
{
"DataType": "STRING",
"Name": "ActualQty",
"Value": ""
},
{
"Entries": [{"SubParameters": [
{
"DataType": "Float8",
"MaxValue": 1.7976931348623157E308,
"MinValue": -1.7976931348623157E308,
"Name": "Material.Target_Quantity",
"Value": 1.0
},
{
"DataType": "String",
"Name": "Material.Lot_Status",
"Value": "Complete"
},
{
"DataType": "String",
"Name": "Material.Material_Class",
"Value": "Production"
},
{
"DataType": "Float8",
"MaxValue": 1.7976931348623157E308,
"MinValue": -1.7976931348623157E308,
"Name": "Material.Actual_Quantity",
"Value": 0.0
},
{
"DataType": "String",
"Name": "Material.Lot_No",
"Value": null
},
{
"DataType": "Int4",
"MaxValue": 2147483647,
"MinValue": -2147483648,
"Name": "Material.Alternate_Priority",
"Value": 0
},
{
"DataType": "String",
"Name": "Material.Lot_Equipment",
"Value": null
},
{
"DataType": "String",
"Name": "Material.Alternate_Group",
"Value": null
},
{
"DataType": "String",
"Name": "Material.Material_UOM",
"Value": "L"
},
{
"DataType": "String",
"Name": "Material.Material_Name",
"Value": "2_01266_012 - Natural Flavouring (Pineapple)-KAN-25KG"
},
{
"DataType": "String",
"Name": "Material.Lot_Manifest",
"Value": null
},
{
"DataType": "String",
"Name": "Material.Lot_Manifest_Class",
"Value": null
},
{
"DataType": "String",
"Name": "Material.Lot_Equipment_Class",
"Value": null
}
]}],
"Name": "Material"
},
{
"DataType": "STRING",
"Name": "MaterialName",
"Value": "test"
},
{
"DataType": "ENUM",
"Name": "SourceEq",
"Value": "Tanker 1"
}
],
"Steps": [{
"Phase": "Unit Procedure",
"Step": "Fill",
"Sublogic": {
"LogicType": "Unit Procedure",
"Name": "Fill",
"Parameters": [
{
"DataType": "BOOLEAN",
"Name": "ColourCorrect",
"Value": false
},
{
"DataType": "STRING",
"Name": "MaterialCode",
"Value": ""
},
{
"Entries": [{"SubParameters": [
{
"DataType": "String",
"Name": "MaterialIn.Lot_Status",
"Value": "Invalid parameter value."
},
{
"DataType": "Float8",
"MaxValue": 1.7976931348623157E308,
"MinValue": -1.7976931348623157E308,
"Name": "MaterialIn.Actual_Quantity",
"Value": 0.0
},
{
"DataType": "String",
"Name": "MaterialIn.Material_Name",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Lot_Manifest_Class",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Lot_Equipment",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Lot_No",
"Value": null
},
{
"DataType": "Int4",
"MaxValue": 2147483647,
"MinValue": -2147483648,
"Name": "MaterialIn.Alternate_Priority",
"Value": 0
},
{
"DataType": "Float8",
"MaxValue": 1.7976931348623157E308,
"MinValue": -1.7976931348623157E308,
"Name": "MaterialIn.Target_Quantity",
"Value": 0.0
},
{
"DataType": "String",
"Name": "MaterialIn.Alternate_Group",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Lot_Manifest",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Lot_Equipment_Class",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Material_Class",
"Value": null
},
{
"DataType": "String",
"Name": "MaterialIn.Material_UOM",
"Value": "Invalid parameter value."
}
]}],
"Name": "MaterialIn"
},
{
"DataType": "STRING",
"Name": "MaterialName",
"Value": ""
},
{
"DataType": "BOOLEAN",
"Name": "Pasteurizing",
"Value": false
},
{
"DataType": "FLOAT",
"MaxValue": 3.4028234663852886E38,
"MinValue": -3.4028234663852886E38,
"Name": "ReqQty",
"Value": null
},
{
"DataType": "ENUM",
"Name": "SourceEq",
"Value": "Tanker 1"
},
{
"DataType": "ENUM",
"Name": "Task",
"Value": "EP_Fill"
}
],
"Steps": [{
"Parameters": [
{
"DataType": "BOOLEAN",
"Name": "Interlocked",
"Value": false
},
{
"DataType": "STRING",
"Name": "MaterialCode",
"Value": ""
},
{
"DataType": "STRING",
"Name": "MaterialName",
"Value": ""
},
{
"DataType": "FLOAT",
"MaxValue": 3.4028234663852886E38,
"MinValue": -3.4028234663852886E38,
"Name": "ReqQty",
"Value": null
},
{
"DataType": "INTEGER",
"MaxValue": 2147483647,
"MinValue": -2147483648,
"Name": "SourceEq",
"Value": null
},
{
"DataType": "ENUM",
"MaxValue": "2147483647",
"MinValue": "-2147483648",
"Name": "Task",
"Value": "EP_Fill"
}
],
"Phase": "Fill",
"Step": "UP2",
"Type": "Equipment Phase"
}]
},
"Type": "Unit Procedure"
}]
}
After fixing the ENUM issue, this is the next error I get. Is there anyway to only make changes to parts of the BOM instead of the whole BOM?
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Cannot set value for param (Task) because the value (EP_Fill) is greater than the parameter's defined maximum value (2147483647).