Hi All, @Mike.Buttery
Can anyone explain why I am getting a difference in the count of lines created using the Revit API compared to DesignScript (which, in this case, is correct), even though I used the same logic and inputs?
As an example I used the following inputs:
Lx = 20 m, Ly = 25 m, dx = 4 m, dy = 5 m, e = 2 m
Lines by DesignScript
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
Lx = 20
Ly = 25
dx = 4
dy = 5
e = 2
def create_Lines_along_X(lx, ly, d_x, e0):
Start_pts_X = [Point.ByCoordinates(x, (-ly/2)-e0 , 0) for x in [i * dx - Lx / 2 for i in range(int(lx / d_x) + 1)]]
End_pts_X = [Point.ByCoordinates(x, ly/2 + e0 , 0) for x in [i * dx - Lx / 2 for i in range(int(lx / d_x) + 1)]]
if lx % dx != 0:
Start_pts_X.append(Point.ByCoordinates(lx/2, (-ly/2)-e0 , 0))
End_pts_X.append(Point.ByCoordinates(lx/2, ly/2 + e0 , 0))
return [Line.ByStartPointEndPoint(start, end) for start, end in zip(Start_pts_X, End_pts_X)]
def create_Lines_along_Y(lx, ly, d_y, e0):
Start_pts_Y = [Point.ByCoordinates((-lx/2)-e0, y, 0) for y in [i * dy - Ly / 2 for i in range(int(ly / d_y) + 1)]]
End_pts_Y = [Point.ByCoordinates(lx/2 + e0, y, 0) for y in [i * dy - Ly / 2 for i in range(int(ly / d_y) + 1)]]
if ly % dy != 0:
Start_pts_Y.append(Point.ByCoordinates((-lx/2)-e0, ly/2 , 0))
End_pts_Y.append(Point.ByCoordinates(lx/2 + e0, ly/2 , 0))
return [Line.ByStartPointEndPoint(start, end) for start, end in zip(Start_pts_Y, End_pts_Y)]
Lines_X = create_Lines_along_X(Lx, Ly, dx, e)
Lines_Y = create_Lines_along_Y(Lx, Ly, dy, e)
OUT = Lines_X, Lines_Y
Lnes by Revit API
import clr
import sys
# Import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Retrieve units
units = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
Lx = UnitUtils.ConvertToInternalUnits(20, units) # Total length along X
Ly = UnitUtils.ConvertToInternalUnits(25, units) # Total length along Y
# Define spaces along each axis
dx = UnitUtils.ConvertToInternalUnits(4, units) # Space along X
dy = UnitUtils.ConvertToInternalUnits(5, units) # Space along Y
# Define extension distance
e = UnitUtils.ConvertToInternalUnits(2, units)
def create_Lines_along_X(lx, ly, d_x, e0):
Start_pts_X = [XYZ(x, (-ly/2)-e0 , 0) for x in [i * dx - Lx / 2 for i in range(int(lx / d_x) + 1)]]
End_pts_X = [XYZ(x, ly/2 + e0 , 0) for x in [i * dx - Lx / 2 for i in range(int(lx / d_x) + 1)]]
if lx % dx != 0:
Start_pts_X.append(XYZ(lx/2, (-ly/2)-e0 , 0))
End_pts_X.append(XYZ(lx/2, ly/2 + e0 , 0))
return [Line.CreateBound(start, end) for start, end in zip(Start_pts_X, End_pts_X)]
def create_Lines_along_Y(lx, ly, d_y, e0):
Start_pts_Y = [XYZ((-lx/2)-e0, y, 0) for y in [i * dy - Ly / 2 for i in range(int(ly / d_y) + 1)]]
End_pts_Y = [XYZ(lx/2 + e0, y, 0) for y in [i * dy - Ly / 2 for i in range(int(ly / d_y) + 1)]]
if ly % dy != 0:
Start_pts_Y.append(XYZ((-lx/2)-e0, ly/2 , 0))
End_pts_Y.append(XYZ(lx/2 + e0, ly/2 , 0))
return [Line.CreateBound(start, end) for start, end in zip(Start_pts_Y, End_pts_Y)]
Lines_X = create_Lines_along_X(Lx, Ly, dx, e)
Lines_Y = create_Lines_along_Y(Lx, Ly, dy, e)
OUT = Lines_X, Lines_Y
How to fix issue in Revit API?
Thanks.