-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_notes.py
More file actions
28 lines (21 loc) · 766 Bytes
/
add_notes.py
File metadata and controls
28 lines (21 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# This code illustrates reading a schedule, adding notes to
# the tasks it contains, then rewriting the schedule.
import jpype
import mpxj
import tempfile
jpype.startJVM()
# Read a sample file
from org.mpxj.reader import UniversalProjectReader
project = UniversalProjectReader().read('example.mpp')
# Update the tasks with notes
for task in project.getTasks():
notes = "This task's ID is " + str(task.getID()) + " and it's name is " + str(task.getName())
task.setNotes(notes)
# Create a temporary file name
tempFile = tempfile.NamedTemporaryFile(suffix='.xml').name
print("Writing new file to", tempFile)
# Write as MSPDI to the temporary file
from org.mpxj.mspdi import MSPDIWriter
writer = MSPDIWriter()
writer.write(project, tempFile)
jpype.shutdownJVM()