예제 #1
0
def CreateRoundStrutwithCone(name, diameter, start, height, coneHeight, topDiameter, frameHeight):
    #print(name)
    vector = XYZ(0, 0, height*-1)
    coneVector = XYZ(0, 0, (coneHeight-frameHeight)*-1)
    frameVector = XYZ(0, 0, frameHeight * -1)

    pp = Plane.CreateByNormalAndOrigin(vector, start + coneVector + frameVector*2)
    ppCone = Plane.CreateByNormalAndOrigin(vector, start + frameVector)
    ppFrame = Plane.CreateByNormalAndOrigin(vector, start)
    frameProfile = CurveLoop().Create([Arc.Create(ppFrame, topDiameter/2, 0, math.pi), Arc.Create(ppFrame, topDiameter/2, math.pi, math.pi*2)])
    coneProfile = CurveLoop().Create([Arc.Create(ppCone, topDiameter/2 + frameHeight + 1/12, 0, math.pi), Arc.Create(ppCone, topDiameter/2 + frameHeight + 1/12, math.pi, math.pi*2)])
    profile = CurveLoop().Create([Arc.Create(pp, diameter/2, 0, math.pi), Arc.Create(pp, diameter/2, math.pi, math.pi*2)])

    frame = GeometryCreationUtilities.CreateExtrusionGeometry([frameProfile], frameVector, frameHeight)
    geo = GeometryCreationUtilities.CreateExtrusionGeometry([profile], vector, height - coneHeight-frameHeight)
    try:
        cone = GeometryCreationUtilities.CreateLoftGeometry([coneProfile, profile], SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId))
        # Create Element
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo, cone, frame])
        ele.SetName(name)
        return ele.Id
    except:
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo, frame])
        ele.SetName(name)
        return ele.Id
예제 #2
0
    def create_widnow_for_panel(self, panel_dict, panel_params, panel=None):
        """
        Создать окна в панели.
        """
        for i in panel_dict['components']['componentRefs']:
            window_type = self.all_windows[i["id"]]
            symb = self.window_family[window_type[0]]
            add_point = XYZ(i['point']['x'], i['point']['y'], i['point']['z']) / 304.8
            c_window = self.doc.Create.NewFamilyInstance(
                add_point,
                symb,
                self.default_level,
                StructuralType.Column)
            c_window = Precast_window(c_window, doc=self.doc, panel=panel)
            c_window["Рзм.Ширина"] = i["length"] / 304.8
            new_point = c_window.element.Location.Point
            new_point = new_point + XYZ(i["length"] / 304.8 / 2, 0, 0)
            # new_point = new_point + XYZ(i["length"] / 304.8 / 2, 0, 0)
            c_window.element.Location.Point = new_point
            axis = Line.CreateBound(c_window.element.Location.Point, c_window.element.Location.Point + XYZ(0,0,10))
            c_window.element.Location.Rotate(axis, math.pi)
            if window_type[1] == "left":
                plane = Plane.CreateByNormalAndOrigin(XYZ(1,0,0), c_window.element.Location.Point)
                new_win = ElementTransformUtils.MirrorElement(self.doc, c_window.element.Id, plane)

                self.doc.Delete(c_window.element.Id)
예제 #3
0
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
예제 #4
0
def CreateStraightPipe(name, diameter, thickness, startO, endO, length):
    #correction = XYZ(0, 0, diameter/2)
    #print("Diameter" + str(diameter))
    #print(name)
    correction = XYZ(0, 0, 0)
    start = startO + correction
    end = endO + correction
    #print(name)
    #print(length)
    if (end - start).GetLength() > 0.1:
        pp = Plane.CreateByNormalAndOrigin(end - start, 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.CreateExtrusionGeometry([profile],
                                                                end - start,
                                                                length)
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo])
        ele.SetName(name)
        return ele.Id
    else:
        print("Duct too small")
        return None
