Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 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
Exemplo n.º 5
0
    def make_loops(self):
        start_x = self.start_x
        start_y = self.start_y
        end_x = start_x + self.width
        end_y = start_y + self.height
        p1 = XYZ(start_x, start_y, 0.0)
        p2 = XYZ(end_x, start_y, 0.0)
        p3 = XYZ(end_x, end_y, 0.0)
        p4 = XYZ(start_x, end_y, 0.0)
        p5 = XYZ(start_x, start_y, 0.0)
        points = [p1, p2, p3, p4, p5]

        profileloop = CurveLoop()
        profileloops = List[CurveLoop]()

        for n, p in enumerate(points):
            try:
                line = Line.CreateBound(points[n], points[n + 1])
            except:
                continue
            else:
                profileloop.Append(line)
        try:
            profileloops.Add(profileloop)
        except Exception as errmsg:
            dialog('Something wrong processing points: {}'.format(self.points))
            # ADD LOGGER
            logger.error('width: {}'.format(self.width))
            logger.error('height: {}'.format(self.height))
            logger.error('start_x: {}'.format(start_x))
            logger.error('start_y: {}'.format(start_y))
            for n, point in enumerate(points):
                logger.error('Point {}:{}'.format(n, point))

        # Defines Location for Label and Value Label
        label_x = start_x - self.label_padding
        label_y = start_y + (self.height / 2)
        value_label_x = start_x + self.width + self.label_padding
        value_label_y = label_y
        self.label_pt = XYZ(label_x, label_y, 0)
        self.value_label_pt = XYZ(value_label_x, value_label_y, 0)

        return profileloops
 def create_curveloop(self, points):
     cl = CurveLoop.Create([])
     prev_point = None
     for point in points:
         if prev_point is None:
             cl.Append(Line.CreateBound(points[-1], points[0]))
         else:
             cl.Append(Line.CreateBound(prev_point, point))
         prev_point = point
     return cl
Exemplo n.º 7
0
        def createfrs(frt):
            #print "createfrs"
            ctr = 0
            b = 7
            c = -7
            t = Transaction(
                doc, "Create TextNotes of all TextTypes in DraftingView")
            t.Start()

            #for i, j in enumerate(frtypes):
            for k in range(10):
                if ctr == len(frt):
                    break
                for l in range(10):
                    if ctr == len(frt):
                        break
                    profileloops = List[CurveLoop]()
                    curveloop = CurveLoop()
                    #curveList = List(Curve)[]
                    p = [
                        XYZ(l * b, k * c, 0),
                        XYZ(5 + l * b, k * c, 0),
                        XYZ(5 + l * b, 5 + k * c, 0),
                        XYZ(l * b, 5 + k * c, 0),
                        XYZ(l * b, k * c, 0)
                    ]

                    for i in range(4):
                        line = DB.Line.CreateBound(p[i], p[i + 1])
                        curveloop.Append(line)

                    profileloops.Add(curveloop)
                    filledreg = FilledRegion.Create(doc, frt[ctr].Id,
                                                    draftview.Id, profileloops)
                    ctr += 1
            t.Commit()
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
 def filled_Region(self, factor, fill):
     BB = self.element.get_BoundingBox(self.view)
     pt1X = (BB.Min[0] - factor) if BB.Min[1] > 0 else (BB.Min[0] - factor)
     pt1Y = (BB.Min[1] - factor) if BB.Min[1] > 0 else (BB.Min[1] - factor)
     pt3X = (BB.Max[0] + factor) if BB.Max[0] > 0 else (BB.Max[0] + factor)
     pt3Y = (BB.Max[1] + factor) if BB.Max[1] > 0 else (BB.Max[1] + factor)
     #Points
     pt1 = XYZ(pt1X, pt1Y, 0)
     pt2 = XYZ(pt1X, pt3Y, 0)
     pt3 = XYZ(pt3X, pt3Y, 0)
     pt4 = XYZ(pt3X, pt1Y, 0)
     start = [pt1, pt2, pt3, pt4]
     end = [pt2, pt3, pt4, pt1]
     #CurveLoop
     lines = []
     for i, j in zip(start, end):
         L = Line.CreateBound(i, j)
         if L:
             lines.append(L)
     curveloop = CurveLoop.Create(lines)
     outRegion = FilledRegion.Create(doc, fill.Id, self.view.Id,
                                     [curveloop])
