|
|
Through the Takeoff Api developers have access to the majority of Quantification Takeoff functionality and data available through the GUI.
Details
| Assembly | Autodesk.Navisworks.Takeoff.dll |
| Namespace | Autodesk.Navisworks.Api.Takeoff |
Access
Access to Quantification functionality is via the Document..::..Takeoff If Quantification is available in your product, then this is non-null. The returned interface must be cast to a DocumentTakeoff before it can be used.
If you are using C# and using the Autodesk.Navisworks.Api.Takeoff namespace then the extension method: DocumentExtensions..::..GetTakeoff can be used for conveninence to handle the cast for you.
DocumentTakeoff docTakeoff =
Autodesk.Navisworks.Api.Application.MainDocument.Takeoff as DocumentTakeoff;
DocumentTakeoff docTakeoff2 =
Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff();
Classes
All classes are contained in the Autodesk.Navisworks.Api.Takeoff Namespace.
| Class | Key Information |
|---|---|
| DocumentExtensions |
Class where extensions to the Document class for the DocumentTakeoff document part class. |
| DocumentTakeoff |
Provides access to the various document-parts associated with takeoff. |
| ItemGroupTable |
Configuration information for ItemGorupTable. |
| ItemTable |
Configuration information for ItemTable. |
| ObjectResourceTable |
Configuration information for ObjectResourceTable. |
| ObjectStepTable |
Configuration information for ObjectStepTable. |
| ObjectTable |
Configuration information for ObjectTable. |
| ResourceGroupTable |
Configuration information for ResourceGroupTable. |
| ResourceTable |
Configuration information for ResourceTable. |
| StepResourceTable |
Configuration information for StepResourceTable. |
| StepTable |
Configuration information for StepTable. |
| TakeoffTable |
provides common base class for features shared by all Tables. |
| TakeoffTableSelection |
Represents the selection in one table. |
| TakeoffColumnDefinition |
The definition of the fixed column in takeoff table. |
| TakeoffProjectSettings |
Access project settings. |
| TakeoffSelection |
Entry point of the selection of each table. |
| TakeoffSelectionChangeEventArgs |
Used in TakeoffSelection Changed event to pass which tables are being modified. |
| TakeoffSheetIds |
Access sheet ids. |
| TakeoffVariable |
Represent a variable. |
| TakeoffVariableCollection |
Represent a row data of configurable columns. |
| TakeoffVariableDefinition |
The definition of the variable column in takeoff table. |
| TakeoffVariableDefinitionCollection |
A collection of config column definitions. |
Examples
Quantification supports two levels of API. The first level uses SQL to query, or modify the Quantification database directly. The second level provides classes to represent takeoff data, and allows data-access, modification, and synchronization with the UI. The following examples demonstrate some common operations.
DocumentTakeoff..::..Loaded raise after Quantification become available, any Quantification related operation should after the event.
DocumentTakeoff..::..Unloading raise before Quantification destruct itself, any clean work should operate when receive the event.
Int64 GetLastInsertRowId()
{
DocumentTakeoff docTakeoff = Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff();
using (NavisworksCommand cmd = docTakeoff.Database.Value.CreateCommand())
{
//use SELECT ... FROM ... WHERE ... sql for query.
//last_insert_rowid() is a stored function used to retrieve the rowid of the last insert row
cmd.CommandText = "select last_insert_rowid()";
using (NavisWorksDataReader dataReader = cmd.ExecuteReader())
{
Int64 lastId = -1;
if (dataReader.Read())
{
Int64.TryParse(dataReader[0].ToString(), out lastId);
}
return lastId;
}
}
}
Int64 InsertItem(Int64? parent, String name, String description, String wbs, Int32 color, Double transparency)
{
Debug.Assert(name != null);
DocumentTakeoff docTakeoff = Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff();
ItemTable table = docTakeoff.Items;
Debug.Assert(table != null);
//Directly operate on database
//Database schema entry: TakeoffTable
//INSERT INTO TABLE(COL1,COL2,COL3...) VALUES(V1,V2,V3...);
String sql = "INSERT INTO TK_ITEM(parent, name, description, wbs, color, transparency) VALUES(@parent, @name, @description,@wbs, @color,@transparency)";
//Modification must be surrounded by NavisworksTransaction
using (NavisworksTransaction trans = docTakeoff.Database.BeginTransaction(DatabaseChangedAction.Edited))
{
using (NavisworksCommand cmd = docTakeoff.Database.Value.CreateCommand())
{
NavisworksParameter p = cmd.CreateParameter();
p.ParameterName = "@parent";
if (parent.HasValue)
p.Value = parent.Value;
else
p.Value = null;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@name";
p.Value = name;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@description";
p.Value = description;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@wbs";
p.Value = wbs;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@color";
p.Value = color;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@transparency";
p.Value = transparency;
cmd.Parameters.Add(p);
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
trans.Commit();
}
return GetLastInsertRowId();
}
Int64 DoTakeoff(Int64 itemId, Guid modelItemGuid)
{
DocumentTakeoff docTakeoff = Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff();
List<Autodesk.Navisworks.Api.ModelItem> items = Autodesk.Navisworks.Api.Application.MainDocument.Models.RootItemDescendantsAndSelf.WhereInstanceGuid(modelItemGuid).ToList();
Int64 lastId = -1;
if (items.Count != 0)
{
using (NavisworksTransaction trans = docTakeoff.Database.BeginTransaction(DatabaseChangedAction.Edited))
{
docTakeoff.Objects.InsertModelItemTakeoff(itemId, items[0]);
//Quantification UI actually expect the takeoff to have a non-empty wbs, so better to set the wbs for it using the sql way
lastId = GetLastInsertRowId();
Debug.Assert(lastId > 0);
using (NavisworksCommand cmd = docTakeoff.Database.Value.CreateCommand())
{
//UPDATE Object set WBS = value WHERE id = lastId;
cmd.CommandText = "UPDATE TK_OBJECT SET wbs = @wbs WHERE id = @id";
NavisworksParameter p = cmd.CreateParameter();
p.ParameterName = "@wbs";
p.Value = 1;
cmd.Parameters.Add(p);
p = cmd.CreateParameter();
p.ParameterName = "@id";
p.Value = lastId;
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
}
trans.Commit();
}
}
return lastId;
}
void UpdateTakeoffValue(Int64 objectId) { DocumentTakeoff docTakeoff = Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff(); //TakeoffVariableCollection TakeoffVariable are the entrance for read/update of the variables TakeoffVariableCollection variableCollection = docTakeoff.Objects.SelectInputVariables(objectId); Int32 lengthIndex = variableCollection.Find("ModelLength"); if (lengthIndex != -1) { TakeoffVariable lengthVariable = variableCollection.GetItem(lengthIndex); if (lengthVariable.IsAbleToSetValue) { lengthVariable.Value = Autodesk.Navisworks.Api.VariantData.FromDouble(5.6); using (NavisworksTransaction trans = docTakeoff.Database.BeginTransaction(DatabaseChangedAction.Edited)) { docTakeoff.Objects.UpdateInputVariables(objectId, variableCollection); trans.Commit(); } } } }
void SelectUIItem(Int64 itemId)
{
TakeoffSelection takeoffSelection = Autodesk.Navisworks.Api.Application.MainDocument.GetTakeoff().CurrentSelection;
takeoffSelection.BeginEdit();
takeoffSelection.Items.Clear();
takeoffSelection.ItemGroups.Clear();
takeoffSelection.StepResources.Clear();
takeoffSelection.Steps.Clear();
takeoffSelection.Items.Add(itemId);
takeoffSelection.EndEdit();
}