edit and/or delete a task

edit and/or delete a task

Anonymous
Not applicable
1,703 Views
9 Replies
Message 1 of 10

edit and/or delete a task

Anonymous
Not applicable

through API is it possible to edit o delete a specific task? 

Regards

Steve

0 Likes
1,704 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Find timeliner project on sdk

0 Likes
Message 3 of 10

Anonymous
Not applicable

@Anonymous can you say me with solution (name of the solution) do you mean please?



 

0 Likes
Message 4 of 10

Anonymous
Not applicable

It means to look for navisworks sdk

0 Likes
Message 5 of 10

Anonymous
Not applicable

Could you send me the navisowrks sdk example that you mean please?

0 Likes
Message 6 of 10

Anonymous
Not applicable

Any solution at the end? @xiaodong_liang could you have a look please?

Message 7 of 10

xiaodongliang
Contributor
Contributor

Hi @Anonymous,

 

I might probably miss the context. if editing task, it is straightforward. The only trick is to copy a task, edit the copy and set back. e.g. 

         Document doc = Nw.Application.ActiveDocument; 
            DocumentTimeliner doc_timeliner = doc.GetTimeliner();
            TimelinerTask oTask = doc_timeliner.Tasks[0] as TimelinerTask;
            TimelinerTask oTaskCopy = oTask.CreateCopy();
            oTaskCopy.DisplayName = "new-" + oTaskCopy.DisplayName;
            doc_timeliner.TaskEdit(0, oTaskCopy);

And I suggest you take a look at the SDK sample @Anonymous mentioned. And also the blogs on https://adndevblog.typepad.com,  though some contents might be out of date.

Message 8 of 10

Anonymous
Not applicable

thanks @xiaodongliang for answering,

 

I have tried our code, but I get "null" in oTask. Please see the picture attached. 

Both the SDK sample that @Anonymous mentioned and the blogs https://adndevblog.typepad.com/aec/2012/10/timeliner-api-part2.html  are different method, they use the *csv file as export and import. My purpose is to replace the task direcly in Navisworks: delete the task and put it the new one.

 

.picture1.jpg

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

Hello Mr. @xiaodongliang

 

I happen to have the same issue as @Anonymous. The only difference is that I want to edit the Children Tasks from a Task.

 

The code you shared worked perfectly for a normal task, but when I edit the Children Tasks in oTaskCopy, the changes are not reflected in the Timeliner. Here is the code:

 for (int iPosition = 0; iPosition < 1; iPosition++)
            {
//Declaration of variables TimelinerTask oTask = StartForm.doc_timeliner.Tasks[0] as TimelinerTask; //Gets the checked task TimelinerTask oTaskCopy = oTask.CreateCopy(); //Creates a copy of the selected task TimelinerTask taskToInsert = oTask.CreateCopyWithoutChildren();
//Modifications to the task that is doing to be inserted as a ChildrenTask taskToInsert.DisplayName = "Example1"; taskToInsert.EquipmentCost = Convert.ToDouble(StartForm.taskList[1].taskCost);
//Modification to the task that is going to be inserted as a normal Task oTaskCopy.DisplayName = StartForm.taskList[1].taskName; DateTime.TryParse(StartForm.taskList[1].EndDate, out hola); oTaskCopy.ActualEndDate = hola; oTaskCopy.LaborCost = Convert.ToDouble(StartForm.taskList[1].taskCost);
//Methods of editing the Timeliner oTaskCopy.Children.Remove(oTaskCopy.Children[1]); //oTaskCopy.Children.Insert(1, taskToInsert); StartForm.doc_timeliner.TaskEdit(0, oTaskCopy); }

oTaskCopy has the modifications for the normal Task

taskToInsert has the modifications of the ChildrenTasks

 

When I debug the oTaskCopy.Children[1] it appears to me that the children task in position 1 was removed, but when I use the TaskEdit method in the Timeliner, the modifications in the big task happen like they should, but the children tasks stay exactly the way they were.

 

Another thing is that, when I uncomment the line:

//oTaskCopy.Children.Insert(1, taskToInsert);

I receive an error that says: " Cannot evaluate expression because the code of the current method is optimized"

I already looked into the blogs and did the solutions they shared, but the error is still there.

 

So, just to clarify the question.

How can I manipulate the Children Tasks like the code shared in the previous comment does with the normal tasks?

 

What is going on with the "method is optimized" issue?

 

Best regards,

 

Javier

0 Likes
Message 10 of 10

xiaodong_liang
Autodesk Support
Autodesk Support

@Anonymous,

 

sorry, I was not able to get back timely. To delete/add/move the child task, the corresponding API is Timeliner.TaskRemoveAt,  Timeliner.TaskAddCopy, Timeliner.TaskMove. While the trick is to use the original task as the parent (Group Item), instead of copy. The Copy is mainly for the scenario when you want to edit the properties of a original task. Similarly, when you want to edit a child task, you will need to make copy of child task, while use original parent task as the group item in TaskEdit.

 

The code below explains.

 

           

DocumentTimeliner doc_timeliner = doc.GetTimeliner();

TimelinerTask oParentTask = doc_timeliner.Tasks[0] as TimelinerTask; 
//to delete a child task, call TaskRemoveAt with the source task object if (oTask.Children.Count > 0)    //try to delete the first child task    doc_timeliner.TaskRemoveAt(oParentTask, 1);

//if edit the properties of parent task TimelinerTask oParentTaskCopy = oTask.CreateCopy(); oParentTaskCopy.DisplayName = "new-" + oParentTaskCopy.DisplayName; doc_timeliner.TaskEdit(0, oParentTaskCopy);

//if edit the properties of child task
TimelinerTask oChildTask = oParentTask.Children[0] as TimelinerTask;
TimelinerTask oChildCopyTask = oChildTask.CreateCopy();
oChildCopyTask.DisplayName = "new-" + oChildCopyTask.DisplayName;
doc_timeliner.TaskEdit(oParentTask, 0, oChildCopyTask);

 

0 Likes