MS Project is a widely used project management software that helps the managers in managing their projects efficiently. It allows to create the tasks, add resources, allocate tasks to resources, monitor the progress, and manage budget-related operations. In this article, you will learn how to embed the project management activities within your C++ applications without MS Project. With the help of code samples, you will learn how to create MS Project files (.mpp/.xml), add tasks, resources, and calendars programmatically using C++. Furthermore, the assignment of tasks to resources in a project will also be demonstrated.
- C++ MS Project File Manipulation API
- Create MS Project Files from Scratch using C++
- Add Tasks to Project using C++
- Add Resources to Project using C++
- Assign Project’s Task to Resource using C++
- Add Calendars in Project using C++
C++ MS Project File Manipulation API
Aspose.Tasks for C++ is a C++ project management API that lets you create, manipulate, export, and convert MS Project files programmatically. The API provides you a complete set of features to create projects, tasks, resources, calendars, and perform other project management activities without MS Project. You can download the complete package of the API from here or install it using NuGet.
Create MS Project Files (.mpp) using C++
Lets first start by creating an empty project. The following are the steps to create an MS Project (.mpp) file from scratch using Aspose.Tasks for C++.
- Create an object of the Project class.
- Set the project’s properties.
- Save the project as .mpp file using Project->Save(u”project.mpp”, Aspose::Tasks::Saving::SaveFileFormat::MPP) method.
The following code sample shows how to create an MS Project’s .mpp file using C++.
Add Tasks to Project using C++
Once you have created a project, you can proceed to add tasks to it. You can either create a new project or load an existing MS Project file to add the tasks. The following are the steps to create and add tasks or subtasks to a project.
- Create a new project or load it from .mpp file using Project class.
- Add task to project using Project->get_RootTask()->get_Children()->Add(u”Summary1″) method and store the newly created task into a Task object.
- (Optional) Add a subtask to the newly created task using Task->get_Children()->Add(u”Subtask1″) method.
- Save the project as .mpp file using Project->Save(u”project.mpp”, Aspose::Tasks::Saving::SaveFileFormat::MPP) method.
The following code sample shows how to create and add tasks to a project using C++.
Read more about extended features related to tasks.
Add Resources to Project using C++
Resources are the entities that are supposed to complete the project. Usually, people are referred to as the resources of a project. The following are the steps to create and add resources to a project.
- Create a new project or load it from a .mpp file using Project class.
- Add a new resource using Project->get_Resources()->Add(u”Rsc”) method.
- Save the project using Project->Save(u”project.mpp”, Aspose::Tasks::Saving::SaveFileFormat::MPP) method.
The following code sample shows how to add a resource in a project using C++.
Read more about extended features related to resources.
Assign Project’s Task to Resource using C++
Once you have created the tasks and resources, the next step is to assign each task to a resource that is responsible for its completion. The following are the steps to assign a task to a resource.
- Create a new project or load it from a .mpp file using Project class.
- Add new tasks and resources if the project is empty.
- Access the desired task and resource into Task and Resource object respectively.
- Assign task to resource using Project->get_ResourceAssignments()->Add(Task, Resource) method.
- Save the project using Project.Save() method.
The following code sample shows how to assign a task to a resource in a project using C++.
Add Calendars in Project using C++
Calendars are used to create a schedule for the project within the MS Project. Aspose.Tasks for C++ has made it very simple to create a calendar for a project. The following are the steps to create a calendar, add weekdays, and specify the working time.
- Create a new project or load it from a .mpp file using Project class.
- Add a calendar to project using Project->get_Calendars()->Add(u”Calendar1″) and store the returned value in Calendar object.
- Add working days to the calendar using Calendar->get_WeekDays()->Add() method.
- Save the project.
You can also set the working time for a weekday in the calendar. For this, you can follow the below steps after adding the working days.
- Create an object of WeekDay class.
- Create an object of WorkingTime class.
- Set timing using WorkingTime->set_FromTime() and WorkingTime->set_ToTime() methods.
- Add working time to the weekday using WeekDay->get_WorkingTimes()->Add(WorkingTime) method.
- Add weekday to the calendar using Calendar->get_WeekDays()->Add(WeekDay) method.
- Save the project.
The following code sample shows how to create a calendar in a project using C++.
Read more about extended features related to calendars.
Conclusion
In this article, you have learned how to create MS Project files and save them as .mpp or .xml using C++. Furthermore, you have learned how to add tasks, resources, resource assignments, and calendars within a project programmatically. You can also explore the documentation for the extended features of Aspose.Tasks for C++ to further enhance the project management capabilities within your applications.