1. Home
  2. Docs
  3. LunchBox Documentation
  4. Grasshopper Components
  5. Data

Data

LunchBox’s Data components allow users to structure their Grasshopper and Rhino data into tabular formats and export it as a variety of file types.

The included viewers also allow users to create charts and data grids from within Grasshopper, and export the results.


Component Descriptions

Below, each component is described and visual examples are given. We’ve also included special Notes and Tips that can help users with less familiar situations.


Description

Appearance


Create DataSet

Allows users to combine multiple DataTables to create a DataSet.

DataSets allow users to structure interrelated data in a tabular format, where each row corresponds to a record number.


Input:

  • A text-based Name for the resulting dataset.
  • The tables to include within the dataset.

Returns: A DataSet.

Data Set Example

Create DataTable

Creates a tabular DataTable where the provided “Headers” are columns, and the “Values” are rows.

Permitted Value types include numerical data (integers or whole numbers), nominal data (text-based or alphanumerical such as a list of GUIDs), or boolean data (such as a list of True/False values).

Input:

  • A text-based Name, or title, for the Data Table
  • A list of text-based Header names for each column of data
  • A structured list of Values that correspond to each Header. Each value will become a row in the DataTable.

Returns: A DataTable

Tip: Ensure that text panels are set to Multiline data to function properly as lists. Right click on the panel and click “Multiline Data” to toggle this function on and off.

Data Table Component
In this example, Random Numbers are being generated to input as Values.
Tip: Ensure that text parameters are set to Multiline Data

Create JSON

Allows users to export a DataSet as a JSON file to a specified location.

Input:

  • A boolean toggle to execute the write function
  • A file path with the extension .json, where the file will be written. Tip: the Grasshopper “File Path” component can be used.
  • A DataSet

After executing the function, verify the JSON file has been created at the specified destination.

Note: If the boolean toggle is set to “True” and any changes are made to the grasshopper definition, the file will be overwritten. It is best practice to reset the toggle to “False” after creating file to avoid issues.

Important Formatting Note: JSON field names cannot contain spaces. Ensure that Header Names do not have spaces.

Create JSON example
Create JSON example with resulting JSON data shown.

Create XML

Allows users to export a DataSet as an XML file.

Input:

  • A boolean toggle to execute the write function
  • A file path with the extension .xml, where the file will be written. Tip: the Grasshopper “File Path” component can be used.
  • A DataSet

After executing the function, verify the XML file has been created at the specified destination

Note: If the boolean toggle is set to “True” and any changes are made to the grasshopper definition, the file will be overwritten. It is best practice to reset the toggle to “False” after creating file to avoid issues.

Create XML example
Create XML example, with the resulting XML data shown.

Create XML (Data Tree)

There are two components called “Create XML”. This one allows users to export the DataTree structure of a dataset as an XML file. The tree-like icon indicates this component is intended to be used for DataTrees rather than Data Sets. The input values also reflect the difference.

Input:

  • A boolean toggle to execute the write function
  • A file path with the extension .xml, where the file will be written. Tip: the Grasshopper “File Path” component can be used.
  • A dataset

Returns: A DataTree definition written as an XML file.

After executing the function, verify the XML file has been created at the specified destination.

Note: If the boolean toggle is set to “True” and any changes are made to the grasshopper definition, the file will be overwritten. It is best practice to reset the toggle to “False” after creating file to avoid issues.

Create XML DataTree example

Read XML by Tag

Allows users to read XML data by tag.

Learn more about XML tags here (outbound link).

Input:

  • An XML
  • A tag, or list of tags

Returns: The values associated with the given tags from the specified dataset

Read XML by Tag example

Create CSV

Allows users to create a CSV (which stands for Comma Separated Values) text-based list. CSV files are commonly used to transfer data between programs.

Input:

  • A list of Headers. Tip: If using a panel, ensure that it is set to Multiline Data.
  • A structured list of Values corresponding to the specified Headers.
  • A delimiter, which will separate the values. The default is a comma. A text-based panel can be used to customize the delimiter.

Returns: Text in a CSV format.


To save the resulting CSV as a .csv file,

  1. Right click on the text panel
  2. Select “Copy Data Only”
  3. Open a Notepad
  4. Paste the data
  5. Save the Notepad’s text file as a .csv (example: “filename.csv”)
Create CSV example.
In this example, a list of random integers are given as values.
Create CSV example results.
Right click on the text panel to copy the data.
Paste the data into a Notepad and save it as a .csv file

Read CSV

Allows users to read the contents of a CSV, separating the headers from the values.

Input:

  • The contents of a CSV in a text-based format.
  • The delimiter used in the CSV. The default delimiter is a comma.

Returns: The headers and values from the CSV file, separated into their respective lists.

Read CSV example
In this example, we used a “File Path” component to specify a CSV, and a “Read file” component to return its contents in a text based format.

Convert JSON to XML

Allows users to convert XML files to JSON files.

Input:

  • A JSON string. In the example to the right, we are using a file path component to specify an XML file and a Read File component to read the file contents.

Returns: The data from the JSON, reformatted as an XML.


Convert XML to JSON

Allows users to convert XML files to JSON files.

Input:

  • An XML string. In the example to the right, we are using a file path component to specify an XML file and a Read File component to read the file contents.

Returns: The data from the XML, reformatted as a JSON

Tip: Ensure the “Read File” component is set to Total File and not “Per Line”. Right click on the component and select “Per Line” to toggle modes.

Convert XML to JSON example
Tip: Ensure the Read File component is set to read the total file, not line by line.

Create Chart

Allows users to create a WinForm chart and save it as a JPEG.

Learn more about WinForm charts here (outbound link).

Input:

  • A chart name, as text
  • A list of Series names
  • A list of X-Axis labels
  • A structured list of Values, corresponding to the specified X-axis labels and Series.

Returns: List of Property Fields.


To use:

  • Input the variables to the component
  • Right click on the component icon. A menu with the option to “View Chart…” should appear.
  • Select “View Chart…”. A window with a chart will open.
  • The chart type and color scheme can be edited by selecting an option in each of the drop down menus at the bottom of the window.
  • Select the “Save Chart” button. A file browser window will open.
  • Specify the file location and name, then hit Save. A JPEG of the chart will be saved.
  • Select “Close” to close out of the WinForm chart editor window and return to Grasshopper.

Supported Chart Types:

  • Bar
  • Column
  • Line
  • Point
  • Spline
  • Stacked Area
  • Stacked Column
  • Stacked Bar
  • Step Line
Create Chart example
To illustrate the component, random integers are used as Values.
Right click on the component icon to see the “View Chart” button.
Chart window example
Color selection example
Chart type selection example

Create Data Grid

Allows users create and view their data in a Grid format, like a spreadsheet.

Input:

  • A list of Header Names
  • A tree of numeric Values, where each branch corresponds to a header in the specified order.

To use:

  • Input the required variables
  • Right click on the component icon. A menu containing “View Data Grid” should appear.
  • Select “View Data Grid”. The LunchBox DataGrid View window should appear.
  • If desired, Values can be copied (Select and CTRL+C) and pasted (CTRL+V) to a Notebook or empty spreadsheet to create a CSV.
  • Select close to return to Grasshopper.

How can we help?