The Navisworks Automation API

Customizing Autodesk® Navisworks® 2013 with
the .NET API
Simon Bee
Software Development Manager IPG-PDC Group
© 2012 Autodesk
Class Summary
This class will introduce you to customizing Autodesk Navisworks 2013
using the new .NET API. It will cover how to create add-ins that sit inside
the product and allow you to integrate with your own programs, how to
automate the product to perform process-intensive and repetitive tasks,
and how to embed the .NET controls in your own application to leverage
the powers of Navisworks.
© 2012 Autodesk
Learning Objectives
At the end of this class, you will be able to:
 Write a simple .NET plugin for Autodesk Navisworks Manage 2013.
 Understand how to automate Autodesk Navisworks.
 Write a simple application that uses the Autodesk Navisworks .NET
controls.
© 2012 Autodesk
Introduction to the Navisworks .NET API
© 2012 Autodesk
About Navisworks
© 2012 Autodesk
Navisworks APIs
NWcreate
.NET API
COM API
© 2012 Autodesk
Design Philosophy
“Easy things should be easy, hard things should be
possible”
© 2012 Autodesk
Applications of the .NET API
Plugins
Automation
Control-based Applications
© 2012 Autodesk
Assemblies
Autodesk.Navisworks.Api
Autodesk.Navisworks.Automation
Autodesk.Navisworks.Controls
Autodesk.Navisworks.ComApi
© 2012 Autodesk
The Main Navisworks .NET API
© 2012 Autodesk
Autodesk.Navisworks.Api
Create Plugins
Load and Save Documents
Query and Manipulate Models
© 2012 Autodesk
Main API Classes
© 2012 Autodesk
Main API Classes
Autodesk.Navisworks.Api.Application
Autodesk.Navisworks.Api.Document
Autodesk.Navisworks.Api.Model
Autodesk.Navisworks.Api.ModelItem
© 2012 Autodesk
Querying The Model
Active Document
Document doc = Application.ActiveDocument;
Get First Model
Model model = doc.Models[0];
Get Root Item
ModelItem root = model.RootItem;
Query Item
bool is_hidden = root.IsHidden;
© 2012 Autodesk
Object Properties
© 2012 Autodesk
Object Properties
Autodesk.Navisworks.Api.PropertyCategory
Autodesk.Navisworks.Api.DataProperty
© 2012 Autodesk
Access Object Properties
Finding Property Category
PropertyCategory prop_cat =
root.PropertyCategories.FindCategoryByName(
PropertyCategoryNames.Item);
Accessing Property Value
DataProperty prop =
prop_cat.Properties.FindPropertyByName(
DataPropertyNames.ItemName);
string value = prop.Value.ToDisplayString();
© 2012 Autodesk
Finding Items
Search
Search s = new Search();
ModelItemCollection searchResults = s.FindAll(false);
Iteration
foreach (ModelItem item in
Application.ActiveDocument.CurrentSelection.SelectedItems)
{
// Examine item here.
}
LINQ
IEnumerable<ModelItem> items =
from item in Application.ActiveDocument.Models.GetRootItems().DescendantsAndSelf
where ItemPrice(item) > 100
select item;
© 2012 Autodesk
Searching The Model
© 2012 Autodesk
Using The Search Class
Create A Search
Search search = new Search();
Add Selection and Conditions
search.Selection.SelectAll();
search.SearchConditions.Add(
SearchCondition.HasPropertyByName("LcRevitData“,
"LcRevitPropertyElementCategory").
EqualValue(VariantData.FromDisplayString("Stairs")));
Execute Search
ModelItemCollection items = search.FindAll(Application.ActiveDocument,
false);
Application.ActiveDocument.CurrentSelection.CopyFrom(items);
© 2012 Autodesk
Mixing Search Methods
Combine Search With LINQ
IEnumerable<ModelItem> expensive_items =
from item in search.FindIncremental(Application.ActiveDocument, false);
where ItemPrice(item) > 100
select item;
© 2012 Autodesk
Modifying The Model
© 2012 Autodesk
Document Parts
Application.ActiveDocument.CurrentSelection
Application.ActiveDocument.Models
Application.ActiveDocument.Tool
Application.ActiveDocument.SelectionSets
© 2012 Autodesk
Modifying The Model
Change Current Selection
IEnumerable<ModelItem> items =
Application.ActiveDocument.Models.GetRootItems().DescendantsAndSelf.
Where(x => x.IsHidden = false);
Application.ActiveDocument.CurrentSelection.CopyFrom(items);
Override Colour
Application.ActiveDocument.Models.OverridePermanentColor(items, Color.Red);
Change Tool
Application.ActiveDocument.Tool = Tool.Select;
© 2012 Autodesk
Responding To Events
DocumentPart Events
Changed
ModelGeometryMaterialChanged
Event Handlers
Application.ActiveDocument.CurrentSelection.Changed +=
new EventHandler<EventArgs>(CurrentSelection_Changed);
private void CurrentSelection_Changed(object sender, EventArgs e)
{
// Respond to event...
}
© 2012 Autodesk
Creating Plugins
© 2012 Autodesk
AddInPlugin
Autodesk.Navisworks.Api.Plugins.AddInPlugin
[PluginAttribute("MyPlugin", "ADSK",
ToolTip = "My Plugin", DisplayName = "My Plugin")]
public class MyPlugin : Autodesk.Navisworks.Api.Plugins.AddInPlugin
{
public override int Execute(params string[] parameters)
{
//
// Do stuff here!
//
return 0;
}
}
© 2012 Autodesk
Plugins In Action
Let’s Write Some Code!
© 2012 Autodesk
The Navisworks Automation API
© 2012 Autodesk
Autodesk.Navisworks.Automation
Automate Navisworks
Perform Batch Jobs
© 2012 Autodesk
Main Automation Class
Autodesk.Navisworks.Api.Automation.NavisworksApplication
static void Main(string[] args)
{
NavisworksApplication app = new NavisworksApplication();
app.OpenFile(@"C:\file\A.nwd");
app.AppendFile(@"C:\file\B.nwd");
app.ExecuteAddInPlugin(“Colouriser.ADSK");
app.SaveFile(@"C:\files\Combined.nwd");
}
© 2012 Autodesk
Automation In Action
Time To Automate Navisworks...
© 2012 Autodesk
The Navisworks .NET Controls
© 2012 Autodesk
Autodesk.Navisworks.Controls
.NET Controls for
rd
3
Party Applications
Utilise Large Model Capability
© 2012 Autodesk
Main Control Classes
Autodesk.Navisworks.Api.Controls.ApplicationControl
Autodesk.Navisworks.Api.Controls.DocumentControl
Autodesk.Navisworks.Api.Controls.ViewControl
© 2012 Autodesk
The Main Controls
© 2012 Autodesk
Controls In Action
A Very Simple Component Viewer
© 2012 Autodesk
The Navisworks COM Interop API
© 2012 Autodesk
Autodesk.Navisworks.ComApi
Autodesk.Navisworks.Api
Autodesk.Navisworks.Interop.ComApi
Autodesk.Navisworks.ComApi
COM
© 2012 Autodesk
Using COM Interop
Accessing Saved Views
InwOpState10 state = ComApiBridge.State;
InwSavedViewsColl views = state.SavedViews();
foreach (InwOpSavedView view in views)
{
comboBox1.Items.Add(view.name);
}
Converting to .NET API
InwOpSelectionSet set = (InwOpSelectionSet)sets[1];
ModelItemCollection items =
ComApiBridge.ToModelItemCollection(set.selection);
Application.ActiveDocument.CurrentSelection.CopyFrom(items);
© 2012 Autodesk
Q&A
Any questions?
© 2012 Autodesk
Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and
services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2012 Autodesk, Inc. All rights reserved.
© 2012 Autodesk