def CreateCurvePipe(name, diameter, thickness, startO, endO, middleO): #print(name) # print("Diameter" + str(diameter)) #correction = XYZ(0, 0, diameter / 2) correction = XYZ(0, 0, 0) start = startO + correction end = endO + correction middle = middleO + correction #print(name) #print(start) #print(end) #print(middle) path = Arc.Create(start, end, middle) pathCurve = CurveLoop().Create([path]) pp = Plane.CreateByNormalAndOrigin( path.ComputeDerivatives(0, True).BasisX, start) profile = CurveLoop().Create([ Arc.Create(pp, diameter / 2 + thickness, 0, math.pi), Arc.Create(pp, diameter / 2 + thickness, math.pi, math.pi * 2) ]) geo = GeometryCreationUtilities.CreateSweptGeometry( pathCurve, 0, path.GetEndParameter(0), [profile]) ele = DirectShape.CreateElement(doc, ElementId(-2000151)) ele.SetShape([geo]) ele.SetName(name) return ele.Id
def CreateCurveDuct(name, width, height, thickness, startO, endO, middleO): #correction = XYZ(0, 0, height / 2) correction = XYZ(0, 0, 0) #print(name) start = startO + correction end = endO + correction middle = middleO + correction ele = () if start.X == end.X and start.Y == end.Y and start.Z == end.Z: print("Curve error, start is the same as end") return None else: path = Arc.Create(start, end, middle) #print(name) #print(start) #print(end) #print(middle) #print(path.Center) pathCurve = CurveLoop().Create([path]) pp = Plane.CreateByNormalAndOrigin( path.ComputeDerivatives(0, True).BasisX, start) profile1 = Arc.Create(pp, width / 2 + thickness, 0, math.pi) normalVec = path.ComputeDerivatives(0, True).BasisX interVector = XYZ((normalVec).Y * -1, (normalVec).X, 0) a = profile1.GetEndPoint(0) vector1 = a - start vector2 = XYZ((a - start).X, (a - start).Y, 0) # angle = vector2.AngleTo(vector1) angle = vector1.AngleOnPlaneTo(interVector, (end - start).Normalize()) #print(angle) trans1 = Transform.CreateRotationAtPoint( path.ComputeDerivatives(0, True).BasisX, angle, start) trans2 = Transform.CreateRotationAtPoint( path.ComputeDerivatives(0, True).BasisX, angle * (-1), start) trans3 = Transform.CreateRotationAtPoint( path.ComputeDerivatives(0, True).BasisX, angle * (-1) + math.pi / 2, start) trans4 = Transform.CreateRotationAtPoint( path.ComputeDerivatives(0, True).BasisX, angle + math.pi / 2, start) b = profile1.GetEndPoint(1) profile2 = Arc.Create(pp, height / 2 + thickness, math.pi / 2, math.pi * 3 / 2) c = profile2.GetEndPoint(0) d = profile2.GetEndPoint(1) point1 = a + c - start point2 = b + c - start point3 = b + d - start point4 = a + d - start numbers = {} list = [] l1 = Line.CreateBound(point1, point2) l1Test1 = l1.CreateTransformed(trans1) l1Test2 = l1.CreateTransformed(trans2) l1Test3 = l1.CreateTransformed(trans3) l1Test4 = l1.CreateTransformed(trans4) numbers[abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z)] = trans1 numbers[abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z)] = trans2 numbers[abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z)] = trans3 numbers[abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z)] = trans4 list.append(abs(l1Test1.GetEndPoint(0).Z - l1Test1.GetEndPoint(1).Z)) list.append(abs(l1Test2.GetEndPoint(0).Z - l1Test2.GetEndPoint(1).Z)) list.append(abs(l1Test3.GetEndPoint(0).Z - l1Test3.GetEndPoint(1).Z)) list.append(abs(l1Test4.GetEndPoint(0).Z - l1Test4.GetEndPoint(1).Z)) list.sort() profileorigion = CurveLoop().Create([ Line.CreateBound(point1, point2), Line.CreateBound(point2, point3), Line.CreateBound(point3, point4), Line.CreateBound(point4, point1) ]) profile = CurveLoop.CreateViaTransform(profileorigion, numbers[list[0]]) geo = GeometryCreationUtilities.CreateSweptGeometry( pathCurve, 0, path.GetEndParameter(0), [profile]) ele = DirectShape.CreateElement(doc, ElementId(-2000151)) ele.SetShape([geo]) ele.SetName(name) return ele.Id