├── src
└── Essentials
│ ├── NodeModelsEssentials
│ ├── images
│ │ └── logo.png
│ ├── README.md
│ ├── pkg.json
│ ├── Controls
│ │ ├── SliderBound.xaml.cs
│ │ ├── StateDynamoControl.xaml.cs
│ │ ├── MyFirstDynamoControl.xaml.cs
│ │ ├── StateDynamoControl.xaml
│ │ ├── MyWpfView.xaml.cs
│ │ ├── CopyableWatch.xaml
│ │ ├── MyWpfView.xaml
│ │ ├── SliderBound.xaml
│ │ ├── MyFirstDynamoControl.xaml
│ │ └── CopyableWatch.xaml.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── packages.config
│ ├── EssentialsError.cs
│ ├── EssentialsTimeout.cs
│ ├── GeometryUVPlanesOnSurface.cs
│ ├── GeometrySurfaceFrom4Points.cs
│ ├── GeometryWobblySurface.cs
│ ├── UIButton.cs
│ ├── EssentialsMultiOperation.cs
│ ├── EssentialsEvents.cs
│ ├── UISlider.cs
│ ├── UIButtonFunction.cs
│ ├── EssentialsDataBridge.cs
│ ├── EssentialsAstNotReusingFunctionCall.cs
│ ├── UISliderBound.cs
│ ├── app.config
│ ├── EssentialsAstReusingFunctionCall.cs
│ ├── EssentialsMultiply.cs
│ ├── GeometryCustomPreview.cs
│ ├── UIState.cs
│ ├── UICopyableWatch.cs
│ └── NodeModelsEssentials.csproj
│ ├── NodeModelsEssentialsFunctions
│ ├── images
│ │ └── logo.png
│ ├── README.md
│ ├── packages.config
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── NodeModelsEssentialsFunctions.csproj
│ └── NodeModelsEssentialsFunctions.cs
│ ├── NodeModelsEssentials.sln
│ └── samples
│ ├── 01_MovingSphere.dyn
│ ├── 02_Surface.dyn
│ └── 03_SurfaceRotation.dyn
├── LICENSE
├── README.md
└── .gitignore
/src/Essentials/NodeModelsEssentials/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonoesp/DynamoNodeModelsEssentials/HEAD/src/Essentials/NodeModelsEssentials/images/logo.png
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nonoesp/DynamoNodeModelsEssentials/HEAD/src/Essentials/NodeModelsEssentialsFunctions/images/logo.png
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/README.md:
--------------------------------------------------------------------------------
1 |
2 | # NodeModelsEssentials
3 |
4 | Visual Studio project that generates the main DLL assembly with the Node Model components. It calls functions that live in a separate assembly, `NodeModelsEssentialsFunctions`.
5 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/README.md:
--------------------------------------------------------------------------------
1 |
2 | # NodeModelsEssentialsFunctions
3 |
4 | Visual Studio project that generates a DLL assembly with functions used by `NodeModelsEssentials` components. This functions need to live in a separate assembly to properly function.
5 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/pkg.json:
--------------------------------------------------------------------------------
1 | { "license":"MIT", "file_hash":null, "name":"DynamoNodeModelsEssentials", "version":"1.0.0", "description":"Dynamo node samples.", "group":"DynamoNodeModelsEssentials", "keywords":[ "dynamo", "samples", "essentials"], "dependencies":[], "contents":"Sample Dynamo nodes.", "engine_version":"1.0.0", "engine":"dynamo", "engine_metadata":"", "site_url":"", "repository_url":"", "contains_binaries":true, "node_libraries":[ "NodeModelsEssentials, Version=1.0.0, Culture=neutral, PublicKeyToken=null", "NodeModelsEssentialsFunctions, Version=1.0.0, Culture=neutral, PublicKeyToken=null"]}
2 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/SliderBound.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace NodeModelsEssentials.Controls
17 | {
18 | ///
19 | /// Interaction logic for SliderBound.xaml
20 | ///
21 | public partial class SliderBound : UserControl
22 | {
23 | public SliderBound()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/StateDynamoControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace NodeModelsEssentials.Controls
17 | {
18 | ///
19 | /// Interaction logic for StateDynamoControl.xaml
20 | ///
21 | public partial class StateDynamoControl : UserControl
22 | {
23 | public StateDynamoControl()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/MyFirstDynamoControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace NodeModelsEssentials.Controls
17 | {
18 | ///
19 | /// Interaction logic for MyFirstDynamoControl.xaml
20 | ///
21 | public partial class MyFirstDynamoControl : UserControl
22 | {
23 | public MyFirstDynamoControl()
24 | {
25 | InitializeComponent();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/StateDynamoControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/MyWpfView.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace NodeModelsEssentials.Controls
17 | {
18 | ///
19 | /// Interaction logic for MyWpfView.xaml
20 | ///
21 | public partial class MyWpfView : UserControl
22 | {
23 | public Button button;
24 |
25 | public MyWpfView()
26 | {
27 | InitializeComponent();
28 | button = this.FindName("aButton") as Button;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/CopyableWatch.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/MyWpfView.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Nono Martínez Alonso
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("NodeModelsEssentials")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NodeModelsEssentials")]
13 | [assembly: AssemblyCopyright("Copyright © 2017, Nono Martinez Alonso (nono.ma)")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ce1b1314-876a-4579-ab8f-5e9b7eeb9954")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.13
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeModelsEssentials", "NodeModelsEssentials\NodeModelsEssentials.csproj", "{CE1B1314-876A-4579-AB8F-5E9B7EEB9954}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NodeModelsEssentialsFunctions", "NodeModelsEssentialsFunctions\NodeModelsEssentialsFunctions.csproj", "{F519DEE9-84FF-4331-B5C8-131C4A684670}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {CE1B1314-876A-4579-AB8F-5E9B7EEB9954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {CE1B1314-876A-4579-AB8F-5E9B7EEB9954}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {CE1B1314-876A-4579-AB8F-5E9B7EEB9954}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {CE1B1314-876A-4579-AB8F-5E9B7EEB9954}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {F519DEE9-84FF-4331-B5C8-131C4A684670}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {F519DEE9-84FF-4331-B5C8-131C4A684670}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {F519DEE9-84FF-4331-B5C8-131C4A684670}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {F519DEE9-84FF-4331-B5C8-131C4A684670}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("NodeModelsEssentialFunctions")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Autodesk")]
12 | [assembly: AssemblyProduct("NodeModelsEssentialFunctions")]
13 | [assembly: AssemblyCopyright("Copyright © 2017, Nono Martinez Alonso (nono.ma)")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("f519dee9-84ff-4331-b5c8-131c4a684670")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/SliderBound.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/MyFirstDynamoControl.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsError.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using System.Linq;
7 | using Newtonsoft.Json;
8 |
9 | namespace NodeModelsEssentials
10 | {
11 | //
12 | // Sample Node Model called MultiplyMulti.
13 | // It returns the product of two numbers and a verbose string.
14 | //
15 | [NodeName("Essentials.Error")]
16 | [NodeDescription("Throw a custom warning when something fails.")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [InPortNames("In")]
19 | [InPortTypes("string")]
20 | [InPortDescriptions("A string.")]
21 | [OutPortNames("Out")]
22 | [OutPortTypes("string")]
23 | [OutPortDescriptions(
24 | "Resulting string.")]
25 | [IsDesignScriptCompatible]
26 |
27 | public class Error : NodeModel
28 | {
29 | [JsonConstructor]
30 | private Error(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
31 | {
32 | }
33 |
34 | public Error()
35 | {
36 | RegisterAllPorts();
37 | }
38 |
39 | public override IEnumerable BuildOutputAst(List inputAsNodes)
40 | {
41 | if (!InPorts[0].Connectors.Any())
42 | {
43 | return new[] {
44 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())
45 | };
46 | }
47 |
48 | var errorFunctionNode =
49 | AstFactory.BuildFunctionCall(
50 | new Func(NodeModelsEssentialsFunctions.Error),
51 | new List { inputAsNodes[0] });
52 |
53 | return new[] {
54 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), errorFunctionNode)
55 | };
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/Controls/CopyableWatch.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 | using System.Threading;
16 | using System.Windows.Threading;
17 |
18 | namespace NodeModelsEssentials.Controls
19 | {
20 | ///
21 | /// Interaction logic for CopyableWatch.xaml
22 | ///
23 | public partial class CopyableWatch : UserControl
24 | {
25 | private string currentText = "";
26 | private TextBox textWatch;
27 | private bool isCopyingText = false;
28 |
29 | public CopyableWatch()
30 | {
31 | InitializeComponent();
32 | textWatch = this.FindName("TextWatch") as TextBox;
33 | }
34 |
35 | private void CopyToClipboard()
36 | {
37 | if (isCopyingText) return;
38 |
39 | Clipboard.SetText(currentText);
40 | var _currentText = textWatch.Text;
41 | textWatch.Text = "Copied to clipboard!";
42 | isCopyingText = true;
43 |
44 | var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(750) };
45 | timer.Start();
46 | timer.Tick += (_sender, _args) => {
47 | timer.Stop();
48 | this.Dispatcher.Invoke(() => {
49 | textWatch.Text = _currentText;
50 | });
51 | isCopyingText = false;
52 | };
53 | }
54 |
55 | private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
56 | {
57 | currentText = (sender as TextBox).Text;
58 | }
59 |
60 | private void TextWatch_MouseDoubleClick(object sender, MouseButtonEventArgs e)
61 | {
62 | this.CopyToClipboard();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsTimeout.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using System.Linq;
7 | using Newtonsoft.Json;
8 |
9 | namespace NodeModelsEssentials
10 | {
11 | //
12 | // Sample Node Model called MultiplyMulti.
13 | // It returns the product of two numbers and a verbose string.
14 | //
15 | [NodeName("Essentials.Timeout")]
16 | [NodeDescription("Sleeps for a bit and throws an error if the sleeping times out. Determine the maximum duration a node can run for (and time out if it surpasses it).")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [InPortNames("Sleep", "Timeout")]
19 | [InPortTypes("int", "int")]
20 | [InPortDescriptions("Sleep duration.", "Timeout duration")]
21 | [OutPortNames("Message")]
22 | [OutPortTypes("string")]
23 | [OutPortDescriptions("Resulting string.")]
24 | [IsDesignScriptCompatible]
25 |
26 | public class Timeout : NodeModel
27 | {
28 | [JsonConstructor]
29 | private Timeout(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
30 | {
31 | }
32 |
33 | public Timeout()
34 | {
35 | RegisterAllPorts();
36 | }
37 |
38 | public override IEnumerable BuildOutputAst(List inputAsNodes)
39 | {
40 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any())
41 | {
42 | return new[] {
43 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())
44 | };
45 | }
46 |
47 | var timeoutFunctionNode =
48 | AstFactory.BuildFunctionCall(
49 | new Func(NodeModelsEssentialsFunctions.Timeout),
50 | new List { inputAsNodes[0], inputAsNodes[1] });
51 |
52 | return new[] {
53 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), timeoutFunctionNode)
54 | };
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/GeometryUVPlanesOnSurface.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using Autodesk.DesignScript.Geometry;
7 | using System.Linq;
8 | using Newtonsoft.Json;
9 |
10 | namespace NodeModelsEssentials
11 | {
12 | //
13 | // Given a surface, returns a grid of UV tangent planes.
14 | //
15 | [NodeName("Geometry.UVPlanesOnSurface")]
16 | [NodeDescription("Given a surface, returns a grid of UV tangent planes.")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [InPortNames("surface", "uCount", "vCount")]
19 | [InPortTypes("Surface", "int", "int")]
20 | [InPortDescriptions("Surface to evaluate", "Count u", "Count v")]
21 | [OutPortNames("Surface")]
22 | [OutPortTypes("Plane[][]")]
23 | [OutPortDescriptions("UV tangent planes.")]
24 | [IsDesignScriptCompatible]
25 | public class UVPlanesOnSurface : NodeModel
26 | {
27 | [JsonConstructor]
28 | private UVPlanesOnSurface(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
29 | {
30 | }
31 |
32 | public UVPlanesOnSurface()
33 | {
34 | RegisterAllPorts();
35 | }
36 |
37 | public override IEnumerable BuildOutputAst(List inputAsNodes)
38 | {
39 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[2].Connectors.Any())
40 | {
41 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
42 | }
43 |
44 | var functionCall =
45 | AstFactory.BuildFunctionCall(
46 | new Func>>(NodeModelsEssentialsFunctions.UVPlanesOnSurface),
47 | new List { inputAsNodes[0], inputAsNodes[1], inputAsNodes[2] });
48 |
49 | // Return an assigment of the generated Ast function call to output node 0
50 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/GeometrySurfaceFrom4Points.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using Autodesk.DesignScript.Geometry;
7 | using System.Linq;
8 | using Newtonsoft.Json;
9 |
10 | namespace NodeModelsEssentials
11 | {
12 | //
13 | // A simple node to create a surface from four points.
14 | //
15 | [NodeName("Geometry.SurfaceFrom4Points")]
16 | [NodeDescription("A simple node to create a surface from four points.")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [InPortNames("point1", "point2", "point3", "point4")]
19 | [InPortTypes(
20 | "Autodesk.DesignScript.Geometry.Point",
21 | "Autodesk.DesignScript.Geometry.Point",
22 | "Autodesk.DesignScript.Geometry.Point",
23 | "Autodesk.DesignScript.Geometry.Point")]
24 | [InPortDescriptions("First point", "Second point", "Third point", "Fourth point")]
25 | [OutPortNames("Surface")]
26 | [OutPortTypes("Autodesk.DesignScript.Geometry.Surface")]
27 | [OutPortDescriptions("A surface defined by four corner points.")]
28 | [IsDesignScriptCompatible]
29 | public class SurfaceFrom4Points : NodeModel
30 | {
31 | [JsonConstructor]
32 | private SurfaceFrom4Points(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
33 | {
34 | }
35 |
36 | public SurfaceFrom4Points()
37 | {
38 | RegisterAllPorts();
39 | }
40 |
41 | public override IEnumerable BuildOutputAst(List inputAsNodes)
42 | {
43 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[2].Connectors.Any() || !InPorts[3].Connectors.Any())
44 | {
45 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
46 | }
47 |
48 | var functionCall =
49 | AstFactory.BuildFunctionCall(
50 | new Func(NodeModelsEssentialsFunctions.SurfaceFrom4Points),
51 | new List { inputAsNodes[0], inputAsNodes[1], inputAsNodes[2], inputAsNodes[3] });
52 |
53 | // Return an assigment of the generated Ast function call to output node 0
54 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/GeometryWobblySurface.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using Autodesk.DesignScript.Geometry;
7 | using System.Linq;
8 | using Newtonsoft.Json;
9 |
10 | namespace NodeModelsEssentials
11 | {
12 |
13 | //
14 | // Given some size parameters, returns a lofted surface with random bumps.
15 | //
16 | [NodeName("Geometry.WobblySurface")]
17 | [NodeDescription("Given some size parameters, returns a lofted surface with random bumps.")]
18 | [NodeCategory("NodeModelsEssentials")]
19 | [InPortNames("baseX", "baseY", "baseZ", "width", "length", "maxHeight", "uCount", "vCount")]
20 | [InPortTypes("double", "double", "double", "double", "double", "double", "int", "int")]
21 | [InPortDescriptions("baseX", "baseY", "baseZ", "width", "length", "maxHeight", "uCount", "vCount")]
22 | [OutPortNames("Surface")]
23 | [OutPortTypes("Surface")]
24 | [OutPortDescriptions("Lofted surface with random bumps.")]
25 | [IsDesignScriptCompatible]
26 | public class WobblySurface : NodeModel
27 | {
28 | [JsonConstructor]
29 | private WobblySurface(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
30 | {
31 | }
32 |
33 | public WobblySurface()
34 | {
35 | RegisterAllPorts();
36 | }
37 |
38 | public override IEnumerable BuildOutputAst(List inputAsNodes)
39 | {
40 |
41 | if (
42 | !InPorts[0].Connectors.Any() ||
43 | !InPorts[1].Connectors.Any() ||
44 | !InPorts[2].Connectors.Any() ||
45 | !InPorts[3].Connectors.Any() ||
46 | !InPorts[4].Connectors.Any() ||
47 | !InPorts[5].Connectors.Any() ||
48 | !InPorts[6].Connectors.Any() ||
49 | !InPorts[7].Connectors.Any()
50 | )
51 | {
52 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
53 | }
54 |
55 | var functionCall =
56 | AstFactory.BuildFunctionCall(
57 | new Func(NodeModelsEssentialsFunctions.WobblySurface),
58 | new List {
59 | inputAsNodes[0],
60 | inputAsNodes[1],
61 | inputAsNodes[2],
62 | inputAsNodes[3],
63 | inputAsNodes[4],
64 | inputAsNodes[5],
65 | inputAsNodes[6],
66 | inputAsNodes[7],
67 | });
68 |
69 | // Return an assigment of the generated Ast function call to output node 0
70 | return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/UIButton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using Dynamo.Controls;
6 | using Dynamo.Graph.Nodes;
7 | using ProtoCore.AST.AssociativeAST;
8 | using Autodesk.DesignScript.Runtime;
9 | using Dynamo.Wpf;
10 | using NodeModelsEssentials.Functions;
11 | using NodeModelsEssentials.Controls;
12 | using Dynamo.UI.Commands;
13 | using Microsoft.Practices.Prism.Commands;
14 | using Newtonsoft.Json;
15 | using DelegateCommand = Dynamo.UI.Commands.DelegateCommand;
16 |
17 | namespace NodeModelsEssentials
18 | {
19 | [NodeName("UI.Button")]
20 | [NodeDescription("A sample Node Model with custom UI.")]
21 | [NodeCategory("NodeModelsEssentials")]
22 | [OutPortNames("Result")]
23 | [OutPortTypes("double")]
24 | [OutPortDescriptions("Current value of internal number property.")]
25 | [IsDesignScriptCompatible]
26 | public class CustomUINodeModelButton : NodeModel
27 | {
28 | #region commands
29 |
30 | public DelegateCommand MyCommand { get; set; }
31 |
32 | #endregion
33 |
34 | #region private members
35 |
36 | private double number;
37 |
38 | #endregion
39 |
40 | #region properties
41 |
42 | public double Number
43 | {
44 | get { return number; }
45 | set
46 | {
47 | number = value;
48 | number = Math.Round(value, 2);
49 | RaisePropertyChanged("Number");
50 |
51 | OnNodeModified();
52 | }
53 | }
54 |
55 | #endregion
56 |
57 | #region constructor
58 |
59 | [JsonConstructor]
60 | private CustomUINodeModelButton(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
61 | {
62 | }
63 |
64 | public CustomUINodeModelButton()
65 | {
66 | RegisterAllPorts();
67 |
68 | MyCommand = new DelegateCommand(SayHello);
69 |
70 | number = 0.0;
71 | }
72 |
73 | #endregion
74 |
75 | #region public methods
76 |
77 | private static void SayHello(object obj)
78 | {
79 | MessageBox.Show("Hello Dynamo!");
80 | }
81 |
82 | [IsVisibleInDynamoLibrary(false)]
83 | public override IEnumerable BuildOutputAst(List inputAsNodes)
84 | {
85 | var doubleNode = AstFactory.BuildDoubleNode(number);
86 |
87 | //var funcNode = AstFactory.BuildFunctionCall(
88 | // new Func(NodeModelsEssentialsFunctions.Multiply),
89 | // new List() { doubleNode, doubleNode }
90 | // );
91 |
92 | return new[]
93 | {
94 | AstFactory.BuildAssignment(
95 | GetAstIdentifierForOutputIndex(0), doubleNode)
96 | };
97 | }
98 |
99 | #endregion
100 | }
101 |
102 | ///
103 | /// View customizer for CustomUINodeModel Node Model.
104 | ///
105 | public class CustomUINodeModelViewCustomization : INodeViewCustomization
106 | {
107 | public void CustomizeView(CustomUINodeModelButton model, NodeView nodeView)
108 | {
109 | var myWpfView = new MyWpfView();
110 |
111 | nodeView.inputGrid.Children.Add(myWpfView);
112 |
113 | myWpfView.DataContext = model;
114 | }
115 |
116 | public void Dispose() { }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DynamoNodeModelsEssentials
2 |
3 | This project provides a Visual Studio template for advanced Dynamo package development using Node Models.
4 |
5 | ## Nodes
6 |
7 | ### Essentials
8 |
9 | - [AstReusingFunctionCall](src/Essentials/NodeModelsEssentials/EssentialsAstReusingFunctionCall.cs). This node displays a desirable way to use the AST (Abstract Syntax Tree) where function calls are executed only once and return values are re-used. (Read node summary for detailed explanation.)
10 | - [AstNotReusingFunctionCall](src/Essentials/NodeModelsEssentials/EssentialsAstNotReusingFunctionCall.cs). This node displays a non-desirable way to use the AST where function calls are executed multiple times and return values are not re-used. (Read node summary for detailed explanation.)
11 | - [DataBridge](src/Essentials/NodeModelsEssentials/EssentialsDataBridge.cs). How the data bridge pattern works in order to pass the data connected to input ports (or the data of generated for the output ports) to the `NodeModel` instance.
12 | - [Error](src/Essentials/NodeModelsEssentials/EssentialsError.cs). Throw a custom warning when something fails.
13 | - [Events](src/Essentials/NodeModelsEssentials/EssentialsEvents.cs). Execute a method of a `NodeModel` on the pre and post graph execution events of the graph.
14 | - [MultiOperation](src/Essentials/NodeModelsEssentials/EssentialsMultiOperation.cs). A node that calls four different functions and returns the resulting values, i.e., a multi-return `NodeModel`.
15 | - [Multiply](src/Essentials/NodeModelsEssentials/EssentialsMultiply.cs). A node that calls a function with two inputs and returns the resulting value.
16 | - [Timeout](src/Essentials/NodeModelsEssentials/EssentialsTimeout.cs). Determine the maximum duration a node can run for (and time out if it surpasses it).
17 |
18 | ### Geometry
19 |
20 | - [CustomPreview](src/Essentials/NodeModelsEssentials/GeometryCustomPreview.cs). Specify how the viewport should render a custom C# class when it's returned by a Dynamo node.
21 | - [SurfaceFrom4Points](src/Essentials/NodeModelsEssentials/GeometrySurfaceFrom4Points.cs).
22 | - [UVPlanesOnSurface](src/Essentials/NodeModelsEssentials/GeometryUVPlanesOnSurface.cs).
23 | - [WobblySurface](src/Essentials/NodeModelsEssentials/GeometryWobblySurface.cs).
24 |
25 | ### UI
26 |
27 | - [Button](src/Essentials/NodeModelsEssentials/UIButton.cs).
28 | - [ButtonFunction](src/Essentials/NodeModelsEssentials/UIButtonFunction.cs).
29 | - [CopyableWatch](src/Essentials/NodeModelsEssentials/UICopyableWatch.cs).
30 | - [Slider](src/Essentials/NodeModelsEssentials/UISlider.cs).
31 | - [SliderBound](src/Essentials/NodeModelsEssentials/UISliderBound.cs).
32 | - [State](src/Essentials/NodeModelsEssentials/UIState.cs).
33 |
34 | ## Acknowledgments
35 |
36 | These nodes document, in one way or another, my own learning on how to create nodes for Dynamo.
37 |
38 | The initial template and samples provided in this project were inspired by [DynamoDS/DynamoSamples](https://github.com/DynamoDS/DynamoSamples) and [teocomi/HelloDynamo](https://github.com/teocomi/HelloDynamo). I highly recommend you to take a look at these for further learning.
39 |
40 | [Jose Luis Garcia del Castillo](http://github.com/garciadelcastillo) wrote the Surface function samples.
41 |
42 | Big thanks to the [Dynamo](http://dynamobim.org) development team.
43 |
44 | ## License
45 |
46 | DynamoNodeModelsEssentials is licensed under the MIT license. (http://opensource.org/licenses/MIT)
47 |
48 | ## Me
49 |
50 | I'm [Nono Martínez Alonso](http://nono.ma) ([nono.ma](http://nono.ma)), a computational designer with a penchant for design, code, and simplicity.
51 | I host [The Getting Simple Podcast](https://gettingsimple.com/podcast), tweet at [@nonoesp](http://www.twitter.com/nonoesp), and sketch at [@sketch.nono.ma](http://sketch.nono.ma). If you use this, I would love to hear about it. Thanks!
52 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsMultiOperation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using System.Linq;
7 | using Newtonsoft.Json;
8 |
9 | namespace NodeModelsEssentials
10 | {
11 | //
12 | // Sample Node Model called MultiplyMulti.
13 | // It returns the product of two numbers and a verbose string.
14 | //
15 | [NodeName("Essentials.MultiOperation")]
16 | [NodeDescription("A node that calls four different functions and returns the resulting values, i.e., a multi-return NodeModel.")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [InPortNames("A", "B")]
19 | [InPortTypes("double", "double")]
20 | [InPortDescriptions("Number A", "Number B")]
21 | [OutPortNames("AxB", "A+B", "A-B", "A/B")]
22 | [OutPortTypes("double", "double")]
23 | [OutPortDescriptions(
24 | "Product of A x B",
25 | "Addition of A and B",
26 | "Subtraction of A and B",
27 | "Division of A by B")]
28 | [IsDesignScriptCompatible]
29 | public class MultiOperation : NodeModel
30 | {
31 | [JsonConstructor]
32 | private MultiOperation(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
33 | {
34 | }
35 |
36 | public MultiOperation()
37 | {
38 | RegisterAllPorts();
39 | }
40 |
41 | public override IEnumerable BuildOutputAst(List inputAsNodes)
42 | {
43 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any())
44 | {
45 | return new[] {
46 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildIntNode(1)),
47 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), AstFactory.BuildIntNode(2)),
48 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(2), AstFactory.BuildIntNode(3)),
49 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(3), AstFactory.BuildIntNode(4))
50 | };
51 | }
52 |
53 | var multiplyFunctionNode =
54 | AstFactory.BuildFunctionCall(
55 | new Func(NodeModelsEssentialsFunctions.Multiply),
56 | new List { inputAsNodes[0], inputAsNodes[1] });
57 |
58 | var addFunctionNode =
59 | AstFactory.BuildFunctionCall(
60 | new Func(NodeModelsEssentialsFunctions.Add),
61 | new List { inputAsNodes[0], inputAsNodes[1] });
62 |
63 | var subtractFunctionNode =
64 | AstFactory.BuildFunctionCall(
65 | new Func(NodeModelsEssentialsFunctions.Subtract),
66 | new List { inputAsNodes[0], inputAsNodes[1] });
67 |
68 | var divideFunctionNode =
69 | AstFactory.BuildFunctionCall(
70 | new Func(NodeModelsEssentialsFunctions.Divide),
71 | new List { inputAsNodes[0], inputAsNodes[1] });
72 |
73 | return new[] {
74 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), multiplyFunctionNode),
75 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), addFunctionNode),
76 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(2), subtractFunctionNode),
77 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(3), divideFunctionNode)
78 | };
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsEvents.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using System.Windows;
6 | using Dynamo.Events;
7 | using System.Linq;
8 | using Newtonsoft.Json;
9 |
10 | namespace NodeModelsEssentials
11 | {
12 | ///
13 | /// A node that displays a message in the pre and post execution events of the graph.
14 | /// These events are fired whenever the graph is modified anywhere, and not only when
15 | /// the Essentials.Events node is modified.
16 | ///
17 | [NodeName("Essentials.Events")]
18 | [NodeDescription("Execute a method of a NodeModel on the pre and post graph execution events of the graph.")]
19 | [NodeCategory("NodeModelsEssentials")]
20 | [InPortNames("In")]
21 | [InPortTypes("string")]
22 | [InPortDescriptions("A string.")]
23 | [OutPortNames("Out")]
24 | [OutPortTypes("string")]
25 | [OutPortDescriptions("Resulting string.")]
26 | [IsDesignScriptCompatible]
27 | class EssentialsEvents : NodeModel
28 | {
29 | #region constructor
30 |
31 | [JsonConstructor]
32 | private EssentialsEvents(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
33 | {
34 | RegisterExecutionEvents();
35 | }
36 |
37 | private void ExecutionEvents_GraphPostExecution(Dynamo.Session.IExecutionSession session)
38 | {
39 | var guid = GUID.ToString().Substring(0, 5);
40 | MessageBox.Show("Post execution event of node " + guid + ".");
41 | }
42 |
43 | private void ExecutionEvents_GraphPreExecution(Dynamo.Session.IExecutionSession session)
44 | {
45 | var guid = GUID.ToString().Substring(0, 5);
46 | MessageBox.Show("Pre execution event of node " + guid + ".");
47 | }
48 |
49 | public EssentialsEvents()
50 | {
51 | RegisterAllPorts();
52 | RegisterExecutionEvents();
53 | }
54 |
55 | ///
56 | /// Subscribe to pre and post graph execution events.
57 | ///
58 | public void RegisterExecutionEvents()
59 | {
60 | ExecutionEvents.GraphPreExecution += ExecutionEvents_GraphPreExecution;
61 | ExecutionEvents.GraphPostExecution += ExecutionEvents_GraphPostExecution;
62 | }
63 |
64 | ///
65 | /// Unsubscribe from pre and post graph execution events.
66 | ///
67 | public void UnregisterExecutionEvents()
68 | {
69 | ExecutionEvents.GraphPreExecution -= ExecutionEvents_GraphPreExecution;
70 | ExecutionEvents.GraphPostExecution -= ExecutionEvents_GraphPostExecution;
71 | }
72 |
73 | // It's important to unregister from execution events, otherwise this events
74 | // will still be called even when the node is removed from the Dynamo graph.
75 | public override void Dispose()
76 | {
77 | base.Dispose();
78 | UnregisterExecutionEvents();
79 | }
80 |
81 | #endregion
82 |
83 | #region ast
84 |
85 | public override IEnumerable BuildOutputAst(List inputAstNodes)
86 | {
87 | if (!InPorts[0].Connectors.Any())
88 | {
89 | return new[]
90 | {AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())};
91 | }
92 |
93 | return new[]
94 | {
95 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), inputAstNodes[0])
96 | };
97 | }
98 |
99 | #endregion
100 |
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/Essentials/samples/01_MovingSphere.dyn:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | 17.3
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentialsFunctions/NodeModelsEssentialsFunctions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F519DEE9-84FF-4331-B5C8-131C4A684670}
8 | Library
9 | Properties
10 | NodeModelsEssentials.Functions
11 | NodeModelsEssentialsFunctions
12 | v4.8.1
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\DynamoVisualProgramming.DynamoServices.2.18.0-beta3336\lib\netstandard2.0\DynamoServices.dll
36 |
37 |
38 | ..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Expression.Interactions.dll
39 | True
40 |
41 |
42 | ..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll
43 |
44 |
45 | ..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.Interactivity.dll
46 |
47 |
48 | ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll
49 |
50 |
51 | ..\packages\NUnit.2.6.3\lib\nunit.framework.dll
52 |
53 |
54 | ..\packages\DynamoVisualProgramming.ZeroTouchLibrary.2.18.0-beta3336\lib\net48\ProtoGeometry.dll
55 |
56 |
57 |
58 |
59 | ..\packages\Prism.4.1.0.0\lib\NET40\System.Windows.Interactivity.dll
60 | True
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/UISlider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Controls;
4 | using Dynamo.Graph.Nodes;
5 | using Dynamo.UI.Commands;
6 | using Dynamo.Wpf;
7 | using ProtoCore.AST.AssociativeAST;
8 | using Autodesk.DesignScript.Runtime;
9 | using NodeModelsEssentials.Controls;
10 | using System.Linq;
11 | using Newtonsoft.Json;
12 |
13 | namespace NodeModelsEssentials
14 | {
15 | [NodeName("UI.Slider")]
16 | [NodeDescription("A sample Node Model with custom Wpf UI.")]
17 | [NodeCategory("NodeModelsEssentials")]
18 | [OutPortNames(">")]
19 | [OutPortTypes("double")]
20 | [OutPortDescriptions("Double")]
21 | [IsDesignScriptCompatible]
22 | public class CustomUIWpfNodeModel : NodeModel
23 | {
24 | #region private members
25 |
26 | private double number;
27 | private double maximumValue;
28 | private double minimumValue;
29 | private double step;
30 |
31 | #endregion
32 |
33 | #region properties
34 |
35 | [IsVisibleInDynamoLibrary(false)]
36 | public DelegateCommand IncreaseCommand { get; set; }
37 |
38 | [IsVisibleInDynamoLibrary(false)]
39 | public DelegateCommand DecreaseCommand { get; set; }
40 |
41 | public double MinimumValue
42 | {
43 | get { return minimumValue; }
44 | set
45 | {
46 | minimumValue = value;
47 | RaisePropertyChanged("MinimumValue");
48 | }
49 | }
50 | public double MaximumValue
51 | {
52 | get { return maximumValue; }
53 | set
54 | {
55 | maximumValue = value;
56 | RaisePropertyChanged("MaximumValue");
57 | }
58 | }
59 |
60 | public double Number
61 | {
62 | get { return number; }
63 | set
64 | {
65 | number = Math.Round(value, 2); ;
66 | RaisePropertyChanged("Number");
67 |
68 | OnNodeModified();
69 | }
70 | }
71 |
72 | #endregion
73 |
74 | #region constructor
75 |
76 | [JsonConstructor]
77 | private CustomUIWpfNodeModel(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
78 | {
79 | }
80 |
81 | public CustomUIWpfNodeModel()
82 | {
83 | RegisterAllPorts();
84 |
85 | IncreaseCommand = new DelegateCommand(IncreaseNumber);
86 | DecreaseCommand = new DelegateCommand(DecreaseNumber);
87 |
88 | MinimumValue = 0.0;
89 | MaximumValue = 100.0;
90 | step = 10.0;
91 | }
92 |
93 | #endregion
94 |
95 | #region public methods
96 |
97 | [IsVisibleInDynamoLibrary(false)]
98 | public override IEnumerable BuildOutputAst(List inputAsNodes)
99 | {
100 | var doubleNode = AstFactory.BuildDoubleNode(number);
101 |
102 | //var funcNode = AstFactory.BuildFunctionCall(
103 | // new Func(NodeModelsEssentialsFunctions.Multiply),
104 | // new List() { doubleNode, doubleNode }
105 | // );
106 |
107 | return new[]
108 | {
109 | AstFactory.BuildAssignment(
110 | GetAstIdentifierForOutputIndex(0), doubleNode)
111 | };
112 | }
113 |
114 | #endregion
115 |
116 | #region command methods
117 |
118 | private void IncreaseNumber(object obj)
119 | {
120 | if (Number + step >= MaximumValue)
121 | {
122 | Number = MaximumValue;
123 | } else
124 | {
125 | Number += step;
126 | }
127 | }
128 | private void DecreaseNumber(object obj)
129 | {
130 |
131 | if (Number - step <= MinimumValue)
132 | {
133 | Number = MinimumValue;
134 | } else
135 | {
136 | Number += -step;
137 | }
138 | }
139 |
140 | #endregion
141 | }
142 |
143 | ///
144 | /// View customizer for CustomUINodeModel Node Model.
145 | ///
146 | public class CustomUIWpfNodeModelViewCustomization : INodeViewCustomization
147 | {
148 | public void CustomizeView(CustomUIWpfNodeModel model, NodeView nodeView)
149 | {
150 | var myFirstDynamoControl = new MyFirstDynamoControl();
151 | nodeView.inputGrid.Children.Add(myFirstDynamoControl);
152 |
153 | myFirstDynamoControl.DataContext = model;
154 | }
155 |
156 | public void Dispose() { }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/UIButtonFunction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows;
4 | using System.Windows.Controls;
5 | using Dynamo.Controls;
6 | using Dynamo.Graph.Nodes;
7 | using ProtoCore.AST.AssociativeAST;
8 | using Autodesk.DesignScript.Runtime;
9 | using Dynamo.Wpf;
10 | using NodeModelsEssentials.Functions;
11 | using NodeModelsEssentials.Controls;
12 | using Dynamo.UI.Commands;
13 | using VMDataBridge;
14 | using Newtonsoft.Json;
15 |
16 | namespace NodeModelsEssentials
17 | {
18 | [NodeName("UI.ButtonFunction")]
19 | [NodeDescription("A sample Node Model with custom UI.")]
20 | [NodeCategory("NodeModelsEssentials")]
21 | [OutPortNames("Result")]
22 | [OutPortTypes("double")]
23 | [OutPortDescriptions("Current value of internal number property.")]
24 | [IsDesignScriptCompatible]
25 | public class CustomUINodeModelButtonFunction : NodeModel
26 | {
27 | #region commands
28 |
29 | public DelegateCommand MyCommand { get; set; }
30 |
31 | #endregion
32 |
33 | #region private members
34 |
35 | private double number;
36 |
37 | #endregion
38 |
39 | #region properties
40 |
41 | public Action Executed;
42 |
43 | public double Number
44 | {
45 | get { return number; }
46 | set
47 | {
48 | number = value;
49 | number = Math.Round(value, 2);
50 | RaisePropertyChanged("Number");
51 |
52 | OnNodeModified();
53 | }
54 | }
55 |
56 | #endregion
57 |
58 | #region constructor
59 |
60 | [JsonConstructor]
61 | private CustomUINodeModelButtonFunction(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
62 | {
63 | }
64 |
65 | public CustomUINodeModelButtonFunction()
66 | {
67 | Executed = new Action(() => {
68 | MessageBox.Show("Executed!");
69 | });
70 |
71 | RegisterAllPorts();
72 |
73 | MyCommand = new DelegateCommand(SayHello);
74 |
75 | number = 0.0;
76 | }
77 |
78 | #endregion
79 |
80 | #region data bridge
81 |
82 | public override void Dispose()
83 | {
84 | base.Dispose();
85 | DataBridge.Instance.UnregisterCallback(GUID.ToString());
86 | }
87 |
88 | protected override void OnBuilt()
89 | {
90 | base.OnBuilt();
91 | DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback);
92 | }
93 |
94 | private void DataBridgeCallback(object data)
95 | {
96 | this.Executed();
97 | }
98 |
99 | #endregion
100 |
101 | #region public methods
102 |
103 | private void SayHello(object obj)
104 | {
105 | OnNodeModified(forceExecute: true);
106 | //MessageBox.Show("Hello Dynamo!");
107 | }
108 |
109 | [IsVisibleInDynamoLibrary(false)]
110 | public override IEnumerable BuildOutputAst(List inputAsNodes)
111 | {
112 | var doubleNode = AstFactory.BuildDoubleNode(number);
113 |
114 | //var funcNode = AstFactory.BuildFunctionCall(
115 | // new Func(NodeModelsEssentialsFunctions.Multiply),
116 | // new List() { doubleNode, doubleNode }
117 | // );
118 |
119 | return new[]
120 | {
121 | AstFactory.BuildAssignment(
122 | GetAstIdentifierForOutputIndex(0),
123 | doubleNode),
124 | AstFactory.BuildAssignment(
125 | AstFactory.BuildIdentifier(AstIdentifierBase + "_dummy"),
126 | DataBridge.GenerateBridgeDataAst(GUID.ToString(), doubleNode))
127 | };
128 | }
129 |
130 | #endregion
131 | }
132 |
133 | ///
134 | /// View customizer for CustomUINodeModel Node Model.
135 | ///
136 | public class CustomUINodeModelButtonFunctionViewCustomization : INodeViewCustomization
137 | {
138 | private MyWpfView myWpfView = null;
139 | public void CustomizeView(CustomUINodeModelButtonFunction model, NodeView nodeView)
140 | {
141 | myWpfView = new MyWpfView();
142 | myWpfView.button.Content = "Changed";
143 | //myWpfView.button.Click += (object sender, RoutedEventArgs e) => {
144 | // model.Number++;
145 | //};
146 | nodeView.inputGrid.Children.Add(myWpfView);
147 |
148 | myWpfView.DataContext = model;
149 | }
150 |
151 |
152 | public void Dispose() {
153 | // unsubscribe myWpfView.button from click event?
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsDataBridge.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections;
4 | using Dynamo.Graph.Nodes;
5 | using ProtoCore.AST.AssociativeAST;
6 | using NodeModelsEssentials.Functions;
7 | using System.Linq;
8 | using Newtonsoft.Json;
9 | using System.Windows;
10 |
11 | namespace NodeModelsEssentials
12 | {
13 | ///
14 | /// A node that displays how a data bridge can be used within a Node Model.
15 | /// Something to note is that the data bridge callback passes an expression list
16 | /// to pass all of the input nodes to the callback, thus providing the input of
17 | /// the node ports to the Node Model class.
18 | /// (This happens using AstFactory.BuildExprList(inputAstNodes), but you could
19 | /// also just pass a single node, or a list of nodes, like inputAstNodes[0].)
20 | ///
21 | [NodeName("Essentials.DataBridge")]
22 | [NodeDescription("How the data bridge pattern works in order to pass the data connected to input ports (or the data of generated for the output ports) to the NodeModel instance.")]
23 | [NodeCategory("NodeModelsEssentials")]
24 | [InPortNames("A", "B", "C")]
25 | [InPortTypes("string", "string", "string")]
26 | [InPortDescriptions("A string.", "Another string.", "Another string.")]
27 | [OutPortNames("Out")]
28 | [OutPortTypes("string")]
29 | [OutPortDescriptions(
30 | "Resulting string.")]
31 | [IsDesignScriptCompatible]
32 | class EssentialsDataBridge : NodeModel
33 | {
34 | #region constructor
35 |
36 | [JsonConstructor]
37 | private EssentialsDataBridge(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
38 | {
39 | }
40 |
41 | public EssentialsDataBridge()
42 | {
43 | RegisterAllPorts();
44 | }
45 |
46 | #endregion
47 |
48 | #region data bridge callback
49 |
50 | ///
51 | /// Register the data bridge callback.
52 | ///
53 | protected override void OnBuilt()
54 | {
55 | base.OnBuilt();
56 | VMDataBridge.DataBridge.Instance.RegisterCallback(GUID.ToString(), DataBridgeCallback);
57 | }
58 |
59 | ///
60 | /// Unregister the data bridge callback.
61 | ///
62 | public override void Dispose()
63 | {
64 | base.Dispose();
65 | VMDataBridge.DataBridge.Instance.UnregisterCallback(GUID.ToString());
66 | }
67 |
68 | ///
69 | /// Callback method for DataBridge mechanism.
70 | /// This callback only gets called once after the BuildOutputAst Function is executed
71 | /// This callback casts the response data object.
72 | ///
73 | /// The data passed through the data bridge.
74 | private void DataBridgeCallback(object data)
75 | {
76 | ArrayList inputs = data as ArrayList;
77 | var str = "";
78 | foreach (var input in inputs)
79 | {
80 | str += input.ToString() + " ";
81 | }
82 | MessageBox.Show("Data bridge callback of node " + GUID.ToString().Substring(0,5) + ": " + str );
83 | }
84 |
85 | #endregion
86 |
87 | #region ast
88 |
89 | public override IEnumerable BuildOutputAst(List inputAstNodes)
90 | {
91 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[2].Connectors.Any())
92 | {
93 | return new[]
94 | {AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode())};
95 | }
96 |
97 | var functionCallNode = AstFactory.BuildFunctionCall(
98 | new Func(NodeModelsEssentialsFunctions.ConcatenateThree),
99 | new List { inputAstNodes[0], inputAstNodes[1], inputAstNodes[2] });
100 |
101 | return new[]
102 | {
103 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCallNode),
104 | AstFactory.BuildAssignment(
105 | AstFactory.BuildIdentifier(AstIdentifierBase + "_dummy"),
106 | // you can pass an expression list like this
107 | VMDataBridge.DataBridge.GenerateBridgeDataAst(GUID.ToString(), AstFactory.BuildExprList(inputAstNodes))
108 | // or build it manually like this
109 | //VMDataBridge.DataBridge.GenerateBridgeDataAst(GUID.ToString(), AstFactory.BuildExprList(new List { inputAstNodes[0], AstFactory.BuildStringNode("test") } ))
110 | )
111 | };
112 | }
113 |
114 | #endregion
115 |
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/EssentialsAstNotReusingFunctionCall.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Graph.Nodes;
4 | using ProtoCore.AST.AssociativeAST;
5 | using NodeModelsEssentials.Functions;
6 | using Newtonsoft.Json;
7 | using System.Linq;
8 |
9 | namespace NodeModelsEssentials
10 | {
11 | //
12 | // This node displays a non-desirable way of using the AST.
13 | // We pass function call nodes (say, multiplyFunctionNode)
14 | // both to the sumFunctionNode and to one of the node outputs.
15 | // This causes the AST to execute the multiply function twice.
16 | // In this case, the overload is not too big, but for CPU-intensive
17 | // tasks or for non-deterministic results (where the returning
18 | // value of a function might be different two consecutive executions)
19 | // the sum node and the output port will have different values.
20 | //
21 | [NodeName("Essentials.AstNotReusingFunctionCall")]
22 | [NodeDescription("This node displays a non-desirable way to use the AST where function calls are executed multiple times and return values are not re-used.")]
23 | [NodeCategory("NodeModelsEssentials")]
24 | [InPortNames("A", "B")]
25 | [InPortTypes("double", "double")]
26 | [InPortDescriptions("Number A", "Number B")]
27 | [OutPortNames("AxB", "A+B", "A-B", "A/B", "SUM")]
28 | [OutPortTypes("double", "double", "double", "double", "double")]
29 | [OutPortDescriptions(
30 | "Product of A x B",
31 | "Addition of A and B",
32 | "Subtraction of A and B",
33 | "Division of A by B",
34 | "Sum of all outputs")]
35 | [IsDesignScriptCompatible]
36 | public class AstNotReusingFunctionCall : NodeModel
37 | {
38 |
39 | #region constructor
40 |
41 | [JsonConstructor]
42 | private AstNotReusingFunctionCall(IEnumerable inPorts, IEnumerable outPorts) : base(inPorts, outPorts)
43 | {
44 | }
45 |
46 | public AstNotReusingFunctionCall()
47 | {
48 | RegisterAllPorts();
49 | }
50 |
51 | #endregion
52 |
53 | #region ast
54 |
55 | public override IEnumerable BuildOutputAst(List inputAsNodes)
56 | {
57 | if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any())
58 | {
59 | return new[] {
60 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildIntNode(1)),
61 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), AstFactory.BuildIntNode(2)),
62 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(2), AstFactory.BuildIntNode(3)),
63 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(3), AstFactory.BuildIntNode(4)),
64 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(4), AstFactory.BuildIntNode(5))
65 | };
66 | }
67 |
68 | var multiplyFunctionNode =
69 | AstFactory.BuildFunctionCall(
70 | new Func(NodeModelsEssentialsFunctions.Multiply),
71 | new List { inputAsNodes[0], inputAsNodes[1] });
72 |
73 | var addFunctionNode =
74 | AstFactory.BuildFunctionCall(
75 | new Func(NodeModelsEssentialsFunctions.Add),
76 | new List { inputAsNodes[0], inputAsNodes[1] });
77 |
78 | var subtractFunctionNode =
79 | AstFactory.BuildFunctionCall(
80 | new Func(NodeModelsEssentialsFunctions.Subtract),
81 | new List { inputAsNodes[0], inputAsNodes[1] });
82 |
83 | var divideFunctionNode =
84 | AstFactory.BuildFunctionCall(
85 | new Func(NodeModelsEssentialsFunctions.Divide),
86 | new List { inputAsNodes[0], inputAsNodes[1] });
87 |
88 | var sumFunctionNode =
89 | AstFactory.BuildFunctionCall(
90 | new Func(NodeModelsEssentialsFunctions.Sum),
91 | new List {
92 | multiplyFunctionNode,
93 | addFunctionNode,
94 | subtractFunctionNode,
95 | divideFunctionNode });
96 |
97 | return new[] {
98 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), multiplyFunctionNode),
99 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(1), addFunctionNode),
100 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(2), subtractFunctionNode),
101 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(3), divideFunctionNode),
102 | AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(4), sumFunctionNode),
103 | };
104 | }
105 |
106 | #endregion
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/Essentials/samples/02_Surface.dyn:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | 10
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/Essentials/NodeModelsEssentials/UISliderBound.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Dynamo.Controls;
4 | using Dynamo.Graph.Nodes;
5 | using Dynamo.UI.Commands;
6 | using Dynamo.Wpf;
7 | using ProtoCore.AST.AssociativeAST;
8 | using Autodesk.DesignScript.Runtime;
9 | using NodeModelsEssentials.Controls;
10 | using NodeModelsEssentials.Functions;
11 | using System.Linq;
12 | using Newtonsoft.Json;
13 |
14 | namespace NodeModelsEssentials
15 | {
16 | [NodeName("UI.SliderBound")]
17 | [NodeDescription("A sample Node Model with custom Wpf UI.")]
18 | [NodeCategory("NodeModelsEssentials")]
19 | [InPortNames("list")]
20 | [InPortTypes("List