-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHelloNodeModel.cs
More file actions
47 lines (43 loc) · 1.49 KB
/
HelloNodeModel.cs
File metadata and controls
47 lines (43 loc) · 1.49 KB
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
using System;
using System.Collections.Generic;
using Dynamo.Graph.Nodes;
using HelloDynamo.Hello;
using ProtoCore.AST.AssociativeAST;
namespace HelloDynamo.HelloNodeModel
{
/// <summary>
/// Sample NodeModel
/// In order to execute AstFactory.BuildFunctionCall
/// the methods have to be in a separate assembly and be loaded by Dynamo separately
/// File pkg.json defines which dll are loaded
/// </summary>
[NodeName("HelloNodeModel")]
[NodeDescription("Example Node Model, multiplies AxB")]
[NodeCategory("HelloDynamo")]
[InPortNames("A", "B")]
[InPortTypes("double", "double")]
[InPortDescriptions("Number A", "Numnber B")]
[OutPortNames("C")]
[OutPortTypes("double")]
[OutPortDescriptions("Product of AxB")]
[IsDesignScriptCompatible]
public class HelloNodeModel : NodeModel
{
public HelloNodeModel()
{
RegisterAllPorts();
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
if (!HasConnectedInput(0) || !HasConnectedInput(1))
{
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
}
var functionCall =
AstFactory.BuildFunctionCall(
new Func<double, double, double>(SampleFunctions.MultiplyTwoNumbers),
new List<AssociativeNode> { inputAstNodes[0], inputAstNodes[1] });
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
}
}
}