Automate the creation of Sites for Shared Coordinates


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
import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
import Revit
# Import geometry conversion extension methods
# Import Math functions
import math

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
from RevitServices.Transactions import TransactionManager

#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
		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 = []
ProPos = []
SiteNames = []

for e,n,el,an in zip(ew, ns, elev, angle):
	pp = ProjectPosition(MtoFeet(e),MtoFeet(n),MtoFeet(el),DegToRad(an))

ProjectLocation = doc.ActiveProjectLocation

for sn in ListOfSiteName:
	DupPL = ProjectLocation.Duplicate(sn)

#Create Site Locations

for pps,sns in zip(ProjectPositions,SiteNames):
	DuplProLoc = sns.SetProjectPosition(Punt.ToXyz(),pps)

OUT = SiteNames
1 Like