-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModelPlusLinksRamRequirements.py
More file actions
189 lines (158 loc) · 6.5 KB
/
ModelPlusLinksRamRequirements.py
File metadata and controls
189 lines (158 loc) · 6.5 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#========================================================================#
# _____ __
# \_ \__ _ _ __ \ \ __ _ _ __ ___ ___ ___
# / /\/ _` | '_ \ \ \/ _` | '_ ` _ \ / _ \/ __|
# /\/ /_| (_| | | | | /\_/ / (_| | | | | | | __/\__ \
# \____/ \__,_|_| |_| \___/ \__,_|_| |_| |_|\___||___/
#
#
# The Script measures the size of the active model as well as all of
# the linked models.
# It produces stat information on how much RAM is required to
# effectively work in this full model environment based on
# 20 x size of compacted size of the active model central model.
# plus
# 1 x the sum of all linked models
#
# Ref: https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/Revit-Customize/files/GUID-C395AAC8-B5E2-40A5-8B48-1BFEEA9116D6-htm.html
# Ref: https://knowledge.autodesk.com/support/revit-products/troubleshooting/caas/sfdcarticles/sfdcarticles/Revit-How-to-calculate-required-RAM-specific-to-a-project-size.html
#
# February 2019
#
#========================================================================#
import os
#------------------------------------------------------------------------#
def SizeInMegaBytes(size):
MB = 1048576
return size / MB
#------------------------------------------------------------------------#
def SizeInKiloBytes(size):
KB = 1024
return size / KB
#------------------------------------------------------------------------#
def GetModelSize(theDoc):
mp = theDoc.GetWorksharingCentralModelPath()
thePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp)
statinfo = os.stat(thePath)
return statinfo.st_size
#------------------------------------------------------------------------#
def GetLinkSize(aLink):
thePath = ''
#Get the External Reference
er = aLink.GetExternalFileReference()
#Make sure it isn't Null
if not(er):
print Element.Name.GetValue(aLink)
else:
#Get the Model Path
mp = er.GetPath()
#Convert the Model Path to a human readable format
#Also convert relative paths to absolute paths
thePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(mp)
statinfo = os.stat(thePath)
return statinfo.st_size
#------------------------------------------------------------------------#
def GetCentralModelName():
return doc.Title[:doc.Title.LastIndexOf('_')] + '.rvt'
#------------------------------------------------------------------------#
def GetLinkName(aLink):
return Element.Name.GetValue(aLink)
#------------------------------------------------------------------------#
def GetNameColumnWidth(theLinkTypes):
docTitle = GetCentralModelName()
NameLength = len(docTitle)
for aLink in theLinkTypes:
linkName = Element.Name.GetValue(aLink)
# If the Link Name eis longer that what we already have then
# we have a new maximum
if len(linkName) > NameLength: NameLength = len(linkName)
return NameLength
#------------------------------------------------------------------------#
def GetIdColumnWidth(theLinkTypes):
idLength = 0
for aLink in theLinkTypes:
if len(aLink.Id.ToString()) > idLength: idLength = len(aLink.Id.ToString())
return idLength
#------------------------------------------------------------------------#
def GetSizeColumnWidth(output):
bi = 0
kb = 0
mb = 0
for o in output.values():
print o
if o[0] > bi: bi = o[0]
if o[1] > kb: kb = o[1]
if o[2] > mb: mb = o[2]
return len(str(bi)), len(str(kb)), len(str(mb))
#------------------------------------------------------------------------#
documents = doc.Application.Documents
TopLevelLinks = []
NestedLinks = []
#Dict for output data
output = {}
RamSize = 0L
theLinkTypes = (
FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_RvtLinks)
.Where(lambda rl: RevitLinkType ==type(rl))
.OrderBy(lambda rl: Element.Name.GetValue(rl))
)
for aLink in theLinkTypes:
x = '+' if aLink.IsNestedLink else 'o'
pid = aLink.GetParentId().ToString() if aLink.IsNestedLink else ''
#Sort Top Level and Nested Links
if aLink.IsNestedLink:
NestedLinks.append(aLink)
else:
TopLevelLinks.append(aLink)
#Get Link Size
linksize = GetLinkSize(aLink)
#Populate the Data Dictionary
output.update(
{
#Name
GetLinkName(aLink):
#List of Size in various Formats
[
#bytes
linksize,
#kilobytes
SizeInKiloBytes(linksize),
#megabytes
SizeInMegaBytes(linksize)
]
}
)
RamSize += linksize
print '[' + x + '][' + aLink.Id.ToString() + '] ' + Element.Name.GetValue(aLink) + ' [' + SizeInKiloBytes(linksize).ToString() + ']'
print 'N° of Links: ' + theLinkTypes.Count().ToString()
activemodelsize = GetModelSize(doc)
RamRequired = 20* activemodelsize
#Get formatting for tabulating the output
ColIdWidth = GetIdColumnWidth(theLinkTypes)
ColNameWidth = GetNameColumnWidth(theLinkTypes)
ColWidthBi, ColWidthKB, ColWidthMB = GetSizeColumnWidth(output)
print 'Id : ' + ColIdWidth.ToString()
print 'Name: ' + ColNameWidth.ToString()
print 'Model Size (MB) = ' + SizeInKiloBytes(activemodelsize).ToString()
print 'Min RAM Required = ' + SizeInKiloBytes(RamRequired).ToString()
print 'Overall Link Size = ' + SizeInKiloBytes(RamSize).ToString()
print '+----------------------------+'
print 'Total Ram Required = ' + SizeInKiloBytes(RamSize + RamRequired).ToString()
#------------------------------------------------------------------------#
def Horizontal():
print '+' + '-' * (ColIdWidth + 2) + '+' + '-' * (ColNameWidth + 2) + '+' + '-' * (ColWidthKB + 2) + '+' + '-' * (ColWidthMB + 2) + '+' + '-' * (ColWidthBi + 2) + '+'
#------------------------------------------------------------------------#
def HorizontalBlank():
print '|' + ' ' * (ColIdWidth + 2) + '|' + ' ' * (ColNameWidth + 2) + '|' + ' ' * (ColWidthKB + 2)
#------------------------------------------------------------------------#
Horizontal()
# Print Active Model as Title
print '| ' + 'Id'.center(ColIdWidth) + ' | ' + GetCentralModelName().ljust(ColNameWidth) + ' | ' + 'kb'.center(ColWidthKB) + ' | ' + 'MB'.center(ColWidthMB) + ' | ' + 'bytes'.center(ColWidthBi) + ' |'
Horizontal()
# Print Linked Models
for l in TopLevelLinks:
id = l.Id.ToString()
name = Element.Name.GetValue(l)
print '| ' + id.rjust(ColIdWidth) + ' | ' + name.ljust(ColNameWidth) + ' | ' + str(output[name][1]).rjust(ColWidthKB) + ' | ' + str(output[name][2]).rjust(ColWidthMB) + ' | ' + str(output[name][0]).rjust(ColWidthBi) + ' |'
Horizontal()