Skip to content
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ViewExtensionDefinition>
<AssemblyPath>..\bin\DynamoAssistantViewExtension.dll</AssemblyPath>
<TypeName>DynamoAssistant.DynamoAssistantViewExtension</TypeName>
</ViewExtensionDefinition>
87 changes: 87 additions & 0 deletions src/DynamoAssistantViewExtension/DynamoAssistantViewExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Windows.Controls;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;

namespace DynamoAssistant
{
/// <summary>
/// The View Extension framework for Dynamo allows you to extend
/// the Dynamo UI by registering custom MenuItems. A ViewExtension has
/// two components, an assembly containing a class that implements
/// IViewExtension or extends ViewExtensionBase, and a ViewExtensionDefinition
/// XML file used to instruct Dynamo where to find the class containing the
/// View Extension implementation. The ViewExtensionDefinition XML file must
/// be located in your [dynamo]\viewExtensions folder.
///
/// This sample demonstrates a View Extension implementation which inherits from
/// ViewExtensionBase. It adds a user interface to Dynamo's extension sidebar
/// when its MenuItem is clicked.
/// The Window created tracks the number of nodes in the current workspace,
/// by handling the workspace's NodeAdded and NodeRemoved events.
/// </summary>
public class DynamoAssistantViewExtension : ViewExtensionBase
{
private MenuItem assistantMenuItem;

public override void Dispose()
{
// Do nothing for now
}

public override void Startup(ViewStartupParams p)
{
}

public override void Loaded(ViewLoadedParams p)
{
// Save a reference to your loaded parameters.
// You'll need these later when you want to use
// the supplied workspaces

var viewModel = new DynamoAssistantWindowViewModel(p);
var window = new DynamoAssistantWindow
{
DataContext = viewModel,
// Set the data context for the main grid in the window.
MainGrid = { DataContext = viewModel },

// Set the owner of the window to the Dynamo window.
Owner = p.DynamoWindow
};
viewModel.dynamoViewModel = p.DynamoWindow.DataContext as DynamoViewModel;
assistantMenuItem = new MenuItem { Header = "Dynamo Gen-AI assistant", IsCheckable = true };
assistantMenuItem.Checked += (sender, args) => p.AddToExtensionsSideBar(this, window);
assistantMenuItem.Unchecked += (sender, args) => p.CloseExtensioninInSideBar(this);
p.AddExtensionMenuItem(assistantMenuItem);
}

public override void Shutdown()
{
}

public override void Closed()
{
if (assistantMenuItem != null)
{
assistantMenuItem.IsChecked = false;
}
}

public override string UniqueId
{
get
{
return "DA05ED05-6842-4CF0-9ADC-575888A01FEC";
}
}

public override string Name
{
get
{
return "Gen-AI assistant";
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<ImportGroup Label="PropertySheets">
<Import Project="$(SolutionDir)Config\CS.props" />
</ImportGroup>
<PropertyGroup>
<RootNamespace>DynamoAssistant</RootNamespace>
<AssemblyName>DynamoAssistantViewExtension</AssemblyName>
<!--Windows and WPF APIs are needed to support dynamo UI extensions-->
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DynamoVisualProgramming.DynamoServices" Version="3.1.0-beta4307" />
<PackageReference Include="DynamoVisualProgramming.WpfUILibrary" Version="3.1.0-beta4307" />
<PackageReference Include="DynamoVisualProgramming.ZeroTouchLibrary" Version="3.1.0-beta4307" />
<PackageReference Include="OpenAI" Version="1.10.0" />
<PackageReference Include="RestSharp" Version="108.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="DynamoAssistantViewExtension_ViewExtensionDefinition.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="AfterBuildOps" AfterTargets="Build">
<ItemGroup>
<PackageDll Include="$(ProjectDir)bin\$(ConfigurationName)\DynamoAssistantViewExtension.dll" />
<PackageXml Include="$(ProjectDir)bin\$(ConfigurationName)\DynamoAssistantViewExtension_ViewExtensionDefinition.xml" />
</ItemGroup>
<Copy SourceFiles="@(PackageDll)" DestinationFolder="$(ProjectDir)..\..\dynamo_viewExtension\Sample View Extension\bin" />
<Copy SourceFiles="@(PackageXml)" DestinationFolder="$(ProjectDir)..\..\dynamo_viewExtension\Sample View Extension\extra" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ViewExtensionDefinition>
<AssemblyPath>..\bin\DynamoAssistantViewExtension.dll</AssemblyPath>
<TypeName>DynamoAssistant.DynamoAssistantViewExtension</TypeName>
</ViewExtensionDefinition>
189 changes: 189 additions & 0 deletions src/DynamoAssistantViewExtension/DynamoAssistantWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<Window x:Class="DynamoAssistant.DynamoAssistantWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DynamoAssistant"
d:DataContext="{d:DesignInstance Type=local:DynamoAssistantWindowViewModel}"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Width="500"
Height="100">
<Grid Name="MainGrid"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">

<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Grid Name="Messages"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<ListView
ItemsSource="{Binding Messages}"
FontFamily="Arial"
Padding="10"
FontWeight="Medium"
FontSize="15"
Background="#2d2d2d"
Foreground="White"
Grid.Row="0"
Width="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="True">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=.}" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<Grid Name="Suggestions"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label
Content="Suggestions:"
FontSize="15"
FontWeight="Bold"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Grid.Row="0"
Grid.Column="0"
Background="#2d2d2d"
Foreground="White"/>

<Button
Content="Tell me what this graph does"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
HorizontalAlignment="Left"
Grid.Row="1"
Grid.Column="0"
Padding="10"
Click="DescribeGraphButton_Click"/>
<Button
Content="Generate annotations for me"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
Grid.Row="1"
Grid.Column="1"
Padding="10"
Click="MakeNoteButton_Click"/>
<Button
Content="Make groups for me"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
HorizontalAlignment="Left"
Grid.Row="2"
Grid.Column="0"
Padding="10"
Click="MakeGroupButton_Click"/>
<Button
Content="Optimize my graph for me"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
HorizontalAlignment="Center"
Grid.Row="2"
Grid.Column="1"
Padding="10"
Click="OptimizeGraphButton_Click"/>
<Button
Content="Help me create a graph"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
HorizontalAlignment="Right"
Grid.Row="2"
Grid.Column="2"
Padding="10"/>
<Button
Content="Show me what's new in Dynamo"
Width="200"
Height="50"
Background="#2d2d2d"
Foreground="White"
Grid.Row="1"
Grid.Column="2"
Padding="10"
Click="WhatsNewButton_Click"/>
</Grid>
</Grid>

<Grid Name="TextInput"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<ScrollViewer
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Grid.Column="0">
<TextBox
Name="UserInput"
Text="{Binding UserInput, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsWaitingForInput}"
FontFamily="Arial"
Padding="10"
FontWeight="Medium"
FontSize="15"
Background="#2d2d2d"
Foreground="White"
AcceptsReturn="True"
TextWrapping="Wrap"
Height="50">
<TextBox.InputBindings>
<KeyBinding Key="Return"
Command="{Binding EnterCommand}"
CommandParameter="{Binding ElementName=UserInput, Path=Text}"/>
</TextBox.InputBindings>
</TextBox>
</ScrollViewer>

<Button
Content="➡"
FontSize="25"
Click="SendButton_Click"
Width="50"
Height="50"
Grid.Column="1"
Background="#2d2d2d"
Foreground="White"
IsEnabled="{Binding IsWaitingForInput}"/>
</Grid>


</Grid>
</Window>
47 changes: 47 additions & 0 deletions src/DynamoAssistantViewExtension/DynamoAssistantWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Windows;

namespace DynamoAssistant
{
/// <summary>
/// Interaction logic for SampleWindow.xaml
/// </summary>
public partial class DynamoAssistantWindow : Window
{
internal DynamoAssistantWindowViewModel ViewModel => MainGrid.DataContext as DynamoAssistantWindowViewModel;
public DynamoAssistantWindow()
{
InitializeComponent();
}

private void SendButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.SendMessage(UserInput.Text);
ViewModel.UserInput = string.Empty;
}

private void DescribeGraphButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.DescribeGraph();
}

private void OptimizeGraphButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.OptimizeGraph();
}

private void WhatsNewButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.WhatsNew();
}

private void MakeNoteButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.MakeNote();
}

private void MakeGroupButton_Click(object sender, RoutedEventArgs e)
{
ViewModel.MakeGroup();
}
}
}
Loading