We have introduced how to add hyperlink in this blog. A further requirement is to open the hyperlink when the user double clicks the object. This will need a couple of APIs:
- InputPlugin to interact with UI for mouse clicking
- A common plugin (say AddInPlugin) to provide a button to invoke InputPlugin
- Call state.GetOverrideURL of COM to get the hyperlinks of the object
The following are a demo code. The plugin EnableToolPluginExample will create a button under Tool Add-ins tab. When the button is clicked, the custom interactive mode is activated. When the user double clicks an object, the first URL will be opened in the default browser.
The complete project is available Download DoubleClick_Hyperlink.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
using ComApi = Autodesk.Navisworks.Api.Interop.ComApi;
usingComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;
using Nw = Autodesk.Navisworks.Api;
namespace ToolPluginDemo
{
// The ToolPlugin example.
[Plugin("ToolPluginTest", "ADSK")]
publicclassToolPluginTest : ToolPlugin
{
ModelItem clickedModel = null;
publicoverridebool MouseDown(View view,
KeyModifiers modifiers,
ushort button,
int x,
int y,
double timeOffset)
{
if(modifiers == KeyModifiers.DoubleClick)
{
// get current selection
PickItemResult itemResult =
view.PickItemFromPoint(x, y);
if (itemResult != null)
{
clickedModel =
itemResult.ModelItem;
ComApi.InwOpState10 state = ComBridge.State;
ComApi.InwOaPath3 oPathInCOMAPI = ComBridge.ToInwOaPath(clickedModel) as ComApi.InwOaPath3;
ComApi.InwURLOverride oURLOver = state.GetOverrideURL(oPathInCOMAPI);
if (oURLOver.URLs().Count > 0)
{
//open the first URL
ComApi.InwURL oURL = oURLOver.URLs()[1];
//use default browser to open
if(oURL.URL.Length>0)
System.Diagnostics.Process.Start(oURL.URL);
System.Diagnostics.Debug.Write(oURL.name);
}
}
}
returnfalse;
}
}
[Plugin("EnableToolPluginExample", "ADSK",
DisplayName = "EnableToolPlugin")]
publicclassEnableToolPluginExample : AddInPlugin
{
staticbool enable = false;
publicoverrideint Execute(paramsstring[] parameters)
{
if (enable)
{
//switch to the native tool
Application.MainDocument.Tool.Value = Tool.Select;
}
else
{
//switch to custom tool
ToolPluginRecord toolPluginRecord =
(ToolPluginRecord)Application.Plugins.FindPlugin(
"ToolPluginTest.ADSK");
Application.MainDocument.Tool.
SetCustomToolPlugin(toolPluginRecord.LoadPlugin());
}
enable = !enable;
return 0;
}
}
}