Hi All,
In my code below, I created a ‘U’ shape from a selected wall face, which I now want to translate along a line with a given distance. However, it seems that the shape I used has a discontinuous CurveLoop, and I’m struggling with how to sort and reorient this CurveLoop…I’m receiving the following error in the RPS console:
Exception : Autodesk.Revit.Exceptions.ArgumentException: This curve will make the loop discontinuous.
Please check my code below:
import math
import clr
from Autodesk.Revit.DB import *
from System.Collections.Generic import IList, List
uidoc = __revit__.ActiveUIDocument
results = clr.Reference[IntersectionResultArray]()
doc = uidoc.Document
Walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
floors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().ToElements()
rebar_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rebar).WhereElementIsElementType().ToElements()
floor_width = floors[0].get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM).AsDouble()
rebar = [r for r in rebar_Types if Element.Name.GetValue(r) == "HA12 (Fe400)"]
units = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
# get walls faces
Faces = []
for w in Walls:
face_Ref = list(HostObjectUtils.GetSideFaces(w, ShellLayerType.Interior))[0]
wall_face = w.GetGeometryObjectFromReference(face_Ref)
Faces.append(wall_face)
Thick_wall = w.Width
# covers parameters
c1 = UnitUtils.ConvertToInternalUnits(0.03, units)
c2 = - (floor_width - UnitUtils.ConvertToInternalUnits(0.05, units))
c3 = UnitUtils.ConvertToInternalUnits(0.05, units) + Thick_wall
# selct the first face end get its edges
face = Faces[0]
edges = face.GetEdgesAsCurveLoops()[0]
plane = edges.GetPlane()
# obtaining a rectangle from offseting edges with the specific covers
new_edges = edges.CreateViaOffset(edges, [c2, c1, c2, c1], plane.Normal.Negate())
# translate the rectangle with a normal distance c3
trans = Transform.CreateTranslation(plane.Normal.Negate().Multiply(c3))
new_edges.Transform(trans)
u_plane = new_edges.GetPlane()
new_edges = list(new_edges)
# remove the top horizontal edge of the rectangle to get the desired shape " U "
new_edges.remove(max(new_edges, key=lambda line: line.Evaluate(0.5, True).Z))
def is_horizontal(line):
return not XYZ.BasisZ.DotProduct(line.Direction)
# get the horizontal line from the shape U and rotate it with 90 degrees to use it as a translation path
for e in new_edges:
if is_horizontal(e):
axis = e.Direction.CrossProduct(u_plane.Normal)
rot = Transform.CreateRotation(axis, math.pi/2)
line = e.CreateTransformed(rot)
result = line.Intersect(e, results)
if result != SetComparisonResult.Overlap:
intersect = "No Overlaping"
else:
intersect = results.Value
st_pt = intersect[0].XYZPoint
offset = line.GetEndPoint(0).DistanceTo(st_pt)
end_pt = line.Evaluate((line.Length - offset)/line.Length, True)
path = Line.CreateBound(st_pt, end_pt)
plane2 = Plane.CreateByNormalAndOrigin(e.Direction, line.GetEndPoint(0))
# define the spacing for trnslation
space = UnitUtils.ConvertToInternalUnits(0.15, units)
count = int(math.ceil(path.Length/space))
# function to use to oriente the curveloop
def substract_point(pt1, pt2):
x_value = pt1.X - pt2.X
y_value = pt1.Y - pt2.Y
Z_value = pt1.Z - pt2.Z
return(x_value + y_value + Z_value)
# define a new curveloop
final_edge = CurveLoop()
# I'm struggling here
for i in range(0, len(new_edges)):
edge = new_edges[i]
st_pt = new_edges[i].GetEndPoint(0)
temp = new_edges[i+1].GetEndPoint(0)
if substract_point(st_pt, temp) == 0 :
edge = new_edges[i]
final_edge.Append(edge)
else:
edge = new_edges[i].CreateReversed()
final_edge.Append(edge)
Any help would be appreciated.
Thanks.