private void ButtonClick(object sender, RoutedEventArgs e) { Button but = e.Source as Button; string content = but.Content.ToString().ToUpper(); FrameworkElement fe = sender as FrameworkElement; FavouriteNodesViewModel dc = fe.DataContext as FavouriteNodesViewModel; ReadyParams rp = dc.ReadyParamType; var vlp = rp as ViewLoadedParams; var dynViewModel = vlp.DynamoWindow.DataContext as DynamoViewModel; var dm = dynViewModel.Model as DynamoModel; NodeSearchModel nsm = dm.SearchModel; List <Dynamo.Search.SearchElements.NodeSearchElement> nodes = nsm.SearchEntries.ToList(); List <int> nodePosition = new List <int>(); List <string> nodeNames = new List <string>(); for (int i = 0; i < nodes.Count; i++) { nodeNames.Add(nodes[i].FullName); if (nodes[i].FullName.ToUpper().Contains(content)) { nodePosition.Add(i); } } if (nodePosition.Count != 0) { MethodInfo dynMethod = nodes[(nodePosition[0])].GetType().GetMethod("ConstructNewNodeModel", BindingFlags.NonPublic | BindingFlags.Instance); object obj = dynMethod.Invoke(nodes[(nodePosition[0])], new object[] { }); NodeModel nM = obj as NodeModel; try { dm.ExecuteCommand(new DynamoModel.CreateNodeCommand(nM, 0, 0, true, false)); } catch (Exception) { } } }
public void Loaded(ViewLoadedParams p) { designtechMenuItem = new MenuItem { Header = "designtech" }; var VM = p.DynamoWindow.DataContext as DynamoViewModel; #region About designtechAboutMenuItem = new MenuItem { Header = "About" }; designtechAboutMenuItem.Click += (sender, args) => { //var viewModel = new GraphInformationViewModel(p); var window = new AboutWindow { Owner = p.DynamoWindow }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechAboutMenuItem); #endregion #region Node/Connector designtechNodeConnectorCountsMenuItem = new MenuItem { Header = "Node/Connector Counts" }; designtechNodeConnectorCountsMenuItem.Click += (sender, args) => { var viewModel = new CountsViewModel(p); var window = new CountsWindow { // 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 }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechNodeConnectorCountsMenuItem); #endregion #region Toggle Freeze designtechToggleFreezeMenuItem = new MenuItem { Header = "Toggle Freeze" }; designtechToggleFreezeMenuItem.Click += (sender, args) => { var viewModel = new ToggleFreezeViewModel(p); var window = new ToggleFreezeWindow { // 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 }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechToggleFreezeMenuItem); #endregion #region Group Navigation designtechGroupNavigationMenuItem = new MenuItem { Header = "Group Navigation" }; designtechGroupNavigationMenuItem.Click += (sender, args) => { var viewModel = new GroupNavigationViewModel(p); var window = new GroupNavigationWindow { // 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 }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechGroupNavigationMenuItem); #endregion #region Error Nodes designtechErrorNodesMenuItem = new MenuItem { Header = "Error Nodes" }; designtechErrorNodesMenuItem.Click += (sender, args) => { var viewModel = new ErrorNodesViewModel(p); var window = new ErrorNodesWindow { // 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 }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechErrorNodesMenuItem); #endregion #region Favourite Nodes designtechFavouriteNodesMenuItem = new MenuItem { Header = "Favourite Nodes" }; designtechFavouriteNodesMenuItem.Click += (sender, args) => { var viewModel = new FavouriteNodesViewModel(p); var window = new FavouriteNodesWindow { // 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 }; window.Left = window.Owner.Left + 400; window.Top = window.Owner.Top + 200; window.Show(); }; designtechMenuItem.Items.Add(designtechFavouriteNodesMenuItem); #endregion p.dynamoMenu.Items.Add(designtechMenuItem); }