예제 #5
0
def CreateCubeStrut(csdname, csdwidth, csdlength, csdheight, csdstart,
                    csdrotation, scdthickness):
    #print(csdname)
    vector = XYZ(0, 0, csdheight * -1)
    pp = Plane.CreateByNormalAndOrigin(vector, csdstart)

    trans = Transform.CreateRotationAtPoint(vector, csdrotation, csdstart)

    point1 = csdstart + XYZ(csdwidth / 2, csdlength / 2, 0)
    point2 = csdstart + XYZ(csdwidth / 2 * -1, csdlength / 2, 0)
    point3 = csdstart + XYZ(csdwidth / 2 * -1, csdlength / 2 * -1, 0)
    point4 = csdstart + XYZ(csdwidth / 2, csdlength / 2 * -1, 0)

    profileorigion = CurveLoop().Create([
        Line.CreateBound(point1, point2),
        Line.CreateBound(point2, point3),
        Line.CreateBound(point3, point4),
        Line.CreateBound(point4, point1)
    ])

    finalProfile = CurveLoop.CreateViaTransform(profileorigion, trans)
    geo = GeometryCreationUtilities.CreateExtrusionGeometry([finalProfile],
                                                            vector, csdheight)
    ele = DirectShape.CreateElement(doc, ElementId(-2000151))
    ele.SetShape([geo])
    ele.SetName(csdname)
    return ele.Id
예제 #6
0
 def print_arc(cls, point, plane=None, radius=0.3):
     doc = __revit__.ActiveUIDocument.Document
     active_view = doc.ActiveView
     creDoc = __revit__.ActiveUIDocument.Document.Create
     if not plane:
         plane = Plane.CreateByNormalAndOrigin(active_view.ViewDirection,
                                               point)
     sketchPlane = SketchPlane.Create(doc, plane)
     new_arc = Arc.Create(point, radius, 0, pi * 2, plane.XVec, plane.YVec)
     m_line = creDoc.NewModelCurve(new_arc, sketchPlane)
     return m_line
예제 #7
0
 def print_line(cls, p1, p2, plane=None, radius=0.3, color='еленая'):
     doc = __revit__.ActiveUIDocument.Document
     active_view = doc.ActiveView
     creDoc = __revit__.ActiveUIDocument.Document.Create
     if not plane:
         vect = p2 - p1
         p3 = p1 + XYZ_multiply(active_view.ViewDirection, vect).Normalize()
         plane = Plane.CreateByThreePoints(p1, p2, p3)
     sketchPlane = SketchPlane.Create(doc, plane)
     new_line = Line.CreateBound(p1, p2)
     m_line = creDoc.NewModelCurve(new_line, sketchPlane)
     m_line.LineStyle = cls.get_line_style(color=color)
     return m_line
예제 #8
0
파일: script.py 프로젝트: Melca-G/Aeolus
def CreateRoundStrut(name, diameter, start, height):
    vector = XYZ(0, 0, height * -1)

    print(name)
    print(height)
    pp = Plane.CreateByNormalAndOrigin(vector, start)
    profile = CurveLoop().Create([
        Arc.Create(pp, diameter / 2, 0, math.pi),
        Arc.Create(pp, diameter / 2, math.pi, math.pi * 2)
    ])
    geo = GeometryCreationUtilities.CreateExtrusionGeometry([profile], vector,
                                                            height)
    ele = DirectShape.CreateElement(doc, ElementId(-2000151))
    ele.SetShape([geo])
    ele.SetName(name)
    return ele.Id
