Custom Exporters

Creating a custom exporter is just like writing a function, with a few small differences:
  • Exporters don’t run on any change to your workflow — they only run on-demand when a user clicks a download / export button.
  • Exporters don’t show up in the Workflow panel. They show up as buttons when you click the Export button:
notion image
  • Exporters cannot add anything to the Model, such as adding new elements or geometry.

How to create an exporter

  1. Create a new function with hypar new — just like any other C# function.
  1. Open hypar.json and edit the $schema property of the function to be
{ "$schema": "", "id": "[SOME_GUID_HERE]", "name": "STL Export", ... }
  1. Make sure to add model_dependencies to your function, which specify the models your exporter needs access to. In this example, the exporter creates an STL file from Location and Envelope, both optionally:
"model_dependencies": [ { "name": "location", "optional": true }, { "name": "Envelope", "optional": true } ],
  1. Your exporter may export one or more file types. For each type of file you want to make available for export, add a FileDestination input to input_schema, like so.
The $hyparFileExtension value is required — without this the exporter will fail!
"input_schema": { "type": "object", "properties": { "Download STL": { "$ref": "", "$hyparFileExtension": "stl" }, "Download Text Report": { "$ref": "", "$hyparFileExtension": "txt" } } },
You may also add regular inputs to the input_schema, like number or text fields, if you need to supply configurable settings for your exporter.
  1. Run hypar init to update the generated code for your function.
  1. In your function code, create the file you want the user to download. You will use the FileDestination object to pass a file back out to the user. Here are a few examples:

Simple text export

var txtDestination = input.DownloadTextReport; // grab the destination string myTextFileContents = "Hello, world!"; // call SetExportTextContents to create an export text file txtDestination.SetExportTextContents(myTextFileContents);

Read a file from disk

var destination = input.DownloadSTL; // grab the destination // write to a temporary local file (see note below *) var tempFilePath = Path.GetTempFileName(); stl.Save(tempFilePath); // create a stream reading from the file path var readStream = File.OpenRead(tempFilePath); // set that stream as the export stream destination.SetExportStream(readStream);
In any Hypar function, you’re only allowed to write files to the system temp directory. Use Path.GetTempFileName or Path.GetTempPath.

Stream directly to export

Don’t close the stream you set as the Export stream (e.g. with a using statement) — Hypar’s API needs access to it after that, and we’ll take care of closing it for you.
var destination = input.DownloadSTL; // grab the destination from input var stream = new MemoryStream(); // create a new stream // do something with that stream // (this example uses a library which can "Save" directly to a stream) stl.Save(stream); // call SetExportStream on the destination destination.SetExportStream(stream); // This line will not be necessary in newer versions // of the `Hypar.Functions` library. stream.Seek(0, SeekOrigin.Begin);
  1. Publish your function with hypar publish to be able to use it on Hypar.

How to use an exporter

Your new exporter won’t be available in the Export menu immediately. You have to add it to the workflow, just like any other function (note: this is likely to change eventually).
notion image
Once added, you’ll see it show up in the export menu:
notion image
When you click the button, you’ll see the inputs/settings of your exporter, including the File Destinations as download buttons.
notion image