def new(cls, center, x_radius, y_radius, x_axis=None, y_axis=None, start_param=0.0, end_param=2 * PI): """ Args: center (``point``): Center of Ellipse x_radius (``float``): X Radius y_radius (``float``): Y Radius x_axis (``point``): X Axis y_axis (``point``): Y Axis start_param (``float``): Start Parameter end_param (``float``): End Parameter """ center = XYZ(center).unwrap() x_axis = DB.XYZ( 1, 0, 0) if x_axis is None else XYZ(x_axis).unwrap().Normalize() y_axis = DB.XYZ( 0, 1, 0) if y_axis is None else XYZ(y_axis).unwrap().Normalize() start_param = start_param or 0.0 end_param = start_param or PI * 2 ellipse = DB.Ellipse.Create(center, x_radius, y_radius, x_axis, y_axis, start_param, end_param) return cls(ellipse)
def pick_pt(self, msg='Pick Point', snap=None): """ Pick Point location Args: msg (str): Message to show snap (str): Snap Options: [endpoints, midpoints, nearest, workplanegrid, intersections, centers, perpendicular, tangents, quadrants, points] Returns: XYZ (`Xyz`): Rpw XYZ Point """ SNAPS = { # 'none': ObjectSnapTypes.None, 'endpoints': ObjectSnapTypes.Endpoints, 'midpoints': ObjectSnapTypes.Midpoints, 'nearest': ObjectSnapTypes.Nearest, 'workplanegrid': ObjectSnapTypes.WorkPlaneGrid, 'intersections': ObjectSnapTypes.Intersections, 'centers': ObjectSnapTypes.Centers, 'perpendicular': ObjectSnapTypes.Perpendicular, 'tangents': ObjectSnapTypes.Tangents, 'quadrants': ObjectSnapTypes.Quadrants, 'points': ObjectSnapTypes.Points, } if snap: return XYZ(PickPoint(SNAPS[snap], msg)) else: return XYZ(PickPoint(msg))
def test_xyz_set_properties(self): pt = XYZ(1,2,3) pt.x = 5 pt.y = 6 pt.z = 7 self.assertEqual(pt.x, 5) self.assertEqual(pt.y, 6) self.assertEqual(pt.z, 7)
def pick_box(self, msg, style='directional'): """ PickBox Returns: XYZ Points (``XYZ``): Min and Max Points of Box """ # This seems kind of usless right now. PICK_STYLE = { 'crossing': UI.Selection.PickBoxStyle.Crossing, 'enclosing': UI.Selection.PickBoxStyle.Enclosing, 'directional': UI.Selection.PickBoxStyle.Directional, } pick_box = PickBox(PICK_STYLE[style]) return (XYZ(pick_box.Min), XYZ(pick_box.Max))
def new(cls, pt1, pt2): """ Args: point1 (``point``): Point like object. See :any:`XYZ` point2 (``point``): Point like object. See :any:`XYZ` """ pt1 = XYZ(pt1) pt2 = XYZ(pt2) line = DB.Line.CreateBound(pt1.unwrap(), pt2.unwrap()) return cls(line)
def min(self): """ >>> points = [(0,0,5), (2,2,2)] >>> points.min = (0,0,2) Returns: XYZ (`DB.XYZ`): Min of point collection. """ x_values = [point.x for point in self.points] y_values = [point.y for point in self.points] z_values = [point.z for point in self.points] x_min = min(x_values) y_min = min(y_values) z_min = min(z_values) return XYZ(x_min, y_min, z_min)
def max(self): """ >>> points = [(0,0,5), (2,2,2)] >>> points.max (2,2,5) Returns: XYZ (`DB.XYZ`): Max of point collection. """ x_values = [point.x for point in self.points] y_values = [point.y for point in self.points] z_values = [point.z for point in self.points] x_max = max(x_values) y_max = max(y_values) z_max = max(z_values) return XYZ(x_max, y_max, z_max)
def new(cls, *args): # http://www.revitapidocs.com/2017.1/19c3ba08-5443-c9d4-3a3f-0e78901fe6d4.htm # XYZ, XYZ, XYZ # Plane, Double, Double, Double (Plane, Radius, startAngle, endAngle) # XYZ, Double, Double, Double ,XYZ, XYZ (Center, radius, vectors, angles) """ Args: start_pt (``point``): Start Point mid_pt (``point``): End Point end_pt (``point``): Mid Point """ if len(args) == 3: start_pt, end_pt, mid_pt = [XYZ(pt).unwrap() for pt in args] arc = DB.Arc.Create(start_pt, end_pt, mid_pt) else: raise NotImplemented('only arc by 3 pts available') return cls(arc)
def average(self): """ >>> points = [XYZ(0,0,0), XYZ(4,4,2)] >>> points.average (2,2,1) Returns: XYZ (`DB.XYZ`): Average of point collection. """ x_values = [point.x for point in self.points] y_values = [point.y for point in self.points] z_values = [point.z for point in self.points] x_avg = sum(x_values) / len(x_values) y_avg = sum(y_values) / len(y_values) z_avg = sum(z_values) / len(z_values) return XYZ(x_avg, y_avg, z_avg)
def test_xyz_rotate_radians(self): import math pt = XYZ(1,0,0) rotate_pt = (-1,0,0) self.assertEqual(pt.rotate(math.pi, radians=True), rotate_pt)
def test_xyz_rotate_180(self): pt = XYZ(1,0,0) rotate_pt = (-1,0,0) self.assertEqual(pt.rotate(180), rotate_pt)
def test_xyz_rotate_90(self): pt = XYZ(1,0,0) rotate_pt = (0,1,0) self.assertEqual(pt.rotate(90), rotate_pt)
def test_xyz_eq(self): self.assertEqual(XYZ(1,2,3), XYZ(1,2,3)) self.assertNotEqual(XYZ(1,2,3), XYZ(2,2,3))
def as_global_pt(self): """ Returns ``GlobalPoint`` property of Reference """ pt = self._revit_object.GlobalPoint if pt: return XYZ(pt)
def test_xyz_from_tuple3(self): pt = XYZ([2,4,6]) self.assertEqual(pt.X, 2) self.assertEqual(pt.Y, 4) self.assertEqual(pt.Z, 6)
def test_xyz_min(self): xyz_collection = rpw.db.XyzCollection(self.points) mn = xyz_collection.min self.assertEqual(mn, XYZ(0,0,0))
def test_xyz_repr(self): self.assertIn('<rpw:XYZ', XYZ(0,0,0).__repr__())
def test_xyz_at_z(self): pt = XYZ(1,2,3).at_z(10) self.assertEqual(pt.z, 10)
def test_xyz_as_tuple(self): pt_tuple = XYZ(1,2,3).as_tuple self.assertEqual(pt_tuple, (1,2,3)) self.assertIsInstance(pt_tuple, tuple)
def test_xyz_average(self): xyz_collection = rpw.db.XyzCollection(self.points) av = xyz_collection.average self.assertEqual(av, XYZ(5,5,0))
def test_xyz_get_properties(self): pt = XYZ(1,2,3) self.assertEqual(pt.x, 1) self.assertEqual(pt.y, 2) self.assertEqual(pt.z, 3)
def setUpClass(cls): logger.title('TESTING XYZ Usage...') cls.pt = XYZ(1,2,3) cls.pt2 = XYZ(4,5,6)
def test_xyz_rotate_axis(self): import math pt = XYZ(1,0,0) axis = XYZ(0,-1,0) rotate_pt = (0,0,1) self.assertEqual(pt.rotate(90, axis=axis), rotate_pt)
def test_xyz_add(self): pt = XYZ(1,2,3) + XYZ(4,5,6) self.assertEqual(pt.x, 5) self.assertEqual(pt.y, 7) self.assertEqual(pt.z, 9)
def test_xyz_from_3args(self): pt = XYZ(2,4,6) self.assertEqual(pt.X, 2) self.assertEqual(pt.Y, 4) self.assertEqual(pt.Z, 6)
def test_xyz_sub(self): pt = XYZ(1,2,3) - XYZ(1,1,1) self.assertEqual(pt.x, 0) self.assertEqual(pt.y, 1) self.assertEqual(pt.z, 2)
def test_xyz_from_DB_XYZ(self): pt = XYZ(DB.XYZ(2,4,6)) self.assertEqual(pt.X, 2) self.assertEqual(pt.Y, 4) self.assertEqual(pt.Z, 6)
def test_xyz_mul(self): pt = XYZ(1,2,3) * 2 self.assertEqual(pt.x, 2) self.assertEqual(pt.y, 4) self.assertEqual(pt.z, 6)
def test_xyz_as_dict(self): pt_dict = XYZ(1,2,3).as_dict self.assertIsInstance(pt_dict, dict) self.assertEqual(pt_dict, {'x':1, 'y':2, 'z':3})
def test_xyz_sorted_by(self): xyz_collection = rpw.db.XyzCollection(self.points) rv = xyz_collection.sorted_by('x') self.assertEqual(rv[0], XYZ(0,0,0)) self.assertEqual(rv[1], XYZ(5,5,0)) self.assertEqual(rv[2], XYZ(10,10,0))