continued with Timeliner API-part2
Programmatically Refreshing Data Source
If we want to refresh a data source as we do in the UI, the relevant source code would be something like the following. Notice methods, DocumentTimeliner.TaskMergeRebuild(), TaskMergeSynchronize(), DataSourceReplaceWithCopy() toward the end of the code.
// Refresh Data Source
// Get the timeliner object
Nw.Document doc = Nw.Application.ActiveDocument;
Nw.DocumentParts.IDocumentTimeliner tl = doc.Timeliner;
Tl.DocumentTimeliner tl_doc = (Tl.DocumentTimeliner)tl;
String name = "MyTLDSName";
// Find the relevant data source and its provider.
Tl.TimelinerDataSource ds = tl_doc.DataSourceFindByDisplayName(name).CreateCopy();
Tl.TimelinerDataSourceProvider provider =
Tl.TimelinerDataSourceProvider.FindDataSourceProvider(data_source).
LoadedPlugin as Tl.TimelinerDataSourceProvider;
if (null != provider && provider.IsAvailable)
{
// call ImportTasks on that copy.
Tl.TimelinerImportTasksResult result = provider.ImportTasks(ds);
// get tasks from data source
Tl.TimelinerTask task = result.RootTask;
// merge with existing tasks
// Rebuild :oReplace the hierarchy of tasks relating to the specified hierarchy,
// but retain any Navisworks TimelinerTask data such as attached selections,
// scripts, animations etc.
tl_doc.TaskMergeRebuild(task, result.TaskTypeWasSet.Value);
//Synchronize
tl_doc.TaskMergeSynchronize(task, result.TaskTypeWasSet.Value);
//replace with updated data source - update sync time
tl_doc.DataSourceReplaceWithCopy(tl_doc.DataSources.IndexOfDisplayName(name), ds);