Upload
others
View
10
Download
0
Embed Size (px)
Citation preview
Super Powered DynamoDynamo Extensions - “with great power comes great
responsibility” - uncle ben
OverView For Today● 8:30 - 9:00 Breakfast and Setup● 9:00 - 9:30 Introductions and Extension Ideas Exchange● 9:30 - 11:00 Extensions Presentation● 11:00 - 12:00 Make an Extension (Part 1)● 12:00 - 13:00 Lunch● 13:00 - 16:00 Make an Extension (Part 2)● 16:00 - 17:00 Share-Out/ Conclusion
Difficulty
ExpressivePower
Graph Custom NodesDS
Zero Touch‘UI’ Nodes
Host integrationExtensions
When to Use an Extension
● Control over the graph (add,remove nodes etc).● Add new UI or functionality that is external to a single node.● Core functionality that needs improvement - simple to add an
extension which will ship with DynamoCore- good model for contribution to Dynamo itself.
● Don’t feel like learning about abstract syntax trees today…
What can we do with them?
● Create an instance of your extension when Dynamo starts.● Add MenuItems to Dynamo Window.● Get a reference to CurrentWorkspace.● Execute Model commands on The Dynamo Model (application).● Get a reference to the DynamoView - now you have as much control as Dynamo
Sandbox or DynamoRevit.
I.E. Control Dynamo like a application.
Extensions Architecture
Extensions are composed of 2 parts:
1. a .Net assembly that contains a class which implements IViewExtension or IExtension.
Extensions Architecture
2. An xml Extension manifest file which tells Dynamo which class to instantiate to start your extension.
<ViewExtensionDefinition>
<AssemblyPath>..\Notifications.dll</AssemblyPath>
<TypeName>Dynamo.Notifications.NotificationsViewExtension</Ty
peName>
</ViewExtensionDefinition>
Extensions Architecture
Dynamo looks for extension manifest files at startup in these folders in the Dynamo core install folder.
If it finds one, it tries to create an instance of it.
Naming is important!
Dynamo/ViewExtensions
MyExtension_ViewExtension.xml
Dynamo/Extensions
MyExtension_Extension.xml
Dynamo Architecture(a brief aside)
DynamoCoreWPF.dll
DynamoCore.dll
Extensions ArchitectureAt Startup Dynamo calls two methods on your extension:
StartUp(Params): called when Dynamo starts loading.
Loaded(Params): called when Dynamo is finished loading.
When these are called exactly, depends on if you are writing an Extension or ViewExtension
Dynamo Model Startup
Instantiate Extensions
Call StartUp() on Extensions
Call Loaded() on Extensions
DynamoView Startup
Call StartUp() on ViewExtensions
Instantiate ViewExtensions
Call Loaded() on ViewExtensions Shutdown() View
Extensions
Shutdown() on Extensions
Composition of ExtensionsTaking advantage of MVVM
(model)Extension
ViewExtension1 ViewExtension2 ViewExtension3
Extensions Manager
Extension Startup + Loaded ParamsMaking stuff happen. (dynamo APIs)
ViewLoadedParams
ReadyParams
ViewStartupParams
StartupParams
WorkspaceModelsCurrentWorkspaceModel
CommandExecutiveNotificationRecieved
CurrentWorkspaceChanged
ExtensionManager
DynamoMenuBackGroundPreviewViewModel
RenderPackageFactoryDynamoWindow*
CommandExecutiveAddMenuItem
SelectionCollectionChanged
AuthProviderPreferences
PathManagerLibraryLoader
CustomNodeManagerDynamoVersion
Dirty TricksMaking more stuff happen.ViewLoadedParams.DynamoWindow.DataContext as DynamoViewModel
Don’t do this unless you have to - it may stop working.
Let’s get started.
For this demo we’re going to run our extension in Dynamo Sandbox, so make sure you can build and run Dynamo Sandbox using the Dynamo repo: https://github.com/DynamoDS/Dynamo
Let’s get started.
DynamoSamples/ SampleViewExtension
https://github.com/DynamoDS/DynamoSamples
Sample WPF extension(from DynamoSamples repo)
● Create a new visual studio project.
● Reference some Dynamo nugets.
● Implement an IViewExtension.
● Add a menu item.● Load it in Dynamo.
Simple! ;)
Sample WPF extension diagram
View Extension
Window
ViewModel
Dynamo
Current Workspace Model
Data Binding
Workspace.NodesReference
Sample WPF extension
● Create a new Visual studio class library project. (target .Net 4.5 minimum)
● Reference required Dynamo Nugets: DynamoCore and DynamoCoreWPFUI
● Project-> Manage Nuget Packages->Browse
Sample WPF extension
● create a class that implements IViewExtension
● Loaded(viewParams) is used to add our main logic and menu Item
Sample WPF extension● Create our
viewModel which will contain our actual logic and raise events to update the view.
● For now we just save the ready params.
Sample WPF extension
● Use the ready params to respond to events from Dynamo and update our UI.
Sample WPF extension
Window
ViewModel
Current Workspace Model
Data Binding : ActiveNodeTypes
Event: Nodes Added/Removed
2. RaisePropertyChanged("ActiveNodeTypes");
Display a string “some node names”...
1 . Recalculate Nodes in graph.
Sample WPF extension● Implement our
window using XAML.● Add new WPF
userControl to project.
● Bind to a property called ‘ActiveNodeTypes’
Sample WPF extension
● Implement our Loaded() method logic using our viewModel and window.
Sample WPF extension● Add an xml file to the project
(SampleViewExtension_ViewExtension.xml)
<ViewExtensionDefinition>
<AssemblyPath>..\SampleViewExtension.dll</AssemblyPath>
<TypeName>SampleViewExtension.SampleViewExtension</TypeName>
</ViewExtensionDefinition>
Sample WPF extensionDynamo/bin/AnyCPU/Debug/ViewExtensions/SampleView_ViewExtension.xmlDynamo/bin/AnyCPU/Debug/SampleViewExtension.dll
Advanced SamplesExecuting Commands on the Dynamo Model and Dynamo View Model.
var VM = ViewLoadedParams.DynamoWindow.DataContext as DynamoViewModel;
//workspace view model command
VM.CurrentSpaceViewModel.ResetFitViewToggleCommand.Execute(null);
//dynamoViewModel command
VM.AddToSelectionCommand.Execute(someNode);
p.CommandExecutive.ExecuteCommand
(new DynamoModel.ForceRunCancelCommand(true, false),
this.UniqueId,
this.Name)
Execute model commands Execute viewModel commands … not guaranteed.
See:Dynamo\src\DynamoCore\Models\RecordableCommands.cs
Advanced SamplesInjecting UI into other views.
Advanced SamplesInjecting UI into other views.
https://github.com/mjkkirschner/DynamoSamples/tree/extensionWorkshop
A hack to illustrate injecting some wpf control whenever the view is updated… performance implications and other caching issues with this code.
Incoming Changes:
● Investigating Package Manager distribution of extensions.● Loading sequence might change a bit.● Loaded Parameters will likely also contain a reference to StartUp
Params.● It would be good to know now- or soon, before 2.0 release what
APIs you are missing from the extensions APIs.
Project Ideas:
● Tracking graph changes by watching workspace collection modified events.
● An extension that finds missing dependencies and reports what package they are in.
● Write your own graph UI.● Execution results view.● MiniMap.● Inject UI into base nodeView.● Improve background preview.
Your Turn!