Hi,
I created this dynamo file with a bit of python in it to automatically define sites based upon an excel input. Althought the script works I really think the python part could use some improvements. Some suggestions on how to improve the python code would be highly appreciated.
This link shows the YT movie why I want this.
Define Sites for Shared Coordinates
excel file:
Sites.xlsx (8.8 KB)
Dynamo File:
CreateSiteLocationsFromExcel.dyn (20.9 KB)
The Python code:
# Import RevitAPI
import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import Math functions
import math
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from RevitServices.Transactions import TransactionManager
#Functions
#Function for getting location values
def GetValues(loc):
pos = loc.GetProjectPosition(XYZ(0,0,0))
angle = pos.Angle
ew = pos.EastWest
e = pos.Elevation
ns = pos.NorthSouth
return [angle, ew, ns, e]
#Function for creating lists
def MakeList(a):
if hasattr(a,"__iter__"):
return a
else:
return [a]
#Function for unitconversions
def FeetToMm(d):
return float(d) * 304.8
def FeetToM(d):
return float(d) * 0.3048
def Feet2ToM2(d):
return float(d) * 304.8**2 / 1000000
def Feet3ToM3(d):
return float(d) * 304.8**3 / 1000000000
def MmToFeet(d):
return float(d) / 304.8
def MtoFeet(d):
return float(d) / 0.3048
def DegToRad(a):
return float(a) / 180 * math.pi
def RadToDeg(a):
return float(a) *180 / math.pi
ew = MakeList(IN[0][0])
ns = MakeList(IN[0][1])
elev = MakeList(IN[0][2])
angle = MakeList(IN[0][3])
ListOfSiteName = MakeList(IN[0][4])
Punt = IN[1]
#ProjectPositions
ProjectPositions = []
ProPos = []
SiteNames = []
TransactionManager.Instance.EnsureInTransaction(doc)
for e,n,el,an in zip(ew, ns, elev, angle):
pp = ProjectPosition(MtoFeet(e),MtoFeet(n),MtoFeet(el),DegToRad(an))
ProjectPositions.append(pp)
ProjectLocation = doc.ActiveProjectLocation
for sn in ListOfSiteName:
DupPL = ProjectLocation.Duplicate(sn)
SiteNames.append(DupPL)
#Create Site Locations
for pps,sns in zip(ProjectPositions,SiteNames):
DuplProLoc = sns.SetProjectPosition(Punt.ToXyz(),pps)
ProPos.append(DuplProLoc)
TransactionManager.Instance.TransactionTaskDone()
OUT = SiteNames