forked from jchristel/SampleCodeRevitBatchProcessor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportWallsDetails_executeThis.py
144 lines (127 loc) · 4.93 KB
/
ReportWallsDetails_executeThis.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#License:
#
#
# Revit Batch Processor Sample Code
#
# Copyright (c) 2020 Jan Christel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# sample description
# how to report on wall types
# note: in place families of category wall and curtain wall do not have a valid Compound structure
import clr
import System
# flag whether this runs in debug or not
debug_ = False
# --------------------------
# default file path locations
# --------------------------
# store output here:
rootPath_ = r'C:\temp'
# path to Common.py
commonlibraryDebugLocation_ = r'C:\temp'
# debug mode revit project file name
debugRevitFileName_ = r'C:\temp\Test_walls.rvt'
# Add batch processor scripting references
if not debug_:
import revit_script_util
import revit_file_util
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
doc = revit_script_util.GetScriptDocument()
revitFilePath_ = revit_script_util.GetRevitFilePath()
else:
# get default revit file name
revitFilePath_ = debugRevitFileName_
# set path to common library
import sys
sys.path.append(commonlibraryDebugLocation_)
# import common library
import Common as com
from Common import *
clr.AddReference('System.Core')
clr.ImportExtensions(System.Linq)
from Autodesk.Revit.DB import *
#output messages either to batch processor (debug = False) or console (debug = True)
def Output(message = ''):
if not debug_:
revit_script_util.Output(str(message))
else:
print (message)
# -------------
# my code here:
# -------------
#
def WriteType (action, description, fileName, doc):
status = True
collector = action()
print ('Writing ' + description +'....')
f = open(fileName, 'w')
f.write('\t'.join(['HOSTFILE', 'WALLTYPEID', 'WALLTYPENAME', 'FUNCTION', 'LAYERWIDTH', 'LAYERMATERIALNAME', '\n']))
try:
for wt in collector:
try:
cs = wt.GetCompoundStructure()
if cs != None:
csls = cs.GetLayers()
for csl in csls:
materialName = str(GetMaterialbyId (csl.MaterialId, doc))
wallTypeName = str(Element.Name.GetValue(wt))
function = str(csl.Function)
width = str(csl.Width*304.8)
f.write('\t'.join([com.GetRevitFileName(revitFilePath_), str(wt.Id), com.EncodeAscii(wallTypeName), function, width, com.EncodeAscii(materialName), '\n']))
else:
f.write('\t'.join([com.GetRevitFileName(revitFilePath_), str(wt.Id), com.EncodeAscii(Element.Name.GetValue(wt)), '\n']))
except Exception:
f.write('\t'.join([com.GetRevitFileName(revitFilePath_) , str(wt.Id), Element.Name.GetValue(wt), '\n']))
except Exception as e:
status = False
Output('Failed to write data file! ' + fileName +' with exception '+str(e))
f.close()
return status
# returns a materials mark and name based on a material id
def GetMaterialbyId (id, doc):
collector = FilteredElementCollector(doc)
collector.OfClass(Material)
for m in collector:
if m.Id.IntegerValue == id.IntegerValue:
return GetNameAndMark(m)
# returns the material mark and defintion name in format:
# {mark}{name}
def GetNameAndMark (mat):
paraName = Element.Name.GetValue(mat)
name= '{}' if paraName == None else '{' + paraName + '}'
paraMark = mat.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)
mark= '{}' if paraMark == None else '{' + paraMark.AsString() + '}'
return name + mark
# gets all wall types in a model
# this includes types of curtain walls as well as any in types of place wall families!
def actionWT():
collector = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType()
return collector
# -------------
# main:
# -------------
# build output file name
fileName_ = rootPath_ + '\\'+ com.GetOutPutFileName(revitFilePath_)
Output('Writing Wall Type Data.... start')
#write out wall type data
result_ = WriteType (actionWT, 'wall type', fileName_, doc)
Output('Writing Wall Type Data.... status: ' + str(result_))
Output('Writing Wall Type Data.... finished ' + fileName_)