Exemplo n.º 11
0
def get_solid_extrusion_from_bbox(bbox):
    solid_opt = SolidOptions(ElementId.InvalidElementId,
                             ElementId.InvalidElementId)
    b1 = XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z)
    b2 = XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z)
    b3 = XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z)
    b4 = XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z)
    bbox_height = bbox.Max.Z - bbox.Min.Z

    lines = List[Curve]()
    lines.Add(Line.CreateBound(b1, b2))
    lines.Add(Line.CreateBound(b2, b3))
    lines.Add(Line.CreateBound(b3, b4))
    lines.Add(Line.CreateBound(b4, b1))
    rectangle = [CurveLoop.Create(lines)]

    extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(
        List[CurveLoop](rectangle),
        XYZ.BasisZ,
        bbox_height,
        solid_opt,
    )
    return extrusion
transmatrix.destmin = cropmin
transmatrix.destmax = cropmax

with Transaction(doc, 'Set Crop Region') as t:
    curveloop = []
    t.Start()
    for bl in selboundary:
        newlinestart = sheet_to_view_transform(bl.GeometryCurve.GetEndPoint(0))
        newlineend = sheet_to_view_transform(bl.GeometryCurve.GetEndPoint(1))
        geomLine = Line.CreateBound(newlinestart, newlineend)
        if MAKELINES:
            sketchp = selview.SketchPlane
            mline = doc.Create.NewModelCurve(geomLine, sketchp)
        curveloop.append(geomLine)
        if DEBUG:
            print('VP POLY LINE POINTS: {0}\n'
                  '                     {1}\n'.format(bl.GeometryCurve.GetEndPoint(0),
                                                      bl.GeometryCurve.GetEndPoint(1)
                                                      ))

        if DEBUG:
            print('NEW CROP LINE POINTS: {0}\n'
                  '                      {1}\n'.format(newlinestart,
                                                       newlineend))
    sortedcurves = sortcurvescontiguous(curveloop)
    if sortedcurves:
        crsm.SetCropShape(CurveLoop.Create(List[Curve](sortedcurves)))
    else:
        TaskDialog.Show('pyRevit', 'Curves must be in a closed loop.')
    t.Commit()
Exemplo n.º 13
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
Exemplo n.º 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
Exemplo n.º 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()
    doc.GetElement(elem_id) for elem_id in uidoc.Selection.GetElementIds()
]
first_selected = selection[0]
solid_opt = SolidOptions(ElementId.InvalidElementId,
                         ElementId.InvalidElementId)

bbox = first_selected.get_BoundingBox(None)
bottom_z_offset = 0.1
bbox.Min = XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z - bottom_z_offset)
b1 = XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z)
b2 = XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z)
b3 = XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z)
b4 = XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z)
bbox_height = bbox.Max.Z - bbox.Min.Z

lines = List[Curve]()
lines.Add(Line.CreateBound(b1, b2))
lines.Add(Line.CreateBound(b2, b3))
lines.Add(Line.CreateBound(b3, b4))
lines.Add(Line.CreateBound(b4, b1))
rectangle = [CurveLoop.Create(lines)]

extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(
    List[CurveLoop](rectangle), XYZ.BasisZ, bbox_height, solid_opt)

category_id = ElementId(Bic.OST_GenericModel)

with db.Transaction("solid_bbox_direct_shape") as tx:
    direct_shape = DirectShape.CreateElement(doc, category_id, "A", "B")
    direct_shape.SetShape([extrusion])