Working with External Files in MCG

The Max Creation Graph includes a number of nodes for reading data from and saving data to external files. Follow these guidelines for the best results and performance.

Reading data from files

The first step for reading a file is to use a Parameter: Asset node. This provides a button in the tool's rollout that opens a browser to let users specify a file.

The selected file is treated like any other asset in a scene. For example, it appears in the Asset Tracking dialog and is included when archiving.

In the graph, the Parameter: Asset node returns the file path as a string. This must be connected to another node to read and process the data, depending on the file type. There are several options:
  • CSV (comma-separated values). This is a common format for importing and exporting data from spreadsheets and other applications. Connect the output from the Parameter: Asset node to a ReadCSVData node, and also connect a string to specify the separator (it does not need to be a comma). The output is an array of string arrays — depending on your data file's structure, you may need to discard some header and footer rows. After that you can use nodes from the Array and Type categories to convert the arrays from strings to other value types like integers or singles. For an example, you can look at the graph for the installed CFDImportData.maxtool.
  • Bitmaps. Use LoadBitmapFromFile to read a bitmap in BMP, GIF, JPG, PNG or TIFF format. After that, connect the output Bitmap to nodes in the Maps/Bitmaps category like GetPixels, BitmapHeight, and BitmapWidth to work with the data.
  • VDB. Use nodes from the OpenVDB category to extract data from the file. For example, you can use GetGridNames to get an array of grid names, and then use one of those names to get the grid's values or vertices.

In most cases, you want to avoid rereading files every time the tool is evaluated. One way to do this is to cache the data (after any processing, if appropriate) with CacheValueUntilControlChanged using the file-name string as the control input so that the cache gets refreshed only when the file name has been changed. Alternatively, you can try using CreateStaticCache, together with Parameter: Signal to allow users to click a button to force the cache to update .

Writing data to files

You can save bitmap and OpenVDB files from MCG-based tools.