How to link the BasicDockPanePlugin to the command ID of CustomRibbon?

How to link the BasicDockPanePlugin to the command ID of CustomRibbon?

Anonymous
Not applicable
1,556 Views
5 Replies
Message 1 of 6

How to link the BasicDockPanePlugin to the command ID of CustomRibbon?

Anonymous
Not applicable
Hi, I want to link a HelloWorldDockPane to a command button in CustomRibbon,like button_3. Then the dockpane will show in the NW windows when I click the button_3. However, the following codes can't work successfully。 I have no idea about the reason. Thx. ____________________________________________________________________________ using System; using System.Windows.Forms; using Autodesk.Navisworks.Api.Plugins; using BasicDockPanePlugin; namespace CustomRibbon { [Plugin("CustomRibbonCommandHandler", "ADSK", DisplayName = "Custom Ribbon")] [Strings("CustomRibbon.name")] [RibbonLayout("CustomRibbon.xaml")] [RibbonTab("ID_CustomTab_1", DisplayName = "Custom Tab 1 - non-localised")] [Command("ID_Button_3", CanToggle = true, Shortcut = "Shift+Z")] public class CustomRibbonCommandHandler : CommandHandlerPlugin { public CustomRibbonCommandHandler() { m_button3_on = false; } public override int ExecuteCommand(string commandId, params string[] parameters) { if (commandId == "ID_Button_3") { m_button3_on = !m_button3_on; } return 0; } public override CommandState CanExecuteCommand(String commandId) { CommandState state = new CommandState(); if (commandId == "ID_Button_3") { state.IsEnabled = true; state.IsChecked = m_button3_on; } return state; } public bool m_button3_on; public Control CreateControlPane() { HelloWorldControl control = new HelloWorldControl(); control.Dock = DockStyle.Fill; //localisation control.Text = this.TryGetString("HelloWorldText"); if (m_button3_on) { control.CreateControl(); } return control; } public void DestroyControlPane(Control pane) { pane.Dispose(); } } }
0 Likes
1,557 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
 
0 Likes
Message 3 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

 

Hi,

 

Plus what you have emailed me in private, you have misunderstood the following:

 

1)      CommandHandlerPlugin is just to create Ribbon interfaces. It cannot create the Dock Pane Window. You must write a DockPanePlugin to create your Dock Pane Window. Please refer to the SDK sample BasicDockPanePlugin.

2)      As the SDK code explains: The ability of the attribute ShortcutWindowTypes of CommandHandlerPlugin is:

If you have defined a DockPanePlugin, you can specify that the Shortcut only applies when that window is active. Use the Id for the  DockPanePlugin. This attribute is just to specify if the shortcut can work or not.

 

Then, what ShortcutWindowTypes works for? Assume we have had a DockPanePlugin e.g. BasicDockPanePlugin. And in CommandHandlerPlugin, we define a command e.g.

 

            [Command("ID_Button_3",

                               CanToggle = true,

                               Shortcut="Shift+Z")]

 

In default, the shortcut can work anytime when we press “Shift+Z”. But if we add the attribute  ShortcutWindowTypes

,

         [Command("ID_Button_3",

                           CanToggle = true,

                           Shortcut = "Shift+Z",

                           ShortcutWindowTypes = "BasicDockPanePlugin.BasicDockPanePlugin.ADSK")]

 

What will happen?

 

-        If the window of BasicDockPanePlugin is not displayed and not activate(Activate means it is being focused), the shortcut will NOT work anymore.

 

-        If the window of BasicDockPanePlugin is displayed and activate, the shortcut will work as normal.

 

In a word, this attribute is just to specify if the shortcut can work or not. In addition, when you set ShortcutWindowTypes, please make sure to set the correct ID (name) of the DockPanePlugin. Otherwise, the shortcut will still work.

 

Hope this explains.

 

 

0 Likes
Message 4 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Back to your original question:  how can I make my dock pane window visible when a button of my Ribbon clicked?

 

Every dock pane window is linked with one DockPanePlugin. In the execute function of the Ribbon button, you can get the plugin by AddInPluginRecord (searching by its name). And call DockPanePlugin.Visible = true. e.g.

 

  DockPanePlugin oDockPlugin =

    (DockPanePlugin)Autodesk.Navisworks.Api.Application.Plugins.FindPlugin("BasicDockPanePlugin.BasicDockPanePlugin.ADSK").LoadedPlugin;

 

  oDockPlugin.Visible = true;

0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi,

I have solved the problem about link a DockPane to the CustomRibbon.

Then an problem appears: how can I make the selection tree shown in the DockPane? 

Thx.

0 Likes
Message 6 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Firstly, if your further question is not related with the original question, I suggest you create a new post thus if any developer has answer, he may be interested in jumping into to help you.

 

You have confused something. There is NOT any .NET API to provide the Selection Tree as same as the product displays. It completely requires you  to build the tree yourself. When you have a dock pane, you can place Tree View control of Windows. This control is managed by yourself. thus you can add any nodes and construct its hierarchy. While the model hierarchy of Navisworks is exposed in terms of tree hierarchy. Each node is a ModelItem. So the simplest way is to iterate the model from RootItem, its children, to its decadences, and add them one by one to the Tree View control.

 

I would suggest you take a look at the MSDN help to get started with Tree View control. And there are many posts on web on Tree View control.

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx

0 Likes