Implement MS Project Calculation Modes in Python

Microsoft Project offers three calculation modes: automated, manual, and none. Each mode offers a different level of control over how the project is updated and recalculated. In this article, we will be learning how to implement the MS Project calculation modes programmatically in Python. Whether you are migrating from manual scheduling to automated scheduling or you need flexibility in managing your project deadlines, this article will provide you with the information and resources needed for such a transition. Let’s get started!

This article covers the following topics:

  1. Python API to Calculate Project Programmatically
  2. Manual Project Calculation
  3. Automatic Project Calculation
  4. No Project Calculation Mode

Python API to Calculate Project Programmatically

We will use Aspose.Tasks for Python API to implement MS project calculation modes. It provides the following calculation modes to calculate the values of dependent properties:

  • None – This mode sets only necessary properties and does not recalculate project dates and costs.
  • Manual – This mode sets only dependent object properties without recalculation of project dates and costs.
  • Automatic – This mode recalculates project dates and cost properties automatically.

Please download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-tasks

Calculate MS Project Manually in Python

We can set the calculation mode to manual and verify it by following the steps below:

  1. Create an instance of the Project class.
  2. Set the calculation mode to MANUAL.
  3. Specify the project start date.
  4. Add new tasks, e.g., Task 1, and Task 2.
  5. Read task properties.
  6. After that, initialize an object of the TaskLinks class and link tasks.
  7. Finally, verify the start and end date of Task 2.

The following code sample shows how to manually calculate a project in Python.

Task1.Id Equals 1 :  True
Task1 OutlineLevel Equals 1 :  True
Task1 Start Equals 15/04/2015 08:00 AM :  2015-04-15 08:00:00
Task1 Finish Equals 15/04/2015 05:00 PM :  2015-04-15 17:00:00
Task1 Duration Equals 1 day :  True
Task2 Start Equals 15/04/2015 08:00 AM :  True
Task2 Finish Equals 15/04/2015 05:00 PM :  True
Task2 Duration Equals 1 day :  True
Task1 Start Equals Task2 Start :  True
Task1 Finish Equals Task2 Finish :  True

Automatic Project Calculation in Python

Similarly, we can calculate the MS project using automatic calculation mode by following the steps mentioned earlier. However, we just need to set the calculation mode to automatic in step 2.

The following code sample shows how to calculate the MS project using automatic calculation mode in Python.

Task1 Start + 1 Equals Task2 Start :  True
Task1 Finish + 1 Equals Task2 Finish :  True
RootTask Finish Equals Task2 Finish :  True
Project Finish Date Equals Task2 Finish :  False

No Project Calculation Mode in Python

We can set the calculation mode to NONE and verify it by following the steps given below:

  1. Create an instance of the Project class.
  2. Set the calculation mode to None.
  3. Specify the project start date.
  4. Add a new task, e.g., Task 1.
  5. Read task properties.
  6. After that, set task duration in days.
  7. Finally, verify the start and end date of the Task.

The following code sample shows how to set MS project calculation mode to none using Python.

Task.Id Equals 0 :  True
Task.OutlineLevel Equals 0 :  False
Task Start Equals DateTime.MinValue :  True
Task Finish Equals DateTime.MinValue :  True
Task Duration Equals 0 mins :  True
Task Duration Equals 2 days :  True
Task Start Equals DateTime.MinValue  :  True
Task Finish Equals DateTime.MinValue  :  True

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Calculate Project in Python – Learning Resources

Besides implementing calculation modes and recalculating MS project schedule and duration, you can explore various other features of the library using the resources below:

Conclusion

In this article, we have learned how to set project calculation modes programmatically in Python. We have also seen how values of dependent properties are calculated in each calculation mode. By leveraging Aspose.Tasks for Python via .NET, you can easily embed such functionality into your Python applications. In case of any ambiguity, please feel free to contact us our free support forum.

See Also