-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLesson 7 Element Selection.py
105 lines (85 loc) · 2.95 KB
/
Lesson 7 Element Selection.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
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
#from Autodesk.Revit.UI.Selection import *
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
#path=os.path.dirname(os.path.abspath(__file__))
class Single_Category(Selection.ISelectionFilter):
def __init__(self, nom_categorie):
self.nom_categorie = nom_categorie
def AllowElement(self, e):
if e.Category.Name == self.nom_categorie:
return True
else:
return False
def AllowReference(self, ref, point):
return true
class Mult_Category(Selection.ISelectionFilter):
def __init__(self, nom_categorie_1, nom_categorie_2):
self.nom_categorie_1 = nom_categorie_1
self.nom_categorie_2 = nom_categorie_2
def AllowElement(self, e):
if e.Category.Name == self.nom_categorie_1 or e.Category.Name == self.nom_categorie_2:
return True
else:
return False
def AllowReference(self, ref, point):
return true
#Element
#PointOnElement
#Edge
#Face
#LinkedElement
# Num_1 -------------------------------------------Select One Element
sel = uidoc.Selection.PickObject(Selection.ObjectType.Element, 'Choose element')
el = doc.GetElement(sel)
t = Transaction(doc, 'selection')
t.Start()
par1 = el.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
par1.Set('Text_1')
t.Commit()
# Num_2 --------------------------------------Select Elements
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, 'Choose elements')
"""els = []
for i sel:
el = doc.GetElement(i)
els.append(el)"""
els = [doc.GetElement( elId ) for elId in sel]
t = Transaction(doc, 'selection')
t.Start()
for i in els:
par1 = i.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
par1.Set('Text_1')
t.Commit()
# Num_3 ------------------------------ Single Category Selection
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, Single_Category('Structural Columns'))
els = [doc.GetElement( elId ) for elId in sel]
t = Transaction(doc, 'selection')
t.Start()
for i in els:
par1 = i.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
par1.Set('Text_1')
t.Commit()
# Num_4 ------------------------------ Multiple Category Selection
sel = uidoc.Selection.PickObjects(Selection.ObjectType.Element, Mult_Category('Structural Columns', 'Floors'))
els = [doc.GetElement( elId ) for elId in sel]
t = Transaction(doc, 'selection')
t.Start()
for i in els:
par1 = i.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
par1.Set('Text_1')
t.Commit()
# Num_5 ------------------------------ Mouse Selection
els = [ doc.GetElement( elId ) for elId in uidoc.Selection.GetElementIds() ]
"""els = []
selection = uidoc.Selection.GetElementIds()
for i in selection:
el = doc.GetElement(i)
els.append(el)"""
t = Transaction(doc, 'selection')
t.Start()
for i in els:
par1 = i.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
par1.Set('Text_1')
t.Commit()