forked from ksobon/archi-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeFamilyType.py
73 lines (57 loc) · 1.97 KB
/
changeFamilyType.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
# Copyright(c) 2016, Konrad Sobon
# @arch_laboratory, http://archi-lab.net
# Import ToDSType(bool) extension method
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
def ProcessList(_func, _list):
return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )
def ProcessParallelLists(_func, *lists):
return map( lambda *xs: ProcessParallelLists(_func, *xs) if all(type(x) is list for x in xs) else _func(*xs), *lists )
def ProcessListArg(_func, _list, _arg):
return map( lambda x: ProcessListArg(_func, x, _arg) if type(x)==list else _func(x, _arg), _list )
def Unwrap(item):
return UnwrapElement(item)
def ChangeType(element, typeId):
element.ChangeTypeId(ElementId(typeId))
return element
if isinstance(IN[0], list):
elements = ProcessList(Unwrap, IN[0])
else:
elements = [Unwrap(IN[0])]
typeIds = IN[1]
try:
errorReport = None
TransactionManager.Instance.EnsureInTransaction(doc)
if isinstance(typeIds, list):
output = ProcessParallelLists(ChangeType, elements, typeIds)
else:
output = ProcessListArg(ChangeType, elements, typeIds)
TransactionManager.Instance.TransactionTaskDone()
except:
# if error accurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable
if errorReport == None:
OUT = output
else:
OUT = errorReport