Navisworks API Training
Lab 5 – Properties
© 2015 Autodesk
Agenda
Object Properties
Find Properties
© 2015 Autodesk
Object Properties
© 2015 Autodesk
.NET API
[Link]
PropertyCategoryCollection
PropertyCategory
[Link]
DataPropertyCollection
DataProperty
Current .NET API cannot modify/add custom
properties. Need COM API
© 2015 Autodesk
Properties Name
• Meaningful name
• Independent of languages
• Pre-define strings, easy to use
• Internal name
• Independent of languages
• Named from the class definition of API
• Display name
• What the end users can see in
• Localization
Meaningful Name Internal Name Display Name
(English)
[Link] LcOaNode Item
[Link] LcOpDwgEntityAttribs Entity Handle
[Link] LcOaNodeLayer Layer
[Link] LcOaNat64AttributeValue Value
© 2015 Autodesk
NamedConstant & VariantData
• NamedConstant
• Identifier for a value combining the internal
constant's name and a localized display
name equivalent
• VariantData
• A value type that can store data of one of
several different types
• [Link]
• Check type before print out the value
© 2015 Autodesk
Iterate Properties Demo
Document oDoc = [Link];
if ([Link] > 0)
{
StringBuilder output = new StringBuilder(1000);
[Link]("Dump Property Category of Current Selected Item\n");
//dump the first item only
ModelItem oItem = [Link][0];
foreach (PropertyCategory oPC in [Link])
{
//each category
[Link](" Display Name: " + [Link] + " Internal Name" + [Link] + "\n");
[Link](" Properties\n");
foreach (DataProperty oDP in [Link])
{
//each property
[Link](" [Display Name]: " + [Link] + "[Internal Name]:" + [Link]);
if ([Link])
//if the value is display string
[Link]("[Value]: " + [Link]() + "\n");
else if ([Link])
//if the value is a date
[Link]("[Value]: " + [Link]().ToShortTimeString() + "\n");
else
//other types
[Link]("<Other types of values>" + "\n");
}
}
}
© 2015 Autodesk
Get Property by Method
• PropertyCategoryCollection
• Various methods to get property
category and property, e.g.
• FindCategoryByDisplayName
• find property category by display name only
• FindCategoryByName
• find property category by internal name only
• FindPropertyByDisplayName
• find property by display name only
• FindPropertyByName
• find property by internal name only
© 2015 Autodesk
Demo: Get Categories by Display
Name
ModelItem oSelectedItem = [Link]<ModelItem>(0);
//get property category by display name
PropertyCategory oPC_DWGHandle =
[Link]("Entity Handle");
//by internal name
PropertyCategory oPC_DWGHandle1 =
[Link]
([Link]);
//by combined name
PropertyCategory oPC_DWGHandle2 =
[Link](new
NamedConstant([Link], "Entity Handle"));
© 2015 Autodesk
Demo: Get Categories by Methods
ModelItem oSelectedItem = [Link]<ModelItem>(0);
//get property category /by display name
PropertyCategory oPC_DWGHandle =
[Link]("Entity Handle");
//by internal name
PropertyCategory oPC_DWGHandle1 =
[Link]
([Link]);
//by combined name
PropertyCategory oPC_DWGHandle2 =
[Link](new
NamedConstant([Link], "Entity Handle"));
© 2015 Autodesk
Demo: Get Properties by Methods
//by display name (property caterogy and property)
DataProperty oDP_DWGHandle =
[Link]("Entity Handle", "Value");
//by internal name
DataProperty oDP_DWGHandle1 =
[Link]([Link],
[Link]);
//by combined name
DataProperty oDP_DWGHandle2 =
[Link](
new NamedConstant([Link], "Entity Handle"
new NamedConstant([Link], "Value"));
//display the value of the DWG handle
[Link](oDP_DWGHandle.[Link]());
© 2015 Autodesk
Add Custom Properties
See Lab 09 [COM Interop]
© 2015 Autodesk
Unique Identifier of Object
[Link]
Same to Item>>Guid in UI
Available for some file formats only (Revit, AutoCAD)
Properties from source CAD file
Some format provides a kind of ID that could be an identifier such as
AutoCAD Handle, Guid of Microstation.
Revit file
Recommend with Elements Properties>>UniqueId.
© 2015 Autodesk
Exercise
Create a plugin
Check the language of Navisworks.
Use the display name of local
language to find some properties
© 2015 Autodesk
© 2015 Autodesk, Inc. All rights reserved.