# Zero-Touch 案例研究 - 網格節點

#### 自訂矩形網格節點

1. 選擇「`Class Library`」做為專案類型

2. 將專案命名為 `CustomNodes`

1. 瀏覽 ZeroTouchLibrary 套件

2. 我們將在 Dynamo Studio 的目前建置 (1.3) 中使用此節點。選取與此相符的套件版本。

3. 請注意，我們也已將類別檔案更名為 `Grids.cs`

``````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;` 參考 ZeroTouchLibrary 套件中的 ProtoGeometry.dll。建立清單需要 `System.Collections.Generic`

``````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);
}
}
return pList;
}
}
}``````

1. 選擇「建置」>「建置方案」

1. Dynamo 資源庫中的自訂 RectangularGrids 節點

2. 圖元區上的自訂節點

3. `.dll` 加入 Dynamo 的「加入」按鈕

#### 修改自訂節點

1. 預設輸入值

2. xCount 輸入的工具提示

RectangularGrid 節點需要某些基本功能。在以下程式碼中，我們加入了輸入埠和輸出埠的描述、摘要和預設輸入值。

``````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);
Point cPt = rect.Center();
}
}
return pList;
}
}
}``````
• 對方法參數指定值來提供輸入預設值：`RectangularGrid(int xCount = 10, int yCount = 10)`

• 建立輸入和輸出的工具提示、搜尋關鍵字，以及 XML 文件前面有 `///` 的摘要。

1. 在此啟用 XML 文件檔案並指定檔案路徑。這會產生 XML 檔案。

Last updated