Hi,
Summary
I was trying to get building footprints’ points from latitude longitude to cartesian coordinates in the last forum post. Since then, I have been trying to get all building’s footprints and after I am planning to extrude the building footprints.
Last Code creating the list in the "Autodesk.DB.XYZ list" format
import clr
from math import cos, sin
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
def ll2cc(lat, lon, deg=True):
def rad(d):
return UnitUtils.Convert(d, UnitTypeId.Degrees, UnitTypeId.Radians)
R = 63710088 # Arithmetic mean radius of Earth in meters
if deg:
lat, lon = rad(lat), rad(lon)
return XYZ(R * cos(lat) * cos(lon), R * cos(lat) * sin(lon), 0)
loc = doc.SiteLocation # Site Location
lat = loc.Latitude
lon = loc.Longitude
# Translate site location lat, lon to 0, 0
translation = XYZ.Zero.Subtract(ll2cc(lat, lon, False))
transform = Transform.CreateTranslation(translation)
latlons = IN[0] # List of lat lon pairs in degrees
OUT = [transform.OfPoint(ll2cc(*ll)) for ll in latlons]
Q1: How can I get a structured list from that code?
The first issue I have encountered is: that the levels of the list are 5 and I can’t run a Python script on that list to make every building’s point translation to cartesian coordinates. I can only translate 1 building’s coordinates.
I want to list structure stay cause each building’s footprint points need to stay separately for further steps (extruding them according to heights).
I tried this:
1. I was getting coordinates data from a code block written this “get_data_values[ x ] [ “geometry” ] [ " coordinates " ];”
2. Then, I get L2 data structure from a code block written this “get_data_value[ 0 ] [ 0 ]; " coordinates " ];” which resulted me getting only 1.building’s footprint points.
3. Then, I thought to get all buildings footprint coordinates in L2 data structure, I should create a code block written this "get_data_value[ 0 ] [ x ] [ 0 ]; " which resulted me getting only 1.building’s footprint points again.
I need to learn level structure more precisely I guess. I have searched for level structure from here But I couldn’t learn much.
I also tried changing the coordination translation code into this
I tried adding a line that creates a list appending all results in the code
# Load the Python Standard and DesignScript Libraries
import clr
from math import cos, sin
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# The inputs to this node will be stored as a list in the IN variables.
latlons = IN[0] # List of lat lon pairs in degrees
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
def ll2cc(lat, lon, deg=True):
def rad(d):
return UnitUtils.Convert(d, UnitTypeId.Degrees, UnitTypeId.Radians)
R = 63710088 # Arithmetic mean radius of Earth in meters
if deg:
lat, lon = rad(lat), rad(lon)
return XYZ(R * cos(lat) * cos(lon), R * cos(lat) * sin(lon), 0)
loc = doc.SiteLocation # Site Location
lat = loc.Latitude
lon = loc.Longitude
# Translate site location lat, lon to 0, 0
translation = XYZ.Zero.Subtract(ll2cc(lat, lon, False))
transform = Transform.CreateTranslation(translation)
**# These lines are added.**
**transformed_points = []**
**for ll in latlons:**
** transformed_points.append(transform.OfPoint(ll2cc(*ll)))**
# Assign your output to the OUT variable.
OUT = transformed_points
Q2: How can I get a polygon or polyline from that list? - (I have a height list also to extrude them in the future.)
My second issue is to create a polyline or polygon out of XYZ result.
From this result, polygon and polyline can’t be created. the error is saying that the list is Autodesk.DB.XYZ[.] not Autodesk.DesignScript.GeometryPoint[.], that is why it can’t create a polygon or polyline.
I exported them to csv and saw the point structure.
To get x,y,z points from the list I tried to split the list this way. But I get null result.
code
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
latlonlist = IN[0]
# Place your code below this line
def split (latlonlist):
split_items = (i.split(',') for i in latlonlist)
# Assign your output to the OUT variable.
OUT = split(latlonlist)
How can I split them into x,y,z to create a polygon or is there a way to create a polygon from the last code giving me this result list Autodesk.DB.XYZ[.]