How to upload files

A how-to guide for uploading files in your solution.

Introduction

Would you like to import data, drawings or 3D geometry to use in your Rhino Grasshopper definition? Then upload files in your solution by following these steps.

Prerequisites

  • You configured the frames and routes for your solution.
  • You configured the relevant contents such as the model(s), viewer(s) and datastore.
  • You have a Rhino Grasshopper definition using the Packhunt input components.

1. Add a file control

To upload files in the solution, configure a File control in your ControlPanel

  • Define a control with kind: File .
  • Optionally define which file types are accepted with the acceptFileExtensions property.

The configuration should look similar to the example below:

  my-control-panel:
	kind: ControlPanel
	my-file:
	    kind: File
	    acceptFileExtensions:
	      - .json

2. Subscribe your model to the control panel

To use the uploaded file in the model,

  • Subscribe the Model to the ControlPanel .
  • Define the frame and source.
  my-model:
      kind: Model
      modelFile: my-model.gh
      subscribe:
        - kind: ControlPanel
          frame: home-frame
          source: my-control-panel  

3. Use the file in your Grasshopper logic

The file control returns the asset as an input. To include the file in your Rhino Grasshopper logic:

  • Place a Packhunt input component matching the file controls name.
  • Use the Packhunt DownloadAsset component to get the file path.
  • Retrieve the file contents:
    • For geometry files you can use the Grasshopper Import3DM component.
    • For text based files, you can use the Grasshopper ReadFile component.
    • Use the file contents in your Grasshopper logic as usual.

Optionally test your Grasshopper logic locally
While making changes to your Grasshopper file, you can use test data for the file input. To generate test data:

  • Use the Packhunt Create File component to create a file containing test data.
  • Use the Packhunt Create Asset component to generate an asset from the file.
  • Connect that asset to the Packhunt Input component.

See the image below for an example Grasshopper definition.

See the image below as an example.

Configuration

See the file control configuration docs for more information.