-
Notifications
You must be signed in to change notification settings - Fork 624
/
HelloDynamoZeroTouch.cs
192 lines (170 loc) · 7.43 KB
/
HelloDynamoZeroTouch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using System;
using System.Collections.Generic;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Interfaces;
using Autodesk.DesignScript.Runtime;
namespace SampleLibraryZeroTouch
{
/// <summary>
/// The HelloDynamoZeroTouch class demonstrates
/// how to create a class in a zero touch library
/// which creates geometry, and exposes public
/// methods and properties as nodes.
/// </summary>
public class HelloDynamoZeroTouch : IGraphicItem
{
//OPTIONAL:
//IGraphicItem is an interface which allows your
//class to participate in the rendering of geometry
//to the background preview, and to Watch3D nodes.
//You do not need to implement IGraphicItem unless
//your node needs to draw geometry to the view.
private Point point;
//--------------------------------------------------
//A NOTE ON XML COMMENTS:
//Dynamo uses the comments you've put on your code to
//populate tooltips and help windows in the user
//interface. In order to enable this behavior, your
//project needs to be set to build xml
//documentation. To do this:
//1. Right click on your project in the solution explorer.
//2. Select Properties.
//3. Select the Build tab.
//4. Check the XML Documentation box.
//The generated xml file will be called the same
//thing as your library, and needs to live along-side
//your library to be picked up by the Dynamo loader.
//--------------------------------------------------
/// <summary>
/// Properties marked as public will show up as
/// nodes in the Query section of the dynamo library.
/// </summary>
public double Awesome { get { return 42.0; } }
/// <summary>
/// The Point stored on the object.
/// </summary>
public Point Point { get { return point; } }
/// <summary>
/// Properties and methods marked as internal will not
/// be visible in the Dynamo UI.
/// </summary>
internal double InvisibleProperty { get { return 42.0; } }
/// <summary>
/// Private methods, such as this constructor,
/// will not be visible in the Dynamo library.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
private HelloDynamoZeroTouch(double x, double y, double z)
{
point = Point.ByCoordinates(x, y, z);
}
/// <summary>
/// Dynamo uses the pattern of static constructors.
/// Don't forget to fill in the xml comments so that
/// you will get help tips in the UI. You can also use
/// default parameters, as we have here. With default
/// parameters defined, you will not be required to attach
/// any inputs to these ports in Dynamo.
/// </summary>
/// <param name="x">The x coordinate of the point.</param>
/// <param name="y">The y coordinate of the point.</param>
/// <param name="z">The z coordinate of the point.</param>
/// <returns>A HelloDynamoZeroTouch object.</returns>
public static HelloDynamoZeroTouch ByCoordinates(double x=42.0, double y=42.0, double z=42.0)
{
// Let's say in our example that the user is not allowed
// to create an instance of this class if any of the
// coordinates is less than zero. We check the parameters
// here because passing to the private constructor, and
// we throw an error if the parameters do not conform.
// These exceptions will be shown in the error bubble
// over the node, and the node will turn yellow.
if (x < 0)
{
throw new ArgumentException("x");
}
if (y < 0)
{
throw new ArgumentException("y");
}
if (z < 0)
{
throw new ArgumentException("z");
}
return new HelloDynamoZeroTouch(x, y, z);
}
/// <summary>
/// The MultiReturn attribute can be used to specify
/// the names of multiple output ports on a node that
/// returns a dictionary. The node must return a dictionary
/// to be recognized as a multi-out node.
/// </summary>
/// <returns></returns>
[MultiReturn(new[] { "thing 1", "thing 2" })]
public static Dictionary<string, List<string>> MultiReturnExample()
{
return new Dictionary<string, List<string>>()
{
{ "thing 1", new List<string>{"apple", "banana", "cat"} },
{ "thing 2", new List<string>{"Tywin", "Cersei", "Hodor"} }
};
}
/// <summary>
/// OPTIONAL:
/// Overriding ToString allows you to control what is
/// displayed whenever the object's string representation
/// is used. For example, ToString is called when the
/// object is displayed in a Watch node.
/// </summary>
/// <returns>The string representation of our object.</returns>
public override string ToString()
{
return string.Format("HelloDynamoZeroTouch:{0},{1},{2}", point.X, point.Y, point.Z);
}
#region IGraphicItem interface
/// <summary>
/// The Tessellate method in the IGraphicItem interface allows
/// you to specify what is drawn when dynamo's visualization is
/// updated.
/// </summary>
/// <param name="package">The IRenderPackage object into which you push your render data</param>
/// <param name="tol">An optional tessellation tolerance which defines the resolution
/// of generated meshes for surfaces.</param>
/// <param name="maxGridLines">An optional tesselation tolerance which specifies the maximum number
/// of surface subdivisions to be used for tesselation.</param>
[IsVisibleInDynamoLibrary(false)]
public void Tessellate(IRenderPackage package, double tol = -1, int maxGridLines = 512)
{
// This example contains information to draw a point
package.PushPointVertex(point.X, point.Y, point.Z);
package.PushPointVertexColor(255, 0, 0, 255);
}
#endregion
}
/// <summary>
/// By decorating a class with the
/// IsVisibleInDynamoLibrary attribute, and setting
/// it to false, you are saying that you want this member
/// to be available to the VM, but not be visible in the
/// library view or search.
///
/// By decorating a class with the SupressImportIntoVM
/// attribute, you are saying that you do not want to import
/// this class into Dynamo. BE CAREFUL! This class will then
/// be unavailable to others that might reference it. In most
/// cases, adding IsVisibleInDynamoLibrary(false) will suffice
/// to hide your method from view without needing to disable
/// its import completely.
/// </summary>
[SupressImportIntoVM]
[IsVisibleInDynamoLibrary(false)]
public class DoesNotImportClass
{
/// <summary>
/// DoesNotImportClass constructor.
/// </summary>
public DoesNotImportClass(){}
}
}