Navisworks 2014 API new feature – InputPlugin

By Xiaodong Liang

This new plugin allows you to handle the interaction events such as mouse and keyboard. By this plugin, you could also know the selected object.

Firstly, create a class deriving from InputPlugin. It is a kind of implicit plugin which has no interface. So the attribute DisplayName is useless.

// The InputPlugin example.        [Plugin("MyInputPlugin", "ADSK")]        public class InputPluginExample : InputPlugin        {        }

Next, override the events you want to use. The plugin provides various events. It is not difficult to know what they fire for from their names.

KeyDown
KeyDrag  
KeyUp 
ModifierKeyDown
ModifierKeyUp 
MouseDown 
MouseDrag 
MouseLeave
MouseMove 
MouseUp 
WheelDrag

I’d introduce MouseDown and KeyDown. The last argument timeOffset is not clear to me. I will update this post when I figure it out.

public override bool MouseDown(                //the current view when mouse down                 View view,                  //Enumerates key modifiers used in input:                 //None, Ctrl,Alt,Shift                 KeyModifiers modifiers,                //left mouse button:1,                 //middle mouse button:2,                //right mouse button:3                ushort button,                //screen coordinate x                int x,                //screen coordinate y                int y,                  // not clear to me :-(                  double timeOffset)                   public override bool KeyDown(                  //the current view when mouse down                  View view,                  //Enumerates key modifiers used in input:                   //None, Ctrl,Alt,Shift                   KeyModifiers modifier,                   //the key pressed                  ushort key,                  // not clear to me :-(                    double timeOffset)

 

View.PickItemFromPoint(x,y) returns the information about selecting: selected objects and selected point in WCS. where x,y is the coordinates in screen.

// The InputPlugin example.        [Plugin("MyInputPlugin", "ADSK")]        public class InputPluginExample : InputPlugin        {               public override bool MouseDown(                //the current view when mouse down                 View view,                  //Enumerates key modifiers used in input:                 //None, Ctrl,Alt,Shift                 KeyModifiers modifiers,                //left mouse button:1,                 //middle mouse button:2,                //right mouse button:3                ushort button,                //screen coordinate x                int x,                //screen coordinate y                int y,                  // not clear to me :-(                  double timeOffset)            {                // key modifiers used in input                Debug.Print(modifiers.ToString());                //left/middle mouse                Debug.Print(button.ToString());                //timeOffset                Debug.Print(timeOffset.ToString());                     // get info of selecting                PickItemResult itemResult =                                 view.PickItemFromPoint(x, y);
                 if (itemResult != null)                {                      //selected point in WCS                   string oStr = string.Format(                       "{0},{1},{2}", itemResult.Point.X,                                  itemResult.Point.Y,                                   itemResult.Point.Z);                   Debug.Print(oStr);                         //selected object                    ModelItem modelItem = itemResult.ModelItem;                    System.Windows.Forms.MessageBox.Show (                                     modelItem.ClassDisplayName);                }                     return false;            }                 public override bool KeyDown(                //the current view when mouse down                View view,                //Enumerates key modifiers used in input:                 //None, Ctrl,Alt,Shift                 KeyModifiers modifier,                 //the key pressed                ushort key,                // not clear to me :-(                  double timeOffset)            {                //  key modifiers + pressed key                Debug.Print(modifier.ToString() + ", " + key);                return false;            }         }

Comments

3 responses to “Navisworks 2014 API new feature – InputPlugin”

  1. Great, will these events support in viewcontrol?

  2. Afshin Jafari Avatar
    Afshin Jafari

    Hi Xiaodong,
    Thanks for the explanation,
    I have tried this plugin (InputPlugin) but unfortunately the MouseDown only fires when the Left click happens. middle click and right click won’t fire.
    mouse up will fire only Left as well, with a little weird behaviour: if you double click on middle, it will fire mouse up too with button = 0!
    modifires is not populating Alt key.
    as far as I can say this plugin is not even tested by autodesk developers and testers?
    am I missing something?
    Regards,
    Afshin

  3. Good post!
    I’ve got an inputPlugin that I’ve put together, which intercepts the mouse clicks to record data as I measure. One issue that I’ve found is that I want to make it ignore right-click default behaviour while the tool is active (specifically because I don’t want it to cancel the measurement tool), however it still seems to do the right-click action. Any thoughts on how to intercept the right-click and ensure that it does nothing?

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading