Hi All,
I am having an issue creating grids using pyrevit, even though the same code works perfectly in Dynamo. I am getting the following error in the RPS console:
CPython Traceback:
ArgumentsInconsistentException : Curve length is too small for Revit’s tolerance (as identified by Application.ShortCurveTolerance).
Parameter name: endpoints
à Autodesk.Revit.CurveAPIUtils.CreateBoundLine(XYZ endpoint1, XYZ endpoint2)
File “D:\Examples_pyRevit\Regard\Regard.extension\Regard.tab\Grid.panel\Grid.pushbutton\grid_script.py”, line 35, in
lines_y = [Line.CreateBound(start, end) for start, end in zip(Start_pts_Y, End_pts_Y)]
File “D:\Examples_pyRevit\Regard\Regard.extension\Regard.tab\Grid.panel\Grid.pushbutton\grid_script.py”, line 35, in
lines_y = [Line.CreateBound(start, end) for start, end in zip(Start_pts_Y, End_pts_Y)]
Please check my attached code:
Grids_creation
#!python3
import sys
sys.path.append(r'C:\Users\nono\AppData\Local\Programs\Python\Python38\Lib\site-packages')
import numpy as np
from Autodesk.Revit.DB import *
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
# Retrieve units
units = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
# Define grid dimensions in user units and convert to internal units
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 (2 meters) and convert to internal units
extension = UnitUtils.ConvertToInternalUnits(2, units)
# Generate start and end points for Y-oriented lines (extended)
Start_pts_Y = [XYZ(x, -(Ly / 2) - extension, 0) for x in np.arange(-Lx / 2, Lx / 2 + dx, dx)]
End_pts_Y = [XYZ(x, (Ly / 2) + extension, 0) for x in np.arange(-Lx / 2, Lx / 2 + dx, dx)]
# Generate start and end points for X-oriented lines (extended)
Start_pts_X = [XYZ(-(Lx / 2) - extension, y, 0) for y in np.arange(-Ly / 2, Ly / 2 + dy, dy)]
End_pts_X = [XYZ((Lx / 2) + extension, y, 0) for y in np.arange(-Ly / 2, Ly / 2 + dy, dy)]
# Create lines for Y-oriented grids
lines_y = [Line.CreateBound(start, end) for start, end in zip(Start_pts_Y, End_pts_Y)]
# Create lines for X-oriented grids
lines_x = [Line.CreateBound(start, end) for start, end in zip(Start_pts_X, End_pts_X)]
# Transaction to create grids
grid_Name = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
with Transaction(doc, "Create Grids") as t:
t.Start()
grids_Y = [Grid.Create(doc, line) for line in lines_y]
grids_X = [Grid.Create(doc, line) for line in lines_x]
for i, grid in enumerate(grids_X):
if i < len(grid_Name):
grid.Name = grid_Name[i]
t.Commit()
Edit:
As you can see below, exactly the same code, without any changes, works in Dynamo. So, what could be the issue?
Any help would be appreciated
Thanks.