Navisworks API

Navisworks API

Reply
Member
3 Posts
0 Kudos
Registered: ‎08-06-2012
Post 1 of 6

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

350 Views, 5 Replies
08-06-2012 06:59 PM
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(); } } }
Member
3 Posts
0 Kudos
Registered: ‎08-06-2012
Post 2 of 6

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

08-06-2012 07:14 PM in reply to: susanvv
 
ADN Support Specialist
1,352 Posts
81 Kudos
Registered: ‎06-12-2011
Post 3 of 6

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

08-09-2012 04:02 AM 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.

 

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

ADN Support Specialist
1,352 Posts
81 Kudos
Registered: ‎06-12-2011
Post 4 of 6

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

08-09-2012 04:17 AM in reply to: xiaodong.liang

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;



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Member
3 Posts
0 Kudos
Registered: ‎08-06-2012
Post 5 of 6

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

08-22-2012 10:25 PM 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.

ADN Support Specialist
1,352 Posts
81 Kudos
Registered: ‎06-12-2011
Post 6 of 6

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

08-28-2012 01:53 AM 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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!