Grasshopper Loop
(by Chuyun0316)
This is a simple loop tool for Grasshopper with 2 components, "Begin" and "End". The loop is realized with a static member in C#.
Support Email

This is a simple loop tool for Grasshopper with 2 components, "Begin" and "End". The loop is realized with a static member in C#.

It's very easy to use, check the following link and you will soon understand. https://youtu.be/8w1bSe2GFCs

This tool can work with a Tree of any datatype in GH, different datatypes in one tree also allowed. However, only one pair of "Begin" and "End" in one GH window, which means you can only one loop.

The mechanism is that the "End" Component will write the values of the input data tree into a static member in the memory, and the "Begin" component will the tree out when triggered by a timer.

 

To install:

  • In Grasshopper, choose File > Special Folders > Components folder. Save the gha file there.
  • Right-click the file > Properties > make sure there is no "blocked" text
  • Restart Rhino and Grasshopper

 

This tool is open sourced and I'm new to C#. The core source codes are posted here. Please make comments. There are 3 class, "Begin", "End" and another class containing a static member.

    public class Class1
    {
        static GH_Structure<IGH_Goo> tree;
        public GH_Structure<IGH_Goo> Tree
        {
            set { tree = new GH_Structure<IGH_Goo>(value, false); }
            get { return tree; }
        }
    }

 

    public class StaticLoopComponent: GH_Component
    {

        ......

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.SetDataTree(0, new Class1().Tree);
        }

        ......
    }

 

    public class EndComponent : GH_Component
    {
        ......
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure<IGH_Goo> tree;
            DA.GetDataTree(0, out tree);
            Class1 cla = new Class1();
            cla.Tree = tree;
        }
        ......
    }

- Mark Kou

License:
Reviews