Timeliner API-part1

By Xiaodong Liang

Navisworks 2012 .NET API provides the ability to access TimeLiner information. Using the TimeLiner API, you can access TimeLiner document data, and create/query/modify tasks and task types as well as simulation appearances. You can also query model items attached to tasks, and define your own data source for tasks. In this article, we will look at these functionalities with Navisworks TimeLiner .NET API.

Getting TimeLiner Information

The top most objects of the TimeLiner API are IDocumentTimeliner and DocumentTimeliner.  IDocumentTimeliner is an intermediary interface and is defined in the Autodesk.Navisworks.Api namespace. We use it to access Timeliner object from a given document.  DocumentTimeliner class is defined in the Autodesk.Navisworks.Timeliner namespace. We use this to further access the information in the Timeliner object.

To access a Timeliner object, you first obtain IDocumentTimeliner object from the document, we then cast to the DocumentTimeliner class. Alternatively, we can access Timeliner object from a document using Timeliner.TimelinerDocumentExtensions.GetTimeliner(Document) method. We can then further access for more information from the properties and methods of the DocumentTimeliner object; for example, for further drilling down the data sources.

The code below shows a sample code to dump the data sources and tasks to the debug window:

// get Timeliner of the document
using Nw = Autodesk.Navisworks.Api;
using Tl = Autodesk.Navisworks.Api.Timeliner;
public void DumpTimeLinerInfo()
{
  // get Timeliner of the document
 
  Nw.Document doc = Nw.Application.ActiveDocument;
  Nw.DocumentParts.IDocumentTimeliner tl = doc.Timeliner;
  Tl.DocumentTimeliner tl_doc = (Tl.DocumentTimeliner)tl;
 
// alternatively, you can also use a static method that slightly 
// simplifies the access to the DocumentTimeLiner slightly. 
 
//Tl.DocumentTimeliner tl_doc2 = Tl.TimelinerDocumentExtensions.GetTimeliner(doc);
 
  // dump some information of each data source
 
  foreach (Tl.TimelinerDataSource oDS in tl_doc.DataSources)
  {
    Debug.Write("n DisplayName: " + oDS.DisplayName +
      "n ProviderName: " + oDS.DataSourceProviderName);                                
 
    foreach (Tl.TimelinerDataSourceField oTlF in oDS.AvailableFields)
    {
      Debug.Write("n DisplayName:  " + oTlF.DisplayName);                      
    }                     
  } // end dump data sources        
 
  // dump some information of each task
 
  foreach (Tl.TimelinerTask oTask in tl_doc.Tasks)
  { 
    Debug.Write("n  DisplayName: " + oTask.DisplayName +                                  
      "n  Planned Start: " + oTask.PlannedStartDate.ToString());
 
    // you can also access selection of a given task 
    // (although we aren’ˉt printing out here.) 
 
    Tl.TimelinerSelection oTlSel = oTask.Selection;
 
    if (oTlSel != null) {
      if(oTlSel.HasExplicitSelection) {
        Nw.ModelItemCollection oExplicitSel = oTlSel.ExplicitSelection;
      }
      if (oTlSel.HasSearch) {
        Nw.Search oSearch = oTlSel.Search; 
      }
    }
  } //end dump tasks
}

Attaching a Selection to a Task

To attach the selection to a task, you first need to make a copy of the task, modify the copy and replace the original with the copy. The code below shows an example of attaching the current selection to all the tasks at the root level:

// attach a current selection to the time liner tasks at the root level 
 
public void AttachSelection()
{
    // get the Timeliner document part from an active document
    Document main_doc = Application.ActiveDocument;
    Tl.DocumentTimeliner doc_tl = Tl.TimelinerDocumentExtensions.GetTimeliner(main_doc);
 
    // copy the current set of tasks. get the current selection. 
    GroupItem root_copy = doc_tl.TasksRoot.CreateCopy() as GroupItem;
    Selection current = main_doc.CurrentSelection;
 
    // walk through the tasks at the root level and attach the current selection
    foreach (Tl.TimelinerTask task in root_copy.Children)
    {  // attach the selection
        task.Selection.CopyFrom(current);
    }
    // replace the timeliner tasks
    doc_tl.TasksCopyFrom(root_copy.Children);
}

Note: the code above does not go through the hierarchy. We also assume that the tasks have valid TaskTypes, DataSources and ExternalId, which should be the case if you haven’t touched them yet.


Comments

9 responses to “Timeliner API-part1”

  1. Dickins John Avatar
    Dickins John

    How to access the properties of the active element in time liner simulation of Navisworks?

  2. Dickins John Avatar
    Dickins John

    public void DumpTimeLinerInfo()
    shows error: “expected class, delegate, enum interface or struct”
    what should be done for this??

  3. xiaodong Avatar
    xiaodong

    sorry, no API for Simulation currently

  4. xiaodong Avatar
    xiaodong

    I am not sure how you created your project. Have you added the dlls of TimeLiner? In which line the error popped out?

  5. 使用timeliner的api出现未能加载文件或程序集“Autodesk.Navisworks.Timeliner.dll”或它的某一个依赖项。找不到指定的模块。

  6. Hi
    How can I change a Navis field in exist task ( for example .LaborCost )
    I want manage exist Task in Navis (data source , or manual ) with .NET

  7. ramy adel Avatar
    ramy adel

    i need to do the same thing , so kindly if you reach to a solution for this issue please contact me as fast as you can …thanks in advance

  8. danyalahmed Avatar
    danyalahmed

    does anyone know how to write code for export data of planned start and end date from timeliner using C# to plugin………….

  9. Ramy adel Avatar
    Ramy adel

    Same here, if anyone could help,it would be a great.

Leave a Reply to BabakCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading