Hello,
I would like to know how make a resource distribution per day with TimephaseData.
I have a task which has an assigned resource but his work is proportionally distributed between the task duration. What I want is to assign each day different number of hours of this resource, so day one 5h , day two 10h, day three 8h, etc. I know this is possible with Timephasedata but I dont get what i want in MS Project.
Dim resAsg1 As New ResourceAssignment(task1, res1)
resAsg1.Uid = project.NextResourceAssignmentUid()
resAsg1.Work = New TimeSpan(8, 0, 0)
resAsg1.Start = New DateTime(2000, 5, 3, 8, 0, 0)
Dim dateRes As DateTime = New DateTime(2000, 5, 3, 8, 0, 0)
Dim tpData As New TimephasedData
tpData.Uid = resAsg1.Uid
tpData.TimephasedDataType = 1
tpData.Start = dateRes
dateRes = dateRes.AddDays(1)
tpData.Finish = dateRes
tpData.Value = “PT5H0M0S”
tpData.Unit = TimeUnitType.Day
resAsg1.TimephasedData.Add(tpData)
Dim tpData2 As New TimephasedData
tpData2.Uid = resAsg1.Uid
tpData2.TimephasedDataType = 1
tpData2.Start = dateRes.AddDays(2)
dateRes = dateRes…AddDays(3)
tpData2.Finish = dateRes
tpData2.Value = “PT10H0M0S”
tpData2.Unit = TimeUnitType.Day
resAsg1.TimephasedData.Add(tpData2)
project.ResourceAssignments.Add(resAsg1)
I don’t know what I’m doing wrong. I think that even if I set the good parameter, other are overwriting them. Any idea?
Thanks
Hi Katherine,
Hi Katherine,
Dim project As New Project()
project.StartDate = New DateTime(2014, 9, 24)
Dim person1 As Resource = project.AddResource("Person 1")
Dim task1 As New Task("Task 1")
task1.Type = TaskType.FixedDuration
task1.DurationFormat = TimeUnitType.Day
Dim assn1 As New ResourceAssignment(task1, person1)
assn1.WorkContour = WorkContourType.Contoured
assn1.TimephasedData = New List(Of TimephasedData)()
Dim td As New TimephasedData()
td.Start = New DateTime(2014, 9, 24, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)
td = New TimephasedData()
td.Start = New DateTime(2014, 9, 25, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(7))
assn1.TimephasedData.Add(td)
td = New TimephasedData()
td.Start = New DateTime(2014, 9, 26, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(4))
assn1.TimephasedData.Add(td)
td = New TimephasedData()
td.Start = New DateTime(2014, 9, 29, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)
td = New TimephasedData()
td.Start = New DateTime(2014, 9, 30, 8, 0, 0)
td.Finish = td.Start.AddHours(9)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(6))
assn1.TimephasedData.Add(td)
td = New TimephasedData()
td.Start = New DateTime(2014, 10, 1, 8, 0, 0)
td.Finish = td.Start.AddHours(9)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)
assn1.Work = InlineAssignHelper(task1.Work, TimeSpan.FromHours(17))
task1.Start = project.StartDate
task1.Finish = td.Finish
task1.Duration = project.Calendar.GetWorkingHours(task1.Start, task1.Finish).WorkingHours
project.RootTask.Children.Add(task1)
project.ResourceAssignments.Add(assn1)
project.CalcResourceAssignmentIds()
project.CalcResourceAssignmentUids()
project.CalcTaskIds()
project.CalcTaskUids()
project.UpdateReferences()
project.Save("Z:\saved.xml", SaveFileFormat.XML)
End Sub
Return String.Format("PT{0}H{1}M{2}S)", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds)
End Function
Hi
Could you please help me to do the same thing (adding thimephased data to an assignment) using the new library???
How can I don this with aspose.tasks 8.4? assn1.TimephasedData = New List(Of TimephasedData)()
Thank you very much!
Hi,
You can use the TimephasedDataCollection.Add method to achieve the same using the new API. Please try the following code sample and let us know your feedback if you face some problem.
Sample Code:
Project project = new Project();
project.Set(Prj.StartDate, new DateTime(2014, 9, 24));
Resource person1 = project.Resources.Add(“Person 1”);
Task task1 = project.RootTask.Children.Add(“Task1”);
task1.Set(Tsk.Type , TaskType.FixedDuration);
task1.Set(Tsk.DurationFormat , TimeUnitType.Day);
ResourceAssignment assn1 = project.ResourceAssignments.Add(task1, person1);
assn1.Set(Asn.WorkContour , WorkContourType.Contoured);
//assn1.TimephasedData = new List();
TimephasedData td = new TimephasedData();
td.Start = new DateTime(2014, 9, 24, 8, 0, 0);
td.Finish = td.Start.AddDays(1);
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork;
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0));
assn1.TimephasedData.Add(td);
Thank you Kashif but I’m still having problems with the timephaseData. Attached you’ll find the XML file. The output is completely different of what I want
My code:
Sub testBasic()
Dim project As New Project
Dim task1 As Task = project.RootTask.Children.Add(“Task1”)
task1.Set(Tsk.Duration, project.GetDuration(40, TimeUnitType.Day))
task1.Set(Tsk.Start, New DateTime(2015, 2, 9))
'task1.Set(Tsk.PercentComplete, 20)
task1.Set(Tsk.ActualStart, task1.Get(Tsk.Start))
task1.Set(Tsk.Type, TaskType.FixedDuration)
Dim res As Resource = project.Resources.Add(“Person1”)
res.Set(Rsc.Type, ResourceType.Work)
Dim Assn As ResourceAssignment = project.ResourceAssignments.Add(task1, res)
'Assn.Set(Asn.Delay, project.GetDuration(5, TimeUnitType.Day))
Assn.Set(Asn.Start, New DateTime(2015, 2, 16, 8, 0, 0))
Assn.Set(Asn.Finish, New DateTime(2015, 4, 3, 17, 0, 0))
Assn.Set(Asn.Work, project.GetDuration(8, TimeUnitType.Hour))
Assn.Set(Asn.WorkContour, WorkContourType.Contoured)
Dim td As New TimephasedData()
td.Uid = Assn.Get(Asn.Uid)
td.Start = New DateTime(2014, 2, 16, 8, 0, 0)
td.Finish = New DateTime(2014, 2, 28, 17, 0, 0)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(8))
td.Unit = TimeUnitType.Month
Assn.TimephasedData.Add(td)
td = New TimephasedData()
td.Uid = Assn.Get(Asn.Uid)
td.Start = New DateTime(2014, 3, 1, 8, 0, 0)
td.Finish = New DateTime(2014, 3, 31, 17, 0, 0)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
td.Unit = TimeUnitType.Month
Assn.TimephasedData.Add(td)
td = New TimephasedData()
td.Uid = Assn.Get(Asn.Uid)
td.Start = New DateTime(2014, 4, 1, 8, 0, 0)
td.Finish = New DateTime(2014, 4, 3, 17, 0, 0)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
td.Unit = TimeUnitType.Month
Assn.TimephasedData.Add(td)
project.Save(“C:/testBAs.xml”, SaveFileFormat.XML)
MsgBox(“Basic test done”)
End Sub
Hi,
I have reviewed the code and found few inconsistencies as follows:
- task1.Set(Tsk.Start, new DateTime(2015, 2, 9))
Comments: Task start date is in 2015 where as timephased data is of year 2014.
- Assn.Set(Asn.Start, new DateTime(2015, 2, 16, 8, 0, 0))
Assn.Set(Asn.Finish, new DateTime(2015, 4, 4, 17, 0, 0))
Comments: Assignment date is in 2015 where as timephased data is of year 2014.
- Assn.Set(Asn.Work, project.GetDuration(8, TimeUnitType.Hour))
Comments: Please assist us about the usage of this line of code.
Could you please review the code and test the scenario again? If problem is still there, please provide us the equivalent XML file created by Microsoft Project, which you actually want to create. It will help us to assist you further in this regard.