Sepasoft MES Module Suite
getCreateByDefUUID(...)
Returns an existing SPC sample when sampleUUID is provided; otherwise creates a new sample from a sample definition UUID at the specified location. Use this helper when a workflow may resume an existing sample or start a new sample with the same call pattern.
Syntax
Python |
# Current system.mes.spc.sample API system.mes.spc.sample.getCreateByDefUUID(sampleUUID, defUUID, locationPath) # Legacy SPC 2.0 API name system.quality.sample.data.getCreateSampleByDefUUID(sampleUUID, defUUID, locationPath) |
Parameters
Parameter | Type | Required | Description |
|---|---|---|---|
sampleUUID | String | Optional | UUID of an existing sample to return. When this value is not blank, the function returns that sample and does not use defUUID or locationPath to create a new one. |
defUUID | String | Required when sampleUUID is blank | UUID of the sample definition to use when creating a new sample. |
locationPath | String | Required when sampleUUID is blank | Equipment path for the MES location where the new sample is initialized. |
Return Value
Type | Description |
|---|---|
CommonSample / QualitySample | Existing sample matching sampleUUID, or a newly created sample based on defUUID and locationPath. Returns None when the current API is called without either a valid sampleUUID or both creation inputs. |
Scope / Availability
Registered on the system.mes.spc.sample script module as getCreateByDefUUID.
The exact getCreateSampleByDefUUID method name is implemented by the legacy SPC 2.0 script class registered under system.quality.sample.data.
Gateway scripts execute locally on the gateway. Designer / Client calls use the quality RPC layer to perform the same sample lookup or creation on the gateway.
Behavior / Edge Cases
Existing sample path: A non-blank sampleUUID takes precedence. The function returns the matching sample and ignores defUUID and locationPath for creation.
New sample path: A blank sampleUUID creates a new sample from defUUID at locationPath.
Blank creation inputs: In the current system.mes.spc.sample API, the function returns None if sampleUUID is blank and either defUUID or locationPath is blank.
Invalid location: The location path must resolve to an MES location that is valid for the sample definition; otherwise sample creation fails or returns no sample depending on call context.
Example Usage
Python |
sample = system.mes.spc.sample.getCreateByDefUUID( "", "8f6f2c8d-7dc8-4dd5-8d1f-1f3c8d9e9a01", "Enterprise\\Site\\Area\\Line 1" ) |
Complex Example
Python |
defUUID = "8f6f2c8d-7dc8-4dd5-8d1f-1f3c8d9e9a01" locationPath = "Enterprise\\Site\\Area\\Line 1" sampleUUID = event.source.parent.getComponent("SampleUUID").text sample = system.mes.spc.sample.getCreateByDefUUID(sampleUUID, defUUID, locationPath) if sample is None: raise ValueError("Unable to find or create the requested SPC sample.") sample.setRefNo("WO-100145") sample.setProductCode("FG-100") sample.setSampleData(1, "Weight", 12.4) system.mes.spc.sample.update(sample, True) |
Related Functions
system.mes.spc.sample.getCreateByDefName() — Returns an existing sample or creates one from a sample definition name.
system.mes.spc.sample.getNewByDefUUID() — Always creates a new sample from a sample definition UUID and location path.
system.mes.spc.sample.getSample() — Returns an existing sample by UUID.
system.mes.spc.sample.update() — Persists changes to a sample and optionally records values.
Sepasoft MES Module Suite