A sample Rhino plugin to showcase MVVM, MaterialDesign and calling into a REST API. For the purposes of this exercise we're writing a tool that calls into the N2YO API in order to get current coordinates and metadata for satellites in Earth's orbit, which we can then bake to Rhino. This project very purposely does not use IoC, which would normally be another vital component of scalable modern applications. This is because IoC is a whole other animal to tackle and we're just trying to focus on the WPF side of things here.
[Recording of the YouTube Livestream]
- Visual Studio 2019 or later (Community is fine)
- Rhino 6
- .NET framework 4.8 or higher
- After you clone the repo, go to N2YO, create a new free account and generate an API key.
- In Visual Studio create a file named "secrets.json" at the root of the SpaceMonkey.Rhinoceros project (VS will complain about a missing file there, so you'll see it)
- Inside that file paste your API key in the following format:
{
"api_key": "PUT_YOUR_API_KEY_HERE"
}
- Makse sure that SpaceMonkey.Rhinoceros is set as the startup project.
- Make sure that if you right-click on the project, then go to Properties > Debug, the "Start action" field is set to Start External Program and is pointing to
C:\Program Files\Rhino 6\System\Rhino.exe
(or wherever your Rhino 6 is installed) - Hit "Run"
- [ATTN: DO THIS ONLY ONCE] After you build the project and start Rhino for the first time, go to the
bin
folder of SpaceMonkey.Rhinoceros (\SpaceMonkey\SpaceMonkey.Rhinoceros\bin
), find a file calledSpaceMonkey.Rhinoceros.rhp
and drag it into the Rhino canvas. That will register the plugin to your instance of Rhino. - Run the
SpaceMonkey
command in Rhino's command line
The original livestream where this project and its underlying concepts are discussed can be found here
The satellite tracking API is provided by N2YO Their REST API documentation can be found here
We all know that McNeel are awesome, which is why they provide a wealth of code samples for Rhino and Grasshopper developers on their GitHub page. For instance, you can find a very barebones implementation of a dockable Rhino plugin that uses WPF via this link. SpaceMonkey also uses that sample.
If you want to learn more about MVVM and start learning about IoC, then check out this great YouTube playlist by AngelSix. This is an in-depth, step-by-step walk through the process of building an MVVM application that follows the IoC pattern. SpaceMonkey uses some of the MVVM-related base classes from these tutorials.
The project's website can be found here
WPF Material Design library has been built by James Willock
And here's the project's GitHub page with links to documentation and Wikis
If you see an error saying Fody is only supported on MSBuild 16 and above
, then you're running an older version of Visual Studio: you need VS 2019 or older. That's no big deal, because Visual Studio community is free. If, however, you really really really don't want to install new VS, you can simply downgrade Fody to v3.x.x.
You have an old Service Pack. Just upgrade your Rhino.
Read the installation instructions above. That file has to be created by you and contain your free API key for N2YO