Work with Resource Calendars

The Resource class exposes the Calendar property which is used to set or get the calendar for a resource. This property accepts and returns an Aspose.Tasks.Calendar object.

Working with Resource Calendars

To define a calendar for a resource in Microsoft Project:

  1. In the Resource Sheet, double-click the desired resource.
  2. Click the Change Working Time button.

Setting Resource Calendar using Aspose.Tasks

The following code example creates a standard calendar and resource and then assigns the calendar to the resource.

1// Create project instance and add resource
2System::SharedPtr<Project> project = System::MakeObject<Project>();
3System::SharedPtr<Resource> res = project->get_Resources()->Add(u"Resource1");
4    
5// Add standard calendar and assign to resource
6System::SharedPtr<Aspose::Tasks::Calendar> cal = project->get_Calendars()->Add(u"Resource1");
7res->Set<System::SharedPtr<Calendar>>(Rsc::Calendar(), cal);

Getting Resource Calendar using Aspose.Tasks

The code example given below demonstrates how to get resource calendars by traversing a project’s resources.

 1// Create project instance
 2System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"ResourceCalendar.mpp");
 3    
 4// Display base calendar name for all resources
 5    
 6{
 7    auto res_enumerator = (project1->get_Resources())->GetEnumerator();
 8    decltype(res_enumerator->get_Current()) res;
 9    while (res_enumerator->MoveNext() && (res = res_enumerator->get_Current(), true))
10    {
11        if (res->Get<System::String>(Rsc::Name()) != nullptr)
12        {
13            System::Console::WriteLine(res->Get<System::SharedPtr<Calendar>>(Rsc::Calendar())->get_BaseCalendar()->get_Name());
14        }
15    }
16}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.