In the Production Parameters article, we showed you how to input data for your material series. In this article, we will show you how to use that data in the AMFG worker scripts. This means you can make a script once, and add new materials or change data from the Production Parameters page without changing your pricing calculations.
Creating Worker Scripts
To use the information that is shared in this article, first, you would need to create a worker script. Please navigate to the Autonomous > Worker Dashboard page in the left sidebar in the Management Console:
Then click on the “Create New Worker” button located at the top-right corner and give the worker a name, description, and type here.
The material information can be used in two worker types:
Pricing
Service Pricing
These types will service all of the cost calculations on AMFG.
Once you have created the worker, assign it to a Quotation Form and a Technology / Material as required. Details on how to do this can be found here: Worker Dashboard
Now that you have this setup, you are ready to start coding in the editor. A simple worker performs the following steps to get a price:
Find 3D model information
Find the material used in the quotation form
Finds the corresponding material series
Gets the cost / kg of the material series from the production parameters page.
Uses that information in a pricing formula.
Updates the price
context = engine.getContext();
#Retrieve the information on the specific part
modelVersion = engine.modelVersionRetrieve({"id": context.modelVersionId})
#Retrieve the material you have selected on the quotation form
selected_material = context["productionParameters"]["Material"]
# Find the linked ID of the material you have selected
material_data = engine.materialRetrieve({"name": selected_material})
# Find the linked material series to the one selected in production parameters
material_series_data = engine.materialSeriesRetrieve({"id": material_data["materialSeriesId"]})
#create variables from the material series data
#Cost per kg
cost_per_kg = material_series_data["cost"]
#Milling feed rate
Milling_feed_mat = material_series_data["surface"]
#custom fields
Material_custom = material_series_data["customFields"]
#custom field number 1
first_custom_field = Material_custom[1]
#Use the information to make a formula
price = (cost_per_kg*100000) / modelVersion["volume"]
#input the price into the price field.
engine.updateResponse({
'price': price,
'priceToken': context.priceToken,
})
The parameters you can use are listed below:
Field in Prod Parameters | Name | Type | Create | Update |
| id | ID | autoassign | no |
| appId | ID | autoassign | no |
| customId | Text | yes | yes |
| name | Text | yes | yes |
Cost per KG: | cost | Numeric | yes | yes |
Surface meters per minute: | surface | Numeric | yes | yes |
Cutting speed: | cuttingSpeed | Numeric | yes | yes |
Feed for roughing part: | feedRoughing | Numeric | yes | yes |
Feed for finishing part: | feedFinishing | Numeric | yes | yes |
| knowledgeSeriesId | Numeric | yes | yes |
Custom Fields | customFields | Array of objects with:
| yes | yes |
| createdAt | Date | autoassign | no |
const materialSeries = engine.materialSeriesList({knowledgeSeriesId: 1});
engine.log(JSON.stringify(materialSeries));
// Output
[{
"id":"1",
"appId":"1677",
"customId":"SERIES-0001",
"name":"6000 Series Aluminum Alloy",
"cost":45,
"surface":13,
"cuttingSpeed":42,
"feedRoughing":14,
"feedFinishing":53,
"knowledgeSeriesId":"1",
"customFields":[
{"id":1,"label":"","value":""},
{"id":2,"label":"","value":""},
{"id":3,"label":"","value":""},
{"id":4,"label":"","value":""},
{"id":5,"label":"","value":""}
],
"createdAt":"2025-02-21T12:04:34.686Z"
}]
How to use Machine Group fields
Within the Machine Groups on Production Parameters, we can now add custom fields for each machine group. This could be used to store information such as:
Base hourly rate
Minimum setup time
Cost of tool change
Average packing density
Maximum batch size
Maximum z height
Average running time before maintenance
Support structures required.
We can now use this information in scripts to make more accurate estimations based on machine data. The key benefit is that if this information changes, you can update the quote logic directly from production parameters.
An example script below will:
Retrieve the machine used on the ticket details
Find the corresponding machine ID
Find the custom fields on that machine
Use custom field 1 as an example (simply add 1,2,3,4,5 to use any custom field)
Update price based on custom fields
// Get the current context object from the engine
context = engine.getContext();
// Retrieve model version metadata using the ID from the context
modelVersion = engine.modelVersionRetrieve({ "id": context.modelVersionId });
// Get the selected machine ID from the production parameters
selected_machine = context["productionParametersIds"]["Machine"];
// Retrieve the machine group object associated with the selected machine
selected_machine_group = engine.machineGroupRetrieve({ "id": selected_machine });
// Log the machine group details for debugging or inspection
engine.log(JSON.stringify(selected_machine_group));
// Retrieve full machine group data using the machineGroupId from the previous call
machine_data = engine.machineGroupRetrieve({ "id": selected_machine_group["machineGroupId"] });
// Log the full machine data to inspect available fields
engine.log(JSON.stringify(machine_data));
// Extract custom fields from the machine data
machine_custom = machine_data["customFields"];
// Select the value of the second custom field (index 1)
// ⚠️ Make sure index 1 exists to avoid runtime errors
first_custom_field = machine_custom[1]["value"];
// Return a price response using the selected custom field value
engine.updateResponse({
'price': first_custom_field, // Set the price to the second custom field's value
'priceToken': context.priceToken // Pass the original price token through for consistency
});
To use a custom field with the same label:
The script below will gather all values from any machine group that has the label “price”:
context = engine.getContext();
modelVersion = engine.modelVersionRetrieve({"id": context.modelVersionId})
selected_machine = context["productionParameterIds"]["Machine"]
selected_machine_group = engine.machineGroupRetrieve({"id": selected_machine})
machine_custom = selected_machine_group["customFields"]
price_field = None
for custom in machine_custom:
if custom.label == "price":
price_field = custom
break
first_custom_field = price_field["value"]
engine.updateResponse({
'price': first_custom_field,
'priceToken': context.priceToken,
})