diff --git a/0-python-code/HowTo_RotateToReference.py b/0-python-code/HowTo_RotateToReference.py new file mode 100644 index 0000000..b2bf98b --- /dev/null +++ b/0-python-code/HowTo_RotateToReference.py @@ -0,0 +1,29 @@ +""" +Function for rotating an element based on rotation of another element. + +TESTED REVIT API: 2016, 2017 + +Author: Jared Friedman | github.com/jbf1212 + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" +from Autodesk.Revit.DB import Line, XYZ + +# Works for point-based elements +# Assumes rotations in XY plane +# Function should be called within a Transaction + +def rotate_to_ref(ref_element, transform_element): + """Match rotation between a reference element and an element to rotate""" + try: + orientation_angle = ref_element.Location.Rotation + ref_location = ref_element.Location.Point + except Exception as errmsg: + print('Could not get element Rotation or Point') + print('Error: {}'.format(errmsg)) + + rot_ang = orientation_angle - transform_element.Location.Rotation + rot_axis = Line.CreateBound(ref_location, XYZ(ref_location.X, ref_location.Y, ref_location.Z+1.0)) + transform_element.Location.Rotate(rot_axis, rot_ang) diff --git a/0-python-code/HowTo_SelectUnboundRooms.py b/0-python-code/HowTo_SelectUnboundRooms.py new file mode 100644 index 0000000..c62ca9e --- /dev/null +++ b/0-python-code/HowTo_SelectUnboundRooms.py @@ -0,0 +1,35 @@ +""" +Selects unbound rooms in model + +TESTED REVIT API: 2015, 2016, 2017 + +Author: Jared Friedman | github.com/jbf1212 + +This file is shared on www.revitapidocs.com +For more information visit http://github.com/gtalarico/revitapidocs +License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md +""" +from Autodesk.Revit.DB import Transaction, Element +from Autodesk.Revit.DB import FilteredElementCollector +from Autodesk.Revit.UI import TaskDialog +from System.Collections.Generic import List + +uidoc = __revit__.ActiveUIDocument +doc = __revit__.ActiveUIDocument.Document + +# GET ALL ROOMS IN MODEL +rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms) +ub_rooms = [] + +for r in rooms: + if r.Area > 0: + pass + else: + ub_rooms.append(r) + +# SELECT UNBOUND ROOMS +collection = List[ElementId]([r.Id for r in ub_rooms]) +selection = uidoc.Selection +selection.SetElementIds(collection) + +TaskDialog.Show('Unbound Rooms', "{} unbound rooms selected". format(len(ub_rooms)))