Hi All, @Mike.Buttery @c.poupin
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.
Please check my code and the Revit model below:
Discountinous CurveLoop
import clr
import sys
import System
import math
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import specify namespace
#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.GeometryReferences)
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# select all walls within the project
Walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
rebar_Types = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rebar).WhereElementIsElementType().ToElements()
rebar = [r for r in rebar_Types if r.get_Name() == "HA12 (Fe400)"]
units = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
results = DB.IntersectionResultArray()
# 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 = UnitUtils.ConvertToInternalUnits(0.05, units)
c3 = UnitUtils.ConvertToInternalUnits(0.05, units) + Thick_wall
# choose one face end get its edges serving as the base of creating the searched rebar shape
face = Faces[0]
edges = face.GetEdgesAsCurveLoops()[0]
plane = edges.GetPlane()
# create an offset of the previous edge as a rectangle
new_edges = edges.CreateViaOffset([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, intersect = line.Intersect(e, results)
if result != SetComparisonResult.Overlap:
intersect = "No Overlaping"
else:
st_pt = intersect[0].XYZPoint
print(st_pt)
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)
OUT = final_edge
regard.rvt (5.2 MB)
Any help would be appreciated.
Thanks.









