コード例 #1
0
 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
コード例 #2
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])
コード例 #3
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
コード例 #4
0
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()
    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])