Double click to open the hyperlink

By Xiaodong Liang

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.

<

p align=”left” class=”MsoNormal” style=”line-height: normal;margin: 0cm 0cm 0pt”>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;

 

        }

 

    }

}

 

image

 

image


Comments

3 responses to “Double click to open the hyperlink”

  1. Hello
    Thanks for this program but I tried to run this program with Visual studio 2012 and Navisworks Manage 2015 and the program gives me an error when double clicking.
    do you have an idea of the problem?
    thanck
    Patrick

  2. Hi Patrick,
    This code still works well in Navisworks 2016 at my side. It looks it can work when the object has at least one URL that is attached, otherwise, it will crash. but you can add try-catch for
    ComApi.InwURLOverride oURLOver = state.GetOverrideURL(oPathInCOMAPI);
    hope this helps.

  3. Antonio Perez Avatar
    Antonio Perez

    Hello,
    I assume It won’t work on Navisworks Freedom.
    Thanks.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading