I cannot seem to figure out how to extract/write to the Timescale in task usage view.
I can’t seem to extract the data from here nor can I write to it.
I’ve got a timesheet data from employees, and I don’t want to manually input the hours across over 1000 tasks.
I’ve spent about 2-3 days trying to figure out how to extract/add data to this field in microsoft project and just cannot seem to work it out.
I’ve tried to hunt down the documentation for help and I’ve review the VBA code and I feel like my code is right but I still can’t get this to work.
Timescale
import pythoncom
import win32com.client
# Initialize COM connection
pythoncom.CoInitialize()
# Create an instance of the Microsoft Project application
ms_project = win32com.client.Dispatch('MSProject.Application')
# Make the application visible (optional)
ms_project.Visible = True
# Open a project file
ms_project.FileOpen('D:\Manufacturing Resourcing\Test Folder\Test.mpp')
project = ms_project.ActiveProject
# Constants for TimeScaleData
pjAssignmentTimescaledWork = 35
pjTimescaleDays = 4
# Function to print task timephased data
def print_task_timephased_data(task):
print(f"Task: {task.Name}")
if task.Assignments.Count > 0:
for assignment in task.Assignments:
print(f" Assignment: {assignment.ResourceName}")
try:
# Get timescale data for each assignment
timephased_data = assignment.TimescaleData(task.Start, task.Finish, pjTimescaleDays, pjAssignmentTimescaledWork)
for data in timephased_data:
print(f" Start Date: {data.StartDate}, Work: {data.Value}")
except Exception as e:
print(f"Error retrieving timephased data: {e}")
# Iterate through all tasks and print their timephased data
for task in project.Tasks:
if task is not None and task.Start and task.Finish: # Check to ensure the task is valid and has start/finish dates
print_task_timephased_data(task)
pythoncom.CoUninitialize()