-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportGEXF.vba
101 lines (91 loc) · 5.28 KB
/
exportGEXF.vba
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Sub exportGEXF()
Dim allTasks As Tasks
Dim theTask As Task
Dim taskDependency As taskDependency
Dim textToExport As String
Dim linkArray() As String
Dim linkArrayLength As Integer
Dim arrayCounter As Integer
Dim filePath As String
Dim theCounter As Integer
Dim edgeSourceTarget As String
Dim parentTask As String
Dim edgeSource As String
textToExport = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>" & vbCrLf _
& "<gexf xmlns=" & Chr(34) & "http://www.gexf.net/1.2draft" & Chr(34) & " version=" & Chr(34) & "1.2" & Chr(34) & ">" & vbCrLf _
& "<meta lastmodifieddate=" & Chr(34) & "2009-03-20" & Chr(34) & ">" & vbCrLf _
& vbTab & "<creator>Wolfgang Geithner</creator>" & vbCrLf _
& vbTab & "<description>Cryring Project Dependencies</description>" & vbCrLf _
& "</meta>" & vbCrLf _
& "<graph mode=" & Chr(34) & "static" & Chr(34) & " defaultedgetype=" & Chr(34) & "directed" & Chr(34) & ">" & vbCrLf _
& "<attributes class=""node"">" & vbCrLf _
& vbTab & "<attribute id=""0"" title=""status"" type=""string""/>" & vbCrLf _
& "</attributes>" & vbCrLf _
& vbTab & "<nodes>" & vbCrLf _
'First create nodes
For Each theTask In ActiveProject.Tasks
If theTask.Status = 0 Then
textToExport = textToExport & vbTab & vbTab & "<node id=""" & theTask.UniqueID & """ label=" & Chr(34) & Chr(34) & " pid=""" & theTask.OutlineParent & """ >" & vbCrLf
Else
textToExport = textToExport & vbTab & vbTab & "<node id=""" & theTask.UniqueID & """ label=""" & theTask.Name & """ pid=""" & theTask.OutlineParent & """ >" & vbCrLf
End If
textToExport = textToExport & vbTab & vbTab & vbTab & "<attvalues>" & vbCrLf _
& vbTab & vbTab & vbTab & vbTab & "<attvalue for=""0"" value=""" & CStr(theTask.Status) & """ />" & vbCrLf _
& vbTab & vbTab & vbTab & "</attvalues>" & vbCrLf _
& vbTab & vbTab & "</node>" & vbCrLf
Next theTask
textToExport = textToExport & vbTab & "</nodes>" & vbCrLf _
& vbTab & "<edges>" & vbCrLf _
'************************ Then create edges *******************************++
theCounter = 0
For Each theTask In ActiveProject.Tasks
If theTask.taskDependencies.Count > 0 Then
'Analyze predecessors
If InStr(theTask.taskDependencies.Parent.UniqueIDPredecessors, ",") = 0 And theTask.taskDependencies.Parent.UniqueIDPredecessors <> "" Then
If InStr(theTask.taskDependencies.Parent.UniqueIDPredecessors, "+") <> 0 Then
'Filter tasks which have prolongations: <taskID>AA/EA+# <time unit>
edgeSource = Left(theTask.taskDependencies.Parent.UniqueIDPredecessors, 4)
Else
edgeSource = theTask.taskDependencies.Parent.UniqueIDPredecessors
End If
edgeSourceTarget = """ source=""" & edgeSource & """ target=""" & theTask.UniqueID
If InStr(textToExport, edgeSourceTarget) = 0 Then
'If source -> target is not already included in edge list
textToExport = textToExport & vbTab & vbTab & "<edge id=""" & CStr(theCounter) & edgeSourceTarget & """ />" & vbCrLf
theCounter = theCounter + 1
End If
Else
linkArray = Split(theTask.taskDependencies.Parent.UniqueIDPredecessors, ",")
linkArrayLength = UBound(linkArray)
If linkArrayLength > 0 Then
For arrayCounter = 0 To linkArrayLength
If linkArray(arrayCounter) <> CStr(theTask.UniqueID) Then
If InStr(linkArray(arrayCounter), "+") <> 0 Then
'Filter tasks which have prolongations: <taskID>AA/EA+# <time unit>
edgeSource = Left(linkArray(arrayCounter), 4)
Else
edgeSource = linkArray(arrayCounter)
End If
edgeSourceTarget = """ source=""" & edgeSource & """ target=""" & theTask.UniqueID
If InStr(textToExport, edgeSourceTarget) = 0 Then
textToExport = textToExport & vbTab & vbTab & "<edge id=""" & CStr(theCounter) & edgeSourceTarget & """ />" & vbCrLf
theCounter = theCounter + 1
End If
End If
Next
End If
End If
End If
Next theTask
'Trailing XML
textToExport = textToExport & vbTab & "</edges>" & vbCrLf _
& "</graph>" & vbCrLf _
& "</gexf>"
'Some cleaning
textToExport = Replace(textToExport, "&", "+")
'Write to file
filePath = "F:\Cryring\dependencies.gexf"
Open filePath For Output As #1
Print #1, textToExport
Close #1
End Sub