The Import Stream component is a way to let online users upload any file that can be used as input to the Grasshopper definition. The component outputs a Memory Stream object, which then needs to be parsed through scripts or third-party plugins in order to extract its contents.
This component is one of several components of the ShapeDiver plugin that can be used to import files in online ShapeDiver models. Read more about the general principles of all ShapeDiver Import components.
In this example, a
.jpg file is imported using the Import Stream component. The imported Memory Stream object is then parsed using a small C# script converting it to a bitmap object:
private void RunScript(object S, ref object B)
Stream stream = (Stream) S;
stream.Position = 0;
B = Image.FromStream((Stream) S);
It is then previewed using the Quick Preview component of Squid and can be used for multiple other applications in Grasshopper.
Note that this example is only provided to explain how the Import Stream component works. In most cases, an image should be imported using the classic Import Bitmap component. The component becomes really useful for those file formats that can not be imported directly as Grasshopper-compatible objects. Think, for example, about Excel files.
Supported file formats
Theoretically, any file format can be imported into Grasshopper using this component. However, for security reasons, we curate a list of allowed formats for now. Right-click on the component to see the exhaustive list of available formats and select which ones should be allowed to be imported by the component.
Among other available formats, the component allows .xlsx (Microsoft Excel) files, .docx (Microsoft Word) files, .zip files…
Let us know through the forum if you want us to add more formats to the list.
Handling imported streams
Unlike other Import components of the ShapeDiver plugin, the component does not extract the contents of imported files into Grasshopper objects automatically. Instead, it outputs three objects:
Stream (S): A Memory Stream object.
ContentType (C): the MIME type of the imported file (for example:
FileEnding (F): the extension of the imported file (for example:
The data contained in the Memory Stream object needs to be parsed and extracted using methods that are often specific to the format of the imported file. In the example above, we used a script to convert the stream to a bitmap object.