Skip to content

Commit b0a0246

Browse files
authored
Merge pull request #20 from Amoursol/master
sync
2 parents 7c8b728 + 07b100f commit b0a0246

File tree

3 files changed

+920
-0
lines changed

3 files changed

+920
-0
lines changed

concepts/ifSwitch

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
IF SWITCH - USE A DICTIONARY FOR IF INSTEAD OF ELIF
3+
-
4+
a dynamoPython script, visit the website for more details
5+
https://github.com/Amoursol/dynamoPython
6+
'''
7+
__author__ = 'Adam Bear - adam@ukbear.com'
8+
__twitter__ = '@adambear82'
9+
__github__ = '@adambear82'
10+
__version__ = '1.0.0'
11+
12+
'''
13+
rather than using if, elif and else a dictionary of values
14+
may be a simplier approach in some cases
15+
'''
16+
17+
inputSwitch = IN[0]
18+
inputOne = IN[1]
19+
inputTwo = IN[2]
20+
inputThree = IN[3]
21+
inputFour = IN[4]
22+
23+
# create a dictionary to map keys to IN[] values
24+
switcher = {
25+
1 : inputOne,
26+
2 : inputTwo,
27+
3 : inputThree,
28+
4 : inputFour
29+
}
30+
31+
# get the dictionary value that corresponds to the key
32+
# if a corresponding value can not be found specify error message
33+
# include a string of the inputSwitch in the error message
34+
output = switcher.get(
35+
inputSwitch,
36+
'no value for key ' + str(inputSwitch)
37+
)
38+
OUT = output
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'''
2+
CREATE FLOOR PLAN VIEW BY ROOMS, LEVEL
3+
'''
4+
__author__ = 'min.naung/mgjean @https://twentytwo.space/contact'
5+
__twitter__ = '@_mgjean'
6+
__version__ ='1.0.0'
7+
8+
# dynamo version - 1.3.2
9+
10+
# import common language runtime
11+
import clr
12+
13+
# clr.AddReference loads and imports .net assembly(dll) as python module
14+
# load RevitAPI.dll and RevitServices.dll
15+
clr.AddReference("RevitAPI")
16+
clr.AddReference("RevitServices")
17+
18+
# import all classes from Revit DB
19+
from Autodesk.Revit.DB import *
20+
# import document manager
21+
from RevitServices.Persistence import DocumentManager
22+
# import transaction manager
23+
from RevitServices.Transactions import TransactionManager
24+
# instantiate current document
25+
doc = DocumentManager.Instance.CurrentDBDocument
26+
27+
# check list for rooms
28+
if isinstance(IN[0], list):
29+
rooms = UnwrapElement(IN[0])
30+
else:
31+
rooms = [UnwrapElement(IN[0])]
32+
# check list for name
33+
if isinstance(IN[1],list):
34+
names = IN[1]
35+
else:
36+
names = [IN[1]]
37+
38+
# level input
39+
level = UnwrapElement(IN[2])
40+
# offset from room bbox (mm to ft)
41+
offset = IN[3]/304.8
42+
43+
def crop_box(bbox, offset):
44+
# modify x,y,z point of bbox
45+
minX = bbox.Min.X - offset
46+
minY = bbox.Min.Y - offset
47+
minZ = bbox.Min.Z - offset
48+
maxX = bbox.Max.X + offset
49+
maxY = bbox.Max.Y + offset
50+
maxZ = bbox.Max.Z + offset
51+
# create new bbox
52+
newbox = BoundingBoxXYZ()
53+
newbox.Min = XYZ(minX,minY, minZ)
54+
newbox.Max = XYZ(maxX, maxY, maxZ)
55+
return newbox
56+
57+
# collect view type in document
58+
viewTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType)
59+
#loop view types
60+
for i in viewTypes:
61+
# floor plane view type
62+
if i.ViewFamily == ViewFamily.FloorPlan:
63+
# get type id
64+
viewTypeId = i.Id
65+
# break the loop
66+
break
67+
# start transaction
68+
TransactionManager.Instance.EnsureInTransaction(doc)
69+
# output list
70+
floorPlans = []
71+
# loop rooms and names together
72+
for i,name in zip(rooms,names):
73+
# level id
74+
levelId = level.Id
75+
# get bounding box
76+
bbox = i.BoundingBox[doc.ActiveView]
77+
# create new bounding vox
78+
newBbox = crop_box(bbox, offset)
79+
# create floor plan view
80+
newView = ViewPlan.Create(doc, viewTypeId, levelId)
81+
# set view name
82+
newView.ViewName = name
83+
# set cropbox to newbbox
84+
newView.CropBox = newBbox
85+
# set cropbox active
86+
newView.CropBoxActive = True
87+
# set visibility
88+
newView.CropBoxVisible = False
89+
# set view scale
90+
newView.Scale = 50
91+
# append output
92+
floorPlans.append(newView)
93+
94+
# End Transaction
95+
TransactionManager.Instance.TransactionTaskDone()
96+
# output
97+
OUT = floorPlans

0 commit comments

Comments
 (0)