Navisworks API

Navisworks API

Reply
New Member
tkachenko_truboprovod
Posts: 2
Registered: ‎10-18-2012
Message 1 of 3 (409 Views)
Accepted Solution

Adding a custom Task to Timeliner (or adding model selections to tasks)

409 Views, 2 Replies
10-18-2012 04:30 AM

Hi everybody!

I have to write a plugin, which adds some selection to every timeliner task. By selection i mean Autodesk.Navisworks.Api.Timeliner.TimelinerSelection class.

So, after user imports an MS Project file as a timeliner datasource, i get the timeliner object, i'm able to iterate through tasks and their children, BUT....

but i cannot write anything to a task or timeliner object - they are all read-only. I read about it in Developers Guide(collections returned by Navisworks are read-only, collections created programmatically are writeabe), i see ReadOnly == true in objects' properties, but i hope there is a solution for this.

So, does anybody know how to WRITE data to timeliner Tasks using .NET API?
 



This is how i get access to timeliner object:

public class navisTest :AddInPlugin
    {        static Document navDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

        static Autodesk.Navisworks.Api.DocumentParts.IDocumentTimeliner Itimeliner = navDoc.Timeliner;

        static DocumentTimeliner timeliner = (DocumentTimeliner)Itimeliner;

        TimelinerTask tsk = new TimelinerTask();

        foreach (TimelinerTask task in timeliner.Tasks)
        {
            foreach (TimelinerTask childTask in task.Children)
            {
                if (!childTask.Selection.IsClear)
                {
                    childTask.Selection.CopyFrom(newCollection);  //some  ModelItemCollection
                    //or CopyFrom(navDoc.CurrentSelection.SelectedItems.DescendantsAndSelf);
                    //anyway it crashes here - "object is readonly"
                }
            }
        }
    }

 


 

Also, i tried to create my own Task object and add it to timeliner - the same thing, it crashes:

TimelinerTask tsk = new TimelinerTask();
tsk.Selection.CopyFrom(navDoc.CurrentSelection.SelectedItems.DescendantsAndSelf);
timeliner.Tasks.Add(tsk);  //crashes here.

 

 

 

Thanks in advance,
Alexander.  :cathappy:
 

Hi,

 

The task cannot be manipulated directly. Please refer to the following code:

 

 Document navDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
Autodesk.Navisworks.Api.DocumentParts.IDocumentTimeliner Itimeliner = navDoc.Timeliner;
DocumentTimeliner timeliner = (DocumentTimeliner)Itimeliner;
GroupItem root_copy = timeliner.TasksRoot.CreateCopy() as GroupItem;
TimelinerTask tsk = new TimelinerTask();
try
{
tsk.Selection.CopyFrom(navDoc.CurrentSelection.SelectedItems.DescendantsAndSelf);
root_copy.Children.Add(tsk); //crashes here.
// replace the timeliner tasks
timeliner.TasksCopyFrom(root_copy.Children);
}
catch (Exception ex)
{
}

 

 

ADN Support Specialist
xiaodong.liang
Posts: 1,335
Registered: ‎06-12-2011
Message 2 of 3 (388 Views)

Re: Adding a custom Task to Timeliner (or adding model selections to tasks)

10-22-2012 09:08 PM in reply to: tkachenko_truboprovod

Hi,

 

The task cannot be manipulated directly. Please refer to the following code:

 

   Document navDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

          Autodesk.Navisworks.Api.DocumentParts.IDocumentTimeliner Itimeliner = navDoc.Timeliner;

          DocumentTimeliner timeliner = (DocumentTimeliner)Itimeliner;

          GroupItem root_copy = timeliner.TasksRoot.CreateCopy() as GroupItem; 

          TimelinerTask tsk = new TimelinerTask();

          try
          {
              tsk.Selection.CopyFrom(navDoc.CurrentSelection.SelectedItems.DescendantsAndSelf);
              root_copy.Children.Add(tsk);  //crashes here.
                // replace the timeliner tasks 
              timeliner.TasksCopyFrom(root_copy.Children); 
          }
          catch (Exception ex)
          {
          }

 

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

New Member
tkachenko_truboprovod
Posts: 2
Registered: ‎10-18-2012
Message 3 of 3 (382 Views)

Re: Adding a custom Task to Timeliner (or adding model selections to tasks)

10-23-2012 12:33 AM in reply to: tkachenko_truboprovod

Thanks a lot!

I've already found this solution yesterdeay, and you verified my guess!

 

Alexander.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.