Skip to content

Commit 7c8b728

Browse files
authored
Merge pull request #19 from Amoursol/master
sync
2 parents 2f85ca5 + 7bf00ec commit 7c8b728

File tree

4 files changed

+335
-0
lines changed

4 files changed

+335
-0
lines changed

revitAPI/CeilingViewsByRooms.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'''
2+
CREATE CEILING VIEW BY LEVEL, ROOMS
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+
level = IN[0]
28+
rooms = IN[1]
29+
names = IN[2]
30+
Offset = IN[3]/304.8
31+
result = []
32+
33+
# make list
34+
if not isinstance(rooms,list):
35+
Rooms = UnwrapElement([rooms])
36+
else:
37+
Rooms = UnwrapElement(rooms)
38+
39+
if not isinstance(names,list):
40+
Names = [names]
41+
else:
42+
Names = names
43+
44+
# create new bbox based on offset
45+
def crop_box(bbox, offset):
46+
minX = bbox.Min.X - offset
47+
minY = bbox.Min.Y - offset
48+
minZ = bbox.Min.Z - offset
49+
maxX = bbox.Max.X + offset
50+
maxY = bbox.Max.Y + offset
51+
maxZ = bbox.Max.Z + offset
52+
53+
newbox = BoundingBoxXYZ()
54+
newbox.Min = XYZ(minX,minY, minZ)
55+
newbox.Max = XYZ(maxX, maxY, maxZ)
56+
return newbox
57+
58+
# collect views
59+
views = FilteredElementCollector(doc).OfClass(View).ToElements()
60+
# get first ceiling view
61+
cview = [v for v in views if v.ViewType == ViewType.CeilingPlan][0]
62+
63+
# start transaction
64+
TransactionManager.Instance.EnsureInTransaction(doc)
65+
66+
# loop room and name
67+
for room,name in zip(Rooms,Names):
68+
# duplicate ceiling view
69+
view = cview.Duplicate(ViewDuplicateOption.WithDetailing)
70+
# get room bbox
71+
bbox = room.BoundingBox[doc.ActiveView]
72+
# create new bbox
73+
cbox = crop_box(bbox,Offset)
74+
# get duplicated view
75+
dupview = doc.GetElement(view)
76+
# set name
77+
dupview.Name = name
78+
# set view cropbox
79+
dupview.CropBox = cbox
80+
# set cropbox active
81+
dupview.CropBoxActive = True
82+
# set cropbox visibility
83+
dupview.CropBoxVisible = False
84+
# set scale
85+
dupview.Scale = 25
86+
# append result
87+
result.append(dupview)
88+
# transaction done
89+
TransactionManager.Instance.TransactionTaskDone()
90+
# output result
91+
OUT = result
92+

revitAPI/CopyPasteFilters.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
COPY AND PASTE FILTERS - VIEW TO VIEWS
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+
21+
# import document manager
22+
from RevitServices.Persistence import DocumentManager
23+
# import transaction manager
24+
from RevitServices.Transactions import TransactionManager
25+
26+
# instantiate current document
27+
doc = DocumentManager.Instance.CurrentDBDocument
28+
29+
# view to copy
30+
viewtocopy= UnwrapElement(IN[0])
31+
# views to paste
32+
viewstopaste = IN[1]
33+
# make list
34+
if not isinstance(viewstopaste,list):
35+
viewstopaste = UnwrapElement([IN[1]])
36+
else:
37+
viewstopaste = UnwrapElement(IN[1])
38+
39+
# start transaction
40+
TransactionManager.Instance.EnsureInTransaction(doc)
41+
# views to paste loop each view
42+
for view in viewstopaste:
43+
# views to copy loop each filter id
44+
for id in viewtocopy.GetFilters():
45+
# set filter override
46+
view.SetFilterOverrides(id,viewtocopy.GetFilterOverrides(id))
47+
# set filter visibility
48+
view.SetFilterVisibility(id,viewtocopy.GetFilterVisibility(id))
49+
50+
# transaction done
51+
TransactionManager.Instance.TransactionTaskDone()
52+
53+
# output views
54+
OUT = viewstopaste
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
CREATE DUCTS BY MODEL CURVES
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+
# clr.AddReference loads and imports .net assembly(dll) as python module
13+
# load RevitAPI.dll and RevitServices.dll
14+
clr.AddReference("RevitAPI")
15+
clr.AddReference("RevitServices")
16+
17+
# import all classes from Revit DB
18+
from Autodesk.Revit.DB import *
19+
20+
# import document manager
21+
from RevitServices.Persistence import DocumentManager
22+
from Autodesk.Revit.DB.Mechanical import *
23+
# import transaction manager
24+
from RevitServices.Transactions import TransactionManager
25+
26+
# instantiate current document
27+
doc = DocumentManager.Instance.CurrentDBDocument
28+
29+
lines = IN[0]
30+
ductType = UnwrapElement(IN[1])
31+
ducts = []
32+
# make list
33+
if isinstance(lines, list):
34+
lines = UnwrapElement(lines)
35+
else:
36+
lines = UnwrapElement([lines])
37+
#current view level
38+
level = doc.ActiveView.GenLevel
39+
#collect family symbol
40+
fsymbol = FilteredElementCollector(doc).OfClass(MechanicalSystemType).ToElements()[0]
41+
42+
#transaction start
43+
TransactionManager.Instance.EnsureInTransaction(doc)
44+
# loop lines
45+
for line in lines:
46+
#create duct
47+
duct = Duct.Create(doc, fsymbol.Id,ductType.Id, level.Id, line.GeometryCurve.GetEndPoint(0), line.GeometryCurve.GetEndPoint(1));
48+
#append to result
49+
ducts.append(duct)
50+
51+
#transaction end
52+
TransactionManager.Instance.TransactionTaskDone()
53+
# output result
54+
OUT = ducts

workflow/powerbiCatToM.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
'''
2+
CATEGORIES TO M SCRIPT - CREATE CONDITIONAL STATEMENT CODE FOR POWER BI
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+
for large projects with lots of clashes it is useful to analyse in
14+
a business inteligence or data visualisation tool such as ms power bi.
15+
creating the conditonal statement in power bi can take a long time if
16+
there are a lot of categories to include
17+
'''
18+
19+
# ------------------------
20+
# import modules
21+
# ------------------------
22+
23+
# refer to the clipboard
24+
import clr
25+
clr.AddReference('System.Windows.Forms')
26+
from System.Windows.Forms import Clipboard
27+
28+
# refer to the document manager
29+
clr.AddReference('RevitServices')
30+
import RevitServices
31+
from RevitServices.Persistence import DocumentManager
32+
doc = DocumentManager.Instance.CurrentDBDocument
33+
34+
# refer to the revit API
35+
clr.AddReference('RevitAPI')
36+
import Autodesk
37+
from Autodesk.Revit.DB import *
38+
39+
# ------------------------
40+
# inputs & variables
41+
# ------------------------
42+
43+
# some categoreies exported from navisworks are not included as
44+
# categories in visibility graphics, for examplevv
45+
# Handrails, Landings, Pads, Runs, Slab Edges, Top Rails, Wall Sweeps
46+
47+
# remove single and double spaces after commas and split into list
48+
catsInput = IN[0]
49+
catsReplace1 = catsInput.replace(', ', ',')
50+
catsReplace2 = catsReplace1.replace(', ', ',')
51+
catsManual = catsReplace2.split(',')
52+
catsManual.sort()
53+
54+
# provide reference strings
55+
hashtag = 'Renamed Columns1'
56+
pathlink = 'pathlink'
57+
filterIn = 'filter_in'
58+
filterOut = 'filter_out'
59+
60+
# ------------------------
61+
# get categories
62+
# ------------------------
63+
64+
# get categories that can add sub categories
65+
# ie the categories which appear in vis graphics
66+
# annotated from forum post with kudos to René Picazo
67+
# https://forum.dynamobim.com/t/get-all-elements-in-model-categories/9447/7
68+
modelCats = []
69+
for cat in doc.Settings.Categories :
70+
if cat.CategoryType == CategoryType.Model and cat.CanAddSubcategory:
71+
modelCats.append(cat.Name)
72+
73+
# only append extra categories if they have been defined in input
74+
if catsInput :
75+
for cat in catsManual :
76+
modelCats.append(cat)
77+
78+
# sort alphabetically so its easier to read
79+
cats = sorted(modelCats)
80+
81+
# ------------------------
82+
# strings
83+
# ------------------------
84+
85+
# the 1st line adds a column to the table based on a filter on the hash
86+
table = ''.join(('= Table.AddColumn(#"', hashtag, '", "filter",'))
87+
88+
# define strings to be used in M code
89+
each = 'each if ['
90+
elif0 = 'else if ['
91+
elif1 = '] = "'
92+
elif2 = '" then "'
93+
elif3 = '"'
94+
95+
# the 2nd line is a special case
96+
# where cats[0] requires 'each' instead of 'else if'
97+
catJoin = each, pathlink, elif1, cats[0], elif2, filterIn, elif3
98+
temp = ''.join(catJoin)
99+
listLines = []
100+
listLines.append(temp)
101+
102+
# the 3rd line and onwards starts with else if
103+
# each row is checked if it is equall to one of the remaining cats
104+
# cats is sliced by [1:] to return items from index 1 to the last index
105+
for c in cats[1:] :
106+
catJoin = elif0, pathlink, elif1, c, elif2, filterIn, elif3
107+
temp = ''.join(catJoin)
108+
listLines.append(temp)
109+
lines = '\r\n'.join(listLines)
110+
111+
# the final line starts with else
112+
# rows not in cats are given the filterOut value
113+
strElse = ''.join(('else "', filterOut, '")'))
114+
115+
# the code is brought together with new lines between each line
116+
code = '\r\n'.join((table, lines, strElse))
117+
118+
# ------------------------
119+
# send to clipboard
120+
# ------------------------
121+
122+
# annotated with kudos to bakery 'by send to clipboard from revit' (sic)
123+
# https://github.com/LukeyJohnson/BakeryForDynamo/blob/97e5622db7ba14cd42caac9b8bd4fdba6b66871e/nodes/bv%20Send%20to%20Clipboard%20from%20Revit.dyf#L5-L12
124+
# try to copy the code, provide a message if it fails
125+
try:
126+
Clipboard.SetText(code)
127+
copyMsg = code
128+
except:
129+
copyMsg = 'Data could not be copied to clipboard'
130+
131+
# ------------------------
132+
# output
133+
# ------------------------
134+
135+
OUT = copyMsg

0 commit comments

Comments
 (0)