# Zero-Touch Case Study - Grid Node

With a Visual Studio project up and running, we will walk through how to build a custom node that creates a rectangular grid of cells. Though we could create this with several standard nodes, it is a useful tool that can be easily contained in a Zero-Touch node. As opposed to grid lines, cells can be scaled about their center points, queried for their corner vertices, or built into faces.

This example will touch on a few of the features and concepts to be aware of when creating a Zero-Touch node. After we build the custom node and add it to Dynamo, make sure review the Going Further with Zero-Touch page for a deeper look at default input values, returning multiple values, documentation, objects, using Dynamo geometry types, and migrations.

![Rectangular grid graph](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-f15885ed0cf71046e2517406176f39c56fc4f33c%2Fcover-image.jpg?alt=media\&token=1d71c897-21ed-4427-afcc-44ca215ca770)

### Custom Rectangular Grid Node <a href="#custom-rectangular-grid-node" id="custom-rectangular-grid-node"></a>

To start building the grid node, create a new Visual Studio class library project. Refer to the Getting Started page for an in-depth walk-through of how to set up a project.

![Creating a new project in Visual Studio](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-0c1c44e881a5fa5fea9cfefa7f108160bbe94586%2Fvs-new-project-1.jpg?alt=media)

![Configuring a new project in Visual Studio](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-f6cbbcd99aca9527610d3f717c4759e73fd7bb1e%2Fvs-new-project-2.jpg?alt=media\&token=ab805834-8032-4376-a931-34f3630bc0b1)

> 1. Choose `Class Library` for the project type
> 2. Name the project `CustomNodes`

Since we will be creating geometry, we need to reference the appropriate NuGet package. Install the ZeroTouchLibrary package from the NuGet Package Manager. This package is necessary for the `using Autodesk.DesignScript.Geometry;` statement.

![ZeroTouchLibrary package](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-3a5527d378dd6cef925624676aa78bdd4da2a67e%2Fvs-nugetpackage.jpg?alt=media\&token=3fc7d224-4267-461a-bb27-56fbba73ae90)

> 1. Browse for the ZeroTouchLibrary package
> 2. We will be using this node in the current build of Dynamo. Select the package version that matches your Dynamo version.
> 3. Notice that we have also renamed the class file to `Grids.cs`

Next, we need to establish a namespace and class in which the RectangularGrid method will live. The node will be named in Dynamo according to the method and class names. We don't have to copy this into Visual Studio yet.

```
using Autodesk.DesignScript.Geometry;
using System.Collections.Generic;

namespace CustomNodes
{
    public class Grids
    {
        public static List<Rectangle> RectangularGrid(int xCount, int yCount)
        {
        //The method for creating a rectangular grid will live in here
        }
    }
}
```

> `Autodesk.DesignScript.Geometry;` references the ProtoGeometry.dll in the ZeroTouchLibrary package `System.Collections.Generic` is necessary for creating lists

Now we can add the method for drawing the rectangles. The class file should look like this and can be copied into Visual Studio.

```
using Autodesk.DesignScript.Geometry;
using System.Collections.Generic;

namespace CustomNodes
{
    public class Grids
    {
        public static List<Rectangle> RectangularGrid(int xCount, int yCount)
        {
            double x = 0;
            double y = 0;

            var pList = new List<Rectangle>();

            for (int i = 0; i < xCount; i++)
            {
                y++;
                x = 0;
                for (int j = 0; j < yCount; j++)
                {
                    x++;
                    Point pt = Point.ByCoordinates(x, y);
                    Vector vec = Vector.ZAxis();
                    Plane bP = Plane.ByOriginNormal(pt, vec);
                    Rectangle rect = Rectangle.ByWidthLength(bP, 1, 1);
                    pList.Add(rect);
                }
            }
            return pList;
        }
    }
}
```

If the project looks similar to this, go ahead and try to build the `.dll`.

![Building a DLL](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-10e5f1d9c7acf49051b4596bc1cb0240e72ce204%2Fvs-grids.jpg?alt=media\&token=fecb216f-11df-493f-a953-624486135e3c)

> 1. Choose Build > Build Solution

Check the project's `bin` folder for a `.dll`. If the build was successful, we can add the `.dll` to Dynamo.

![Custom nodes in Dynamo](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-0018f5de3a3b99dc6c9178d904958ca5918cf830%2FRectangularGrid-Dynamo.png?alt=media)

> 1. The custom RectangularGrids node in the Dynamo Library
> 2. The custom node on the canvas
> 3. The Add button for adding the `.dll` to Dynamo

### Custom Node Modifications <a href="#custom-node-modifications" id="custom-node-modifications"></a>

In the example above, we created a fairly simple node that didn't define much else outside of the `RectangularGrids` method. However, we may want to create tooltips for input ports or give the node a summary like the standard Dynamo nodes. Adding these features to custom nodes makes them easier to use, especially if a user wants to search for them in the Library.

![Input tooltip](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-67f803e4a7fd71dbc34b2d7aecaae8d2f9f30218%2Fnodemodification.png?alt=media\&token=053775e6-1d03-4ae7-ba08-3f7727a0a556)

> 1. A default input value
> 2. A tool tip for the xCount input

The RectangularGrid node needs some of these basic features. In the code below, we have added input and output port descriptions, a summary, and default input values.

```
using Autodesk.DesignScript.Geometry;
using System.Collections.Generic;

namespace CustomNodes
{
    public class Grids
    {
        /// <summary>
        /// This method creates a rectangular grid from an X and Y count.
        /// </summary>
        /// <param name="xCount">Number of grid cells in the X direction</param>
        /// <param name="yCount">Number of grid cells in the Y direction</param>
        /// <returns>A list of rectangles</returns>
        /// <search>grid, rectangle</search>
        public static List<Rectangle> RectangularGrid(int xCount = 10, int yCount = 10)
        {
            double x = 0;
            double y = 0;

            var pList = new List<Rectangle>();

            for (int i = 0; i < xCount; i++)
            {
                y++;
                x = 0;
                for (int j = 0; j < yCount; j++)
                {
                    x++;
                    Point pt = Point.ByCoordinates(x, y);
                    Vector vec = Vector.ZAxis();
                    Plane bP = Plane.ByOriginNormal(pt, vec);
                    Rectangle rect = Rectangle.ByWidthLength(bP, 1, 1);
                    pList.Add(rect);
                    Point cPt = rect.Center();
                }
            }
            return pList;
        }
    }
}
```

* Give the inputs default values by assigning values to the method parameters: `RectangularGrid(int xCount = 10, int yCount = 10)`
* Create input and output tooltips, search keywords, and a summary with XML documentation preceded by `///`.

To add tooltips, we need an xml file in the project directory. A `.xml` can be automatically generated by Visual Studio by enabling the option.

![Enabling XML documentation](https://1734247194-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY5ZuHF3yuXFWp1C46ZSo%2Fuploads%2Fgit-blob-7d6e0fd9bc48b7367e30f552c047473ef77a2d73%2Fvs-xml.jpg?alt=media)

> 1. Enable XML documentation file here and specify a file path. This generates an XML file.

That's it! We have created a new node with several standard features. The following chapter Zero-Touch Basics goes into greater detail about Zero-Touch node development and the issues to be aware of.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://primer2.dynamobim.org/1_developer_primer_intro/3_developing_for_dynamo/2-zero-touch-case-study-grid-node.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
