From 133972dfeffea09c9d9b09a322f827ae80a0d1d1 Mon Sep 17 00:00:00 2001 From: Jared Friedman Date: Mon, 26 Jun 2017 09:25:37 -0400 Subject: [PATCH 1/2] Added RotateToRef and SelectUnbound --- 0-python-code/HowTo_RotateToReference.py | 28 ++++++++++++++++++ 0-python-code/HowTo_SelectUnboundRooms.py | 35 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 0-python-code/HowTo_RotateToReference.py create mode 100644 0-python-code/HowTo_SelectUnboundRooms.py diff --git a/0-python-code/HowTo_RotateToReference.py b/0-python-code/HowTo_RotateToReference.py new file mode 100644 index 0000000..5ab620e --- /dev/null +++ b/0-python-code/HowTo_RotateToReference.py @@ -0,0 +1,28 @@ +""" +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 +""" + +# 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: + o_angle = ref_element.Location.Rotation + l_loc = ref_element.Location.Point + except Exception as errmsg: + logger.debug('Could not get element Rotation or Point') + logger.debug('Error: {}'.format(errmsg)) + + rot_ang = o_angle - transform_element.Location.Rotation + rot_axis = DB.Line.CreateBound(l_loc, DB.XYZ(l_loc.X, l_loc.Y, l_loc.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))) From b3bc9891ac1a4e256dca7d1ab155373217394f4e Mon Sep 17 00:00:00 2001 From: jbf1212 Date: Mon, 26 Jun 2017 10:13:28 -0400 Subject: [PATCH 2/2] Updated rotate to ref --- 0-python-code/HowTo_RotateToReference.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/0-python-code/HowTo_RotateToReference.py b/0-python-code/HowTo_RotateToReference.py index 5ab620e..b2bf98b 100644 --- a/0-python-code/HowTo_RotateToReference.py +++ b/0-python-code/HowTo_RotateToReference.py @@ -9,6 +9,7 @@ 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 @@ -17,12 +18,12 @@ def rotate_to_ref(ref_element, transform_element): """Match rotation between a reference element and an element to rotate""" try: - o_angle = ref_element.Location.Rotation - l_loc = ref_element.Location.Point + orientation_angle = ref_element.Location.Rotation + ref_location = ref_element.Location.Point except Exception as errmsg: - logger.debug('Could not get element Rotation or Point') - logger.debug('Error: {}'.format(errmsg)) + print('Could not get element Rotation or Point') + print('Error: {}'.format(errmsg)) - rot_ang = o_angle - transform_element.Location.Rotation - rot_axis = DB.Line.CreateBound(l_loc, DB.XYZ(l_loc.X, l_loc.Y, l_loc.Z+1.0)) + 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)