Skip to content

Commit a3da84d

Browse files
authored
Merge pull request #21 from Amoursol/master
sync
2 parents 653d236 + dd3e58b commit a3da84d

19 files changed

+1229
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Many thanks to all contributors of this community focused resource:
2121
* [Min Naung](https://github.com/mgjean)
2222
* [Oliver Green](https://github.com/OliverEGreen)
2323
* [Pablo Derendinger](https://github.com/pabloderen)
24-
* [John Pierson](https://github.com/sixtysecondrevit)
24+
* [John Pierson](https://github.com/johnpierson)
2525
* [Racel Williams](https://github.com/Racel)
2626
* [Radu Gidei](https://github.com/radumg)
27+
* [Timon Hazell](https://github.com/thazell)

concepts/listFlatten.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,21 @@ def flatten(L):
2828

2929
flat_List2 = flatten(list_Of_List_Irregular)
3030

31-
OUT = flat_List1, flat_List2
31+
32+
#2nd option to Flatten list of list Irregular
33+
def flatten2(L):
34+
# Return Flatten list from irregular list of list
35+
def flat(L,output):
36+
for item in L:
37+
if type(item) == list:
38+
flat(item,output)
39+
else:
40+
output.append(item)
41+
42+
output=[]
43+
flat(L,output)
44+
return output
45+
46+
flat_List3 = flatten2(list_Of_List_Irregular)
47+
48+
OUT = flat_List1, flat_List2, flat_List3

concepts/listGetItemAtIndex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# items from a series of indices
1616

1717
# The input port elements
18-
numbers = [ 0, 1, 2, 3, 4, 5, 6 7, 8, 9, 10
18+
numbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
1919

2020
getItemAtIndex = numbers[ 3 ] # Getting the item at a specified index
2121
getLastItem = numbers[ -1 ] # Getting the last item in a list
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
DYNAMOAPI: GET CURRENT WORKSPACE NAME
3+
"""
4+
__author__ = 'John Pierson - sixtysecondrevit@gmail.com'
5+
__twitter__ = '@60secondrevit'
6+
__github__ = '@sixtysecondrevit'
7+
__version__ = '1.0.0'
8+
"""
9+
Using reflection we are able to obtain the current Dynamo instance from the Revit instance.
10+
"""
11+
# we need to import the common language runtime to be able to interact with Dynamo & Revit
12+
13+
# Importing Reference Modules
14+
# CLR ( Common Language Runtime Module )
15+
import clr
16+
# Adding the DynamoRevitDS.dll module to work with the Dynamo API
17+
clr.AddReference('DynamoRevitDS')
18+
import Dynamo
19+
20+
# access to the current Dynamo instance and workspace
21+
dynamoRevit = Dynamo.Applications.DynamoRevit()
22+
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
23+
24+
# Access current version of dynamo
25+
version=dynamoRevit.RevitDynamoModel.Version
26+
27+
# checks version of dynamo and adjusts output according to version
28+
if version.StartsWith("1."):
29+
30+
# Gets file name which includes full path
31+
filename=currentWorkspace.FileName
32+
33+
# Splits out file path to just file name
34+
OUT=filename.Split("\\")[-1].Replace(".dyn","")
35+
36+
elif version.StartsWith("2."):
37+
OUT=currentWorkspace.Name
38+
39+
else:
40+
OUT="Not supported"

dynamoAPI/dynamologger.py

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
"""
2+
Export DATA to Server for Dynamo Usage Tracking
3+
-
4+
a dynamoPython script, visit the website for more details
5+
https://github.com/Amoursol/dynamoPython
6+
"""
7+
__author__ = 'Timon Hazell'
8+
__twitter__ = '@tmnhzll'
9+
__github__ = '@thazell'
10+
__version__ = '1.0.0'
11+
12+
"""
13+
#The purpose of this script is to allow users to track usage of dynamo.
14+
#The user needs to set the directory below and then it can be copied to all the scripts in the office.
15+
#It will create a single json or CSV per dynamo run (so expect tons of files)
16+
#The single file per run was selected to limit issues with writing to the same file, which occurred on the creators' network.
17+
#Note if a script runs 30x in one session, each run will be logged, so consider that when working.
18+
"""
19+
20+
#
21+
# ------------------Header - Import Section
22+
import sys
23+
import clr
24+
25+
26+
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
27+
import os
28+
29+
# Adding the DynamoRevitDS.dll module to work with the Dynamo API
30+
clr.AddReference('DynamoRevitDS')
31+
import Dynamo
32+
33+
# Import RevitAPI
34+
clr.AddReference("RevitAPI")
35+
import Autodesk
36+
from Autodesk.Revit import DB
37+
38+
# Import DocumentManager and TransactionManager
39+
clr.AddReference("RevitServices")
40+
import RevitServices
41+
from RevitServices.Persistence import DocumentManager
42+
43+
44+
doc = DocumentManager.Instance.CurrentDBDocument
45+
uiapp = DocumentManager.Instance.CurrentUIApplication
46+
app = uiapp.Application
47+
48+
try:
49+
runscript = IN[0]
50+
except:
51+
runscript = True
52+
53+
if runscript:
54+
55+
#----------------Stored Variables Section
56+
57+
# -->>>> update this string below to a network folder that all users have write access to
58+
networkFolder = r'C:\Temp\logreports\DynamoLogReports\''
59+
60+
#Time saveed is assumed based on the following example:
61+
#If you expect that every time you renumber sheets you save 5 minutes, but if you renumber 500 sheets you save 5 minutes + 10 seconds per sheet * 500 sheets)
62+
#edit the following values for each script as an estimate.
63+
estimatedtimesavedeachrun = 10 #put the number of seconds this script will save the office every time it runs
64+
timesavedperelement = 0 #put the number of seconds this script will save for every element that gets edited.
65+
66+
67+
releasedOrTesting = "Testing"
68+
exportAsJson = False #choose whether to record as a json (True) or csv (False)
69+
70+
#try:
71+
import datetime
72+
#add date and time to and central file name subdirectory
73+
74+
75+
#--------------------Processing Section
76+
77+
#get current time of dynamo run
78+
dtstampstring = str(datetime.datetime.today())
79+
80+
#get computername of run
81+
computername = os.environ['COMPUTERNAME']
82+
83+
#get windows username
84+
username = os.environ['USERNAME']
85+
86+
#get dynamo filename
87+
88+
# access to the current Dynamo instance and workspace
89+
dynamoRevit = Dynamo.Applications.DynamoRevit()
90+
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
91+
92+
# access current version of dynamo
93+
version=dynamoRevit.RevitDynamoModel.Version
94+
95+
# checks version of dynamo and adjusts output according to version
96+
if version.StartsWith("1."):
97+
98+
# Gets file name which includes full path
99+
filename=currentWorkspace.FileName
100+
# Splits out file path to just file name
101+
dynamoFileName=filename.Split("\\")[-1].Replace(".dyn","")
102+
103+
elif version.StartsWith("2."):
104+
dynamoFileName=currentWorkspace.Name
105+
else:
106+
dynamoFileName="Unkown"
107+
108+
#get revit projectnumber
109+
projectnumber = doc.ProjectInformation.Number
110+
111+
#get revit projectname
112+
projectname = doc.ProjectInformation.Name
113+
114+
#get revit year
115+
revitYear = app.VersionNumber
116+
117+
#get full revit version
118+
revitfullversion = app.VersionBuild
119+
120+
#get revit saved filename or use
121+
try:
122+
rvtfilename = doc.Title
123+
except:
124+
rvtfilename = "Unkown" # file may not be saved
125+
126+
#calculate time saved per run:
127+
#current time saves per run is just an estimate.
128+
#The user can use the following code if they want to count the number of elements
129+
#that were processed in dynamo
130+
# and use that list to figure out the time savings per element
131+
try:
132+
dynamoelementsupdated = IN[1]
133+
if isinstance(dynamoelementsupdated,list):
134+
elementsupdated = len(dynamoelementsupdated)
135+
elif isinstance(dynamoelementsupdated, int):
136+
elementsupdated = dynamoelementsupdated
137+
elif isintance(dynamoelementsupdated, float):
138+
elementsupdated = dynamoelementsupdated
139+
elif isintance(dynamoelementsupdated, str):
140+
elementsupdated = int(dynamoelementsupdated)
141+
else:
142+
elementsupdated = 0
143+
except:
144+
elementsupdated = 0
145+
146+
timeSavedPerRun = estimatedtimesavedeachrun + timesavedperelement * elementsupdated
147+
#--------------------Output Section
148+
149+
150+
#create a dictionary which will be sent to a seperate file for each dynamo run
151+
outputdictionary = {}
152+
outputdictionary["Computer"] = computername
153+
outputdictionary["DynamoFile"] = dynamoFileName
154+
outputdictionary["Project Name"] = projectname
155+
outputdictionary["Project Number"] = projectnumber
156+
outputdictionary["Active Revit Project File Name"] = rvtfilename
157+
outputdictionary["Released or Testing"] = releasedOrTesting
158+
outputdictionary["Revit Version"] = revitYear
159+
outputdictionary["Revit Version Full Build"] = revitfullversion
160+
outputdictionary["TimeSaved (sec)"] = timeSavedPerRun
161+
outputdictionary["TimeStamp"] = dtstampstring
162+
outputdictionary["User"] = username
163+
164+
165+
#set directory, create directory if it doesn't exist:
166+
directory = networkFolder + computername + '\\'
167+
168+
if not os.path.exists(directory):
169+
os.mkdir(directory)
170+
newfilename = str(datetime.datetime.today()).replace(" ","-").replace(":","-").replace(".","-") + ""
171+
172+
173+
if exportAsJson:
174+
import json
175+
#export json
176+
177+
newfilename += "-logger.json"
178+
#create json file. a new file will be created every time. This was found to be the most consistent way of getting every run recorded.
179+
180+
with open(directory + newfilename, 'w') as fp:
181+
#OUT = outputdictionary
182+
jsonstring = json.dumps(outputdictionary, indent=4)
183+
fp.write(jsonstring)
184+
185+
else:
186+
import csv
187+
188+
newfilename += "-logger.csv"
189+
#create json file. a new file will be created every time. This was found to be the most consistent way of getting every run recorded.
190+
191+
192+
with open(directory + newfilename, 'wb') as csvfile:
193+
spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
194+
fieldnames = outputdictionary.keys()
195+
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
196+
writer.writeheader()
197+
writer.writerow(outputdictionary)
198+
199+
200+
outputpreviewlist = []
201+
outputpreviewlist.append("The following was recorded to file:")
202+
outputpreviewlist.append(directory + newfilename)
203+
for title in outputdictionary.keys():
204+
outputpreviewlist.append("{0}: {1}".format(title,outputdictionary[title]))
205+
OUT = outputpreviewlist
206+
207+
#if you want to see the output file, uncomment the following lines of code.
208+
#import subprocess
209+
#os.startfile(directory + newfilename)
210+
211+
#-----------------Some code was based on work and questions on the forums by these people, thank you
212+
#John Pierson
213+
#Brendan Cassidy

revitAPI/CenterRoom.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'''
2+
ROOM RELOCATE TO CENTER OF THE ROOM
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 , 2.0.1
9+
10+
# import common language runtime
11+
import clr
12+
13+
# clr.AddReference loads and imports .net assembly(dll) as module
14+
# load RevitAPI.dll and RevitServices.dll
15+
clr.AddReference("RevitAPI")
16+
clr.AddReference("RevitServices")
17+
# import dynamo geometry classes
18+
clr.AddReference('ProtoGeometry')
19+
20+
# import RevitNodes for geometry conversion
21+
# convert dynamo to revit vice versa
22+
clr.AddReference("RevitNodes")
23+
# import system and revit
24+
import System,Revit
25+
clr.ImportExtensions(Revit.Elements)
26+
clr.ImportExtensions(Revit.GeometryConversion)
27+
28+
# import geometry class and point class from dynamo geometry
29+
from Autodesk.DesignScript.Geometry import (Geometry,
30+
Point as pt)
31+
32+
# import all classes from Revit DB
33+
from Autodesk.Revit.DB import *
34+
# import document manager
35+
from RevitServices.Persistence import DocumentManager
36+
# import transaction manager
37+
from RevitServices.Transactions import TransactionManager
38+
# instantiate current document
39+
doc = DocumentManager.Instance.CurrentDBDocument
40+
41+
42+
# input[0]
43+
elems = IN[0]
44+
45+
# make list
46+
if not isinstance(elems,list):
47+
elems = UnwrapElement([elems])
48+
else:
49+
elems = UnwrapElement(elems)
50+
51+
# output
52+
res = []
53+
# start transaction
54+
TransactionManager.Instance.EnsureInTransaction(doc)
55+
56+
# loop elements
57+
for e in elems:
58+
# level elevation - unit millimeter
59+
elevation = e.Level.Elevation * 304.8
60+
# get geo-objects of the element
61+
geoelem = e.GetGeometryObjectFromReference(Reference(e))
62+
# get enumerator to loop geo-objects
63+
geoobj = geoelem.GetEnumerator()
64+
# loop geo-objector
65+
for obj in geoobj:
66+
# convert to dynamo type
67+
room_geometry = obj.ToProtoType()
68+
# get the centroid of the element
69+
point = room_geometry.Centroid()
70+
# create location point with level elevation
71+
center = pt.ByCoordinates(point.X,point.Y,elevation)
72+
# current element location
73+
current = e.Location.Point
74+
# point convert to revit and minus from current location
75+
newloc = center.ToXyz() - current
76+
# move to new location
77+
e.Location.Move(newloc)
78+
79+
# transaction done
80+
TransactionManager.Instance.TransactionTaskDone()
81+
82+
# output
83+
OUT = elems

0 commit comments

Comments
 (0)