ToolPlugin is actually a combination of InputPlugin and RenderPlugin. It allows you to customize the tool. Typically, it configures the behavior when mouse clicking the object. So you could switch between the native tool of Navisworks and your tools.
Firstly, create a class deriving from ToolPlugin . It is a kind of implicit plugin which has no interface. So the attribute DisplayName could be ignored. Next, override the methods you want to use. e.g. the following code demo overrides MouseDown and OverlayRenderModel. When the mouse clicks, it records the selected object, next draws a custom graphics with the bounding box of the object. In another word, when the mouse clicks the object, it will not highlight the object anymore, it will draw a temporary cuboids.
// The ToolPlugin example.
[Plugin("ToolPluginTest", "ADSK")]
public class ToolPluginTest : ToolPlugin
{
ModelItem clickedModel = null;
public override bool MouseDown(View view,
KeyModifiers modifiers,
ushort button,
int x,
int y,
double timeOffset)
{
// get current selection
PickItemResult itemResult =
view.PickItemFromPoint(x, y);
if (itemResult != null)
{
clickedModel =
itemResult.ModelItem;
Application.ActiveDocument.ActiveView.
RequestDelayedRedraw(ViewRedrawRequests.Render);
}
return false;
}
public override void OverlayRenderModel(View view, Graphics graphics)
{
if (clickedModel != null)
{
//color for graphics
Color yellow = Color.FromByteRGB(255, 255, 0);
graphics.Color(yellow, 0.8);
//boundingbox of the current selection
BoundingBox3D boundingBox = clickedModel.BoundingBox();
Point3D origin = boundingBox.Min;
Vector3D xVector =
new Vector3D((boundingBox.Max -
boundingBox.Min).X, 0, 0);
Vector3D yVector =
new Vector3D(0, (boundingBox.Max -
boundingBox.Min).Y, 0);
Vector3D zVector =
new Vector3D(0, 0, (boundingBox.Max -
boundingBox.Min).Z);
//draw a cuboid
graphics.Cuboid(origin, xVector, yVector, zVector, true);
}
}
}
To let Navisworks know to use your tool, you will need to write some codes in your main workflow (e.g. main plugin). Find your tool plugin, and set it as a current tool by
Tool.SetCustomToolPlugin
To switch back to the native tool of Navisworks, you could just set the tool to any mode of navigation.
[Plugin("EnableToolPluginExample", "ADSK",
DisplayName = "EnableToolPlugin")]
public class EnableToolPluginExample : AddInPlugin
{
static bool enable = false;
public override int Execute(params string[] 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;
}
}