예제 #9
0
파일: script.py 프로젝트: Melca-G/Aeolus
def CreateStraightPipe(name, diameter, thickness, startO, endO, length):
    correction = XYZ(0, 0, diameter / 2)
    start = startO + correction
    end = endO + correction
    print(name)
    print(length)
    pp = Plane.CreateByNormalAndOrigin(end - start, 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.CreateExtrusionGeometry([profile],
                                                            end - start,
                                                            length)
    ele = DirectShape.CreateElement(doc, ElementId(-2000151))
    ele.SetShape([geo])
    ele.SetName(name)
    return ele.Id
예제 #10
0
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/eirannejad/pyRevit/blob/master/LICENSE
"""

__doc__ = 'Reorients the current 3D view camera, perpendicular to the selected face. ' \
          'This tool will set a sketch plane over the selected face for 3d drawing.'

__window__.Close()
from Autodesk.Revit.DB import Transaction, View3D, SketchPlane, Plane
from Autodesk.Revit.UI.Selection import ObjectType

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = [doc.GetElement(elId) for elId in __revit__.ActiveUIDocument.Selection.GetElementIds()]

curview = uidoc.ActiveView
try:
    ref = uidoc.Selection.PickObject(ObjectType.Face)
    el = doc.GetElement(ref.ElementId)
    face = el.GetGeometryObjectFromReference(ref)
    if isinstance(curview, View3D):
        t = Transaction(doc, 'Orient to Selected Face')
        t.Start()
        sp = SketchPlane.Create(doc, Plane(face.Normal, face.Origin))
        curview.OrientTo(face.Normal.Negate())
        uidoc.ActiveView.SketchPlane = sp
        uidoc.RefreshActiveView()
        t.Commit()
except:
    pass
예제 #11
0
for path, c in zip(points, count):
    # if c > 1:  # Лучевая схема
    if 2 > 1:  # Ортогональная схема
        sublist = []
        for i, p in enumerate(path):
            try:
                start, end = path[i], path[i + 1]

                line = Line.CreateBound(
                    start, end
                )  #https://forums.autodesk.com/t5/revit-api-forum/how-to-crete-3d-modelcurves-to-avoid-exception-curve-must-be-in/td-p/8355936
                direction = line.Direction
                x, y, z = direction.X, direction.Y, direction.Z
                normal = XYZ(z - y, x - z, y - x)
                # normal = XYZ.BasisZ.CrossProduct(line.Direction)
                plane = Plane.CreateByNormalAndOrigin(normal, start)
                sketchPlane = SketchPlane.Create(doc, plane)
                modelCurve = doc.Create.NewModelCurve(line, sketchPlane)

                # sublist.append(Line().ByStartPointEndPoint(path[i], path[i + 1]))
                sublist.append(modelCurve)
            except IndexError:
                continue
        lines.append(sublist)
    else:
        sublist = []
        sublist.append(Line.ByStartPointEndPoint(path[0], path[-1]))
        lines.append(sublist)

OUT = cirs, panels, elements, dividedWires, lengthsWithReserve, discreteLengths, naimenovanie, marka2, sposobRaschyota, kolichestvo, edinitcyIzmereniia,
예제 #12
0
 # offsets = [None] + path[:-1], path, path[1:] + [None]  # https://stackoverflow.com/a/56654140
 offsets = path, path[1:] + [None]  # https://stackoverflow.com/a/56654140
 for point, next_point in list(zip(*offsets)):
     if next_point:
         try:
             line = Line.CreateBound(point, next_point)  # https://forums.autodesk.com/t5/revit-api-forum/how-to-crete-3d-modelcurves-to-avoid-exception-curve-must-be-in/td-p/8355936
         except Exception:
             print('{} не удалось создать линии'.format(cir.id))
             continue
         direction = line.Direction
         x, y, z = direction.X, direction.Y, direction.Z
         normal = XYZ(z - y, x - z, y - x)
         # normal = XYZ.BasisZ.CrossProduct(line.Direction)
         # if not normal.GetLength():
         #     normal = XYZ(1, 0, 0)
         plane = Plane.CreateByNormalAndOrigin(normal, point)
         sketchPlane = SketchPlane.Create(doc, plane)
         model_line = doc.Create.NewModelCurve(line, sketchPlane)
         name = get_wire_name(cir)
         if '!мвс ' + name not in [i.Name for i in lineStyles]:
             # print(name)
             # print(cir.els[0].Id)
             lineStyles.append(cats.NewSubcategory(cats.get_Item(BuiltInCategory.OST_Lines), '!мвс ' + name))
         # model_line.LineStyle = [i for i in lineStyles if i.Name == '!мвс ' + name][0]
         for i in lineStyles:
             if i.Name == '!мвс ' + name:
                 try:  # Срабатывает только со второго запуска скрипта. Не критично (Вероятно, можно исправить перезапуском подтранзакции)
                     model_line.LineStyle = i
                 except:
                     errors.add(name)
                 break
예제 #13
0
 def project_on_plane(point, origin=None, normal=None, plane=None):
     "Проекция точки на плоскость."
     if plane is None:
         plane = Plane.CreateByNormalAndOrigin(normal, origin)
     normal = plane.Normal * plane.Project(point)[1]
     return point - normal
예제 #14
0
def CreateStraightDuct(csdname, csdwidth, csdheight, thickness, csdstartO,
                       csdendO, csdlength):
    #print(csdname)
    #correction = XYZ(0, 0, csdheight / 2)
    correction = XYZ(0, 0, 0)
    csdstart = csdstartO + correction
    csdend = csdendO + correction
    if (csdend - csdstart).GetLength() > 0.1:
        pp = Plane.CreateByNormalAndOrigin(csdend - csdstart, csdstart)
        profile1 = Arc.Create(pp, csdwidth / 2 + thickness, 0, math.pi)
        interVector = XYZ((csdend - csdstart).Y * -1, (csdend - csdstart).X, 0)
        a = profile1.GetEndPoint(0)
        b = profile1.GetEndPoint(1)
        profile2 = Arc.Create(pp, csdheight / 2 + thickness, math.pi / 2,
                              math.pi * 3 / 2)
        c = profile2.GetEndPoint(0)
        d = profile2.GetEndPoint(1)
        point1 = a + c - csdstart
        point2 = b + c - csdstart
        point3 = b + d - csdstart
        point4 = a + d - csdstart
        l1 = Line.CreateBound(point1, point2)

        vector1 = point1 - point2
        vector2 = XYZ((point1 - point2).X, (point1 - point2).Y, 0)
        #print(vector1)
        #print(vector2)
        angle = vector1.AngleOnPlaneTo(interVector,
                                       (csdend - csdstart).Normalize())
        #angle = vector2.AngleTo(vector1)
        #print(angle)
        #print(point1)
        #print(point2)
        trans1 = Transform.CreateRotationAtPoint(csdend - csdstart, angle,
                                                 csdstart)
        trans2 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle * (-1), csdstart)
        trans3 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle * (-1) + math.pi / 2,
                                                 csdstart)
        trans4 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                                 angle + math.pi / 2, csdstart)
        #print(angle)
        #print(angle*(-1))
        #print(angle * (-1) + math.pi/2)
        #print(angle + math.pi / 2)

        #print(point4)
        profileorigion = CurveLoop().Create([
            Line.CreateBound(point1, point2),
            Line.CreateBound(point2, point3),
            Line.CreateBound(point3, point4),
            Line.CreateBound(point4, point1)
        ])
        #print(l1.GetEndPoint(0))
        #print(l1.GetEndPoint(1))

        numbers = {}
        list = []
        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()
        finalProfile = CurveLoop.CreateViaTransform(profileorigion,
                                                    numbers[list[0]])
        geo = GeometryCreationUtilities.CreateExtrusionGeometry(
            [finalProfile], csdend - csdstart, csdlength)
        ele = DirectShape.CreateElement(doc, ElementId(-2000151))
        ele.SetShape([geo])
        ele.SetName(csdname)
        return ele.Id
    else:
        print("Duct too small")
        return None
예제 #15
0
def AngleAdjustment(csdend, csdstart, csdwidth, csdheight, thickness):
    pp = Plane.CreateByNormalAndOrigin(csdend - csdstart, csdstart)
    interVector = XYZ((csdend - csdstart).Y * -1, (csdend - csdstart).X, 0)

    profile1 = Arc.Create(pp, csdwidth / 2 + thickness, 0, math.pi)
    #print(pp.XVec)
    #print(pp.YVec)
    a = profile1.GetEndPoint(0)
    b = profile1.GetEndPoint(1)
    profile2 = Arc.Create(pp, csdheight / 2 + thickness, math.pi / 2,
                          math.pi * 3 / 2)

    c = profile2.GetEndPoint(0)
    d = profile2.GetEndPoint(1)
    point1 = a + c - csdstart
    point2 = b + c - csdstart
    point3 = b + d - csdstart
    point4 = a + d - csdstart
    l1 = Line.CreateBound(point1, point2)

    vector1 = point1 - point2
    vector2 = XYZ((point1 - point2).X, (point1 - point2).Y, 0)
    vector3 = point1 - point4
    #print(vector1)
    #print(vector2)
    angle = vector1.AngleOnPlaneTo(interVector,
                                   (csdend - csdstart).Normalize())
    #print(angle)
    #print(point1)
    #print(point2)
    trans1 = Transform.CreateRotationAtPoint(csdend - csdstart, angle, point2)
    trans2 = Transform.CreateRotationAtPoint(csdend - csdstart, angle * (-1),
                                             point2)
    trans3 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                             angle * (-1) + math.pi / 2,
                                             point2)
    trans4 = Transform.CreateRotationAtPoint(csdend - csdstart,
                                             angle + math.pi / 2, point2)
    #print(angle)
    #print(angle*(-1))
    #print(angle * (-1) + math.pi/2)
    #print(angle + math.pi / 2)

    #print(point4)
    profileorigion = CurveLoop().Create([
        Line.CreateBound(point1, point2),
        Line.CreateBound(point2, point3),
        Line.CreateBound(point3, point4),
        Line.CreateBound(point4, point1)
    ])
    #print(l1.GetEndPoint(0))
    #print(l1.GetEndPoint(1))

    numbers = {}
    list = []
    l1Test1 = l1.CreateTransformed(trans1)
    l1Test2 = l1.CreateTransformed(trans2)
    l1Test3 = l1.CreateTransformed(trans3)
    l1Test4 = l1.CreateTransformed(trans4)
    #print(l1Test1.GetEndPoint(0))
    #print(l1Test1.GetEndPoint(1))
    #print(l1Test2.GetEndPoint(0))
    #print(l1Test2.GetEndPoint(1))
    #print(l1Test3.GetEndPoint(0))
    #print(l1Test3.GetEndPoint(1))
    #print(l1Test4.GetEndPoint(0))
    #print(l1Test4.GetEndPoint(1))
    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()
예제 #16
0
파일: __init__.py 프로젝트: NauGaika/PikBim
            break
    return uiview

def SignedDistanceTo(plane, p):
    v = p - plane.Origin
    return plane.Normal.DotProduct(v)

def project_onto(plane, p):
    d = SignedDistanceTo(plane, p)
    q = p - d * plane.Normal
    return q

general_mark = RB_selections.pick_element_by_class(IndependentTag)
taggets = RB_selections.pick_elements_by_class(IndependentTag)
if taggets and general_mark:
    plane = Plane.CreateByNormalAndOrigin(active_view.ViewDirection, active_view.Origin)

    middle = project_onto(plane, general_mark.LeaderElbow)
    head = project_onto(plane, general_mark.TagHeadPosition)
    point = project_onto(plane, general_mark.LeaderEnd)

    vect = (point - middle).Normalize()
    l1 = Line.CreateUnbound(head, (middle - head).Normalize())
    with Transaction(doc, "Выровнять марки") as t:
        t.Start()
        for i in taggets:
            tag_point = project_onto(plane, i.LeaderEnd)
            l2 = Line.CreateUnbound(tag_point, vect)
            inter = StrongBox[IntersectionResultArray]()
            l1.Intersect(l2, inter)
            new_middle = list(inter.Value)[0].XYZPoint
예제 #17
0
파일: script.py 프로젝트: Melca-G/Aeolus
__doc__ = 'Rotate Pipe Fittings connected to pipe'\
          'Click the tool, select the pipe and then the fitting ' \
          'Type in a number you want to rotate and you are good to go,'\
          'Can Take negative Values'
pipFilter = PipeSelectionFilter()
fittingFilter = PipeFittingSelectionFilter()
choices = uidoc.Selection
pipeRef = choices.PickObject(ObjectType.Element, pipFilter, "Pick Pipe")
pointRef = choices.PickPoint(ObjectSnapTypes.Endpoints, "Pick End Point")
# extendRef = choices.PickObjects(ObjectType.Element, fittingFilter, "Pick Pipe Fitting")
pipe = doc.GetElement(pipeRef.ElementId)
# extend = doc.GetElement(extendRef.ElementId)

pointOne = pipe.Location.Curve.GetEndPoint(0)
pointTwo = pipe.Location.Curve.GetEndPoint(1)

line1 = pointRef.DistanceTo(pointOne)
line2 = pointRef.DistanceTo(pointTwo)
if line1 >= line2:
    pointEnd = pointTwo
    normal = pointTwo.Subtract(pointOne)
else:
    pointEnd = pointOne
    normal = pointTwo.Subtract(pointTwo)
plane = Plane.CreateByNormalAndOrigion(normal, pointEnd)

t = Transaction(doc, 'Extend Pipes')
t.Start()

t.Commit()
예제 #18
0
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