|
| 1 | +""" |
| 2 | +Solidify Selected Element BoundingBox Example |
| 3 | +Creates a Generic Model Direct Shape |
| 4 | +
|
| 5 | +TESTED REVIT API: 2017 |
| 6 | +
|
| 7 | +Author: Frederic Beaupere | github.com/hdm-dt-fb |
| 8 | +This file is shared on www.revitapidocs.com |
| 9 | +For more information visit http://github.com/gtalarico/revitapidocs |
| 10 | +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md |
| 11 | +""" |
| 12 | +import clr |
| 13 | +clr.AddReference("RevitAPI") |
| 14 | +from Autodesk.Revit.DB import Curve, CurveLoop, DirectShape, ElementId, Line, XYZ |
| 15 | +from Autodesk.Revit.DB import SolidOptions, GeometryCreationUtilities |
| 16 | +from Autodesk.Revit.DB import BuiltInCategory as Bic |
| 17 | +from System.Collections.Generic import List |
| 18 | +from rpw import db, ui, doc, uidoc |
| 19 | + |
| 20 | +selection = [doc.GetElement(elem_id) for elem_id in uidoc.Selection.GetElementIds()] |
| 21 | +first_selected = selection[0] |
| 22 | +solid_opt = SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId) |
| 23 | + |
| 24 | +bbox = first_selected.get_BoundingBox(None) |
| 25 | +bottom_z_offset = 0.1 |
| 26 | +bbox.Min = XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z - bottom_z_offset) |
| 27 | +b1 = XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z) |
| 28 | +b2 = XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z) |
| 29 | +b3 = XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z) |
| 30 | +b4 = XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z) |
| 31 | +bbox_height = bbox.Max.Z - bbox.Min.Z |
| 32 | + |
| 33 | +lines = List[Curve]() |
| 34 | +lines.Add(Line.CreateBound(b1, b2)) |
| 35 | +lines.Add(Line.CreateBound(b2, b3)) |
| 36 | +lines.Add(Line.CreateBound(b3, b4)) |
| 37 | +lines.Add(Line.CreateBound(b4, b1)) |
| 38 | +rectangle = [CurveLoop.Create(lines)] |
| 39 | + |
| 40 | +extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(List[CurveLoop](rectangle), |
| 41 | + XYZ.BasisZ, |
| 42 | + bbox_height, |
| 43 | + solid_opt) |
| 44 | + |
| 45 | +category_id = ElementId(Bic.OST_GenericModel) |
| 46 | + |
| 47 | +with db.Transaction("solid_bbox_direct_shape") as tx: |
| 48 | + direct_shape = DirectShape.CreateElement(doc, category_id, "A", "B") |
| 49 | + direct_shape.SetShape([extrusion]) |
0 commit comments