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;
}
}