Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

5 REPLIES 5
Reply
Message 1 of 6
susanvv
804 Views, 5 Replies

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

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(); } } }
5 REPLIES 5
Message 2 of 6
susanvv
in reply to: susanvv

 
Message 3 of 6
xiaodong_liang
in reply to: susanvv

 

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.

 

 

Message 4 of 6

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;

Message 5 of 6
susanvv
in reply to: xiaodong_liang

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.

Message 6 of 6
xiaodong_liang
in reply to: susanvv

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report