Get Resource Units for a Task

Hi,

I’m trying to work out the “Units” of a resource used for a task (e.g. 100%, 50%…).

I’m trying to use the “Work” of the resource divided by the task “Duration” (see below). However, this doesn’t always give me the same result as MS-Project’s UI. Can you please comment on my approach? Am I solving this problem the correct way?

Thanks in advance,

Ian

Project project = new Project("test.mpp");
foreach (Resource rsc in project.Resources)
{
    ResourceAssignmentCollection rscAssignments = rsc.Assignments;
    foreach (ResourceAssignment rsca in rscAssignments)
    {
        TimeSpan resourceWork = rsca.Get(Asn.Work).TimeSpan;
        TimeSpan taskDuration = rsca.Get(Asn.Task).Get(Tsk.Duration).TimeSpan;
        double units = (resourceWork.Ticks / taskDuration.Ticks) * 100;
    }
}

Hi Ian,

Thank you for contacting Aspose support team.

You may please retrieve information of resource assignment to achieve this. Please give a try to the following sample code using attached sample MPP file and share the feedback.

Project prj = new Project(“ResourceUnit.mpp”);
foreach (var resassn in prj.ResourceAssignments)
{
Console.WriteLine(“Task :” + resassn.Get(Asn.Task).Get(Tsk.Id) + ", Resource Name =
" + resassn.Get(Asn.Resource).Get(Rsc.Name) + ", Units = " + resassn.Get(Asn.Units) * 100 + “%”);
}

Perfect! I didn’t see the “Asn.Units” option, but that’s what I wanted. Thank you.

You are welcome.