The SDK
A generator's file has one default export, made with defineGenerator from @classcad/pdm-generator. The function gets everything it needs:
export default defineGenerator<{ width: number }>(async ({ params, api, savePart, saveAssembly, readAsset, readAssetBase64, log }) => {
// …
})
params | Every parameter of the run: the form's values, the manifest's defaults for the rest |
api | ClassCAD: api.v1.<domain>.<call>(param). A ClassCAD error becomes an exception |
savePart({ key, name }) | Saves the part as the output key. Without a name, the PDM makes one from the parameters |
saveAssembly({ key, name }) | The same for an assembly, with all its parts in one file |
readAsset(path), readAssetBase64(path) | A file from the generator's directory, a template model for example: api.v1.common.load({ data: readAssetBase64('Template.ofb'), encoding: 'base64', format: 'OFB' }) |
log.info(), log.warn() | Lines in the run's log |
Every run gets a ClassCAD session of its own, opened on the first call and closed at the end.
Saying no. Throw an error and the run fails with your message, word for word, for example when parameters don't fit together. The PDM doesn't retry it, since it would fail again.
What a generator may import. Only files in its own directory, by relative path, and @classcad/pdm-generator. Packages from npm and Node's own modules (fs, net, …) aren't allowed yet. Assets go into the directory. The whole directory may be up to 5 MB.
How long. A run stops after 300 seconds unless the worker allows more (RUN_TIMEOUT_S).