0

I'm trying to create a graph with data from an MPP file using win32com.client to read the data. But after consulting Microsoft's documentation, I tried to start with a simple code.

import win32com.client

mppFileName = 'C:/python/test.mpp'

mpp = win32com.client.Dispatch("MSProject.Application")
mpp.visible = 0
    
mpp.FileOpen(mppFileName)
project = mpp.ActiveProject

ResourceList = project.Resources
assignments = project.Assignments
    
for resource in ResourceList:
    if resource.Work != 0:
        print(resource.Name, ' ', resource.Job)
     
mpp.FileClose(Save=0)
  
exit()

But this code generates an error on the assignments= line (Assignments is 'unknown'). Does anyone know the correct way to work with Assignments and TimeScaleValues ​​objects? My goal is to create a graph with the amount of work assigned by week to each project resource.

4
  • project doesn't have an Assignments property, but resource does, as per the documentation link you provide. Commented Feb 3, 2022 at 13:15
  • Hi thank you for your comment! Using the documentation I understood that I have two nested collections that I have to declare. I already tried to use "Assigments = ResourceList.Assigments", "Assignments = Resources.Assignment", and other variances, but nothing seems to work. This link VBA documentation does not helped me a lot too... Commented Feb 3, 2022 at 14:42
  • Have you tried assignments = resource.Assignments in the 'for' loop? The documentation is very clear: Assignments is a property of the Resource object (like Work): learn.microsoft.com/en-us/office/vba/api/… Commented Feb 3, 2022 at 14:46
  • Thank you for your help! With your comments and Rachel's answers, I was able to go ahead. I have to do the assignments inside loop and not outside... Thank you! Commented Feb 3, 2022 at 19:59

1 Answer 1

1

You'll want to loop through the Assignments collection for each Resource. Then for each Assignment, loop through the time periods you want (e.g. weeks) using the TimeScaleData method which is the key to reading (and setting) work by day/week/etc. This method returns a TimeScaleValues collection of TimeScaleValue objects.

pseudo code:

for r in ResourceList:
  asgmts = r.Assignments
  for a in asgmts 
    ''' create timescalevalues collection to loop through time periods'''
    tsvs = a.TimeScaleData(start, end, type, unit)
    for tsv in tsvs
      ' aggregate the work as needed

Other useful objects to know: Application, Tasks collection, Task object, and Resources collection

Also search stackoverflow for similar questions such as TimeScaleData in Project using .net. Most questions & answers will not be python (c#, vb.net, vba) but the core of using the project object model will be applicable.

Sign up to request clarification or add additional context in comments.

2 Comments

What are the possible values for type and unit?
@CamiloMartinezM. the link to the documentation is in the answer. Click on TimeScaleData.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.