Skip to content

test_create_view_helpers

Revit-hosted tests for the view helpers in pyrevit.revit.db.create.

Run from Revit via the pyRevit DevTools "Create View Helpers Tests" button (doc-project context). Every test rolls back its changes.

Attributes

TEST_LEVEL = 'Integration' module-attribute

TEST_ENVIRONMENT = 'Revit' module-attribute

TOLERANCE = 1e-06 module-attribute

Classes

RolledBackTestCase

Bases: TestCase

Runs each test inside a transaction that is rolled back.

Methods:

setUp()

Skip family documents and open the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def setUp(self):
    """Skip family documents and open the transaction."""
    if revit.doc.IsFamilyDocument:
        self.skipTest("Requires model document, not family document")
    self.transaction = DB.Transaction(revit.doc, "create view helpers test")
    self.transaction.Start()
tearDown()

Roll back the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def tearDown(self):
    """Roll back the transaction."""
    self.transaction.RollBack()

CreateSectionViewTests

Bases: RolledBackTestCase

Regression tests for #4017.

Methods:

test_west_to_east_looks_north_and_cuts_on_the_line()

A line drawn west to east cuts on the line and looks north.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_west_to_east_looks_north_and_cuts_on_the_line(self):
    """A line drawn west to east cuts on the line and looks north."""
    self._assert_section((-6, 16), (36, 16), (0, 1, 0))
test_south_to_north_looks_west_and_cuts_on_the_line()

A line drawn south to north cuts on the line and looks west.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_south_to_north_looks_west_and_cuts_on_the_line(self):
    """A line drawn south to north cuts on the line and looks west."""
    self._assert_section((14.25, -12), (14.25, 36), (-1, 0, 0))
setUp()

Skip family documents and open the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def setUp(self):
    """Skip family documents and open the transaction."""
    if revit.doc.IsFamilyDocument:
        self.skipTest("Requires model document, not family document")
    self.transaction = DB.Transaction(revit.doc, "create view helpers test")
    self.transaction.Start()
tearDown()

Roll back the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def tearDown(self):
    """Roll back the transaction."""
    self.transaction.RollBack()

CropViewToElementsTests

Bases: RolledBackTestCase

Regression tests for #4022.

Attributes

PADDING = 1.0 class-attribute instance-attribute

Methods:

test_crop_applies_on_a_view_with_a_scope_box()

The crop box matches the elements even though the view had a scope box.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_crop_applies_on_a_view_with_a_scope_box(self):
    """The crop box matches the elements even though the view had a scope box."""
    view, level = self._plan_view_with_scope_box(self._first_scope_box())
    scope_width = view.CropBox.Max.X - view.CropBox.Min.X
    wall = self._wall_wider_than(level, scope_width)
    revit.doc.Regenerate()
    extents = query.get_elements_bounding_box([wall])
    expected_width = extents.Max.X - extents.Min.X + 2 * self.PADDING
    self.assertNotAlmostEqual(scope_width, expected_width)
    update.crop_view_to_elements(view, [wall], padding=self.PADDING)
    revit.doc.Regenerate()
    self.assertTrue(view.CropBoxActive)
    self.assertAlmostEqual(
        view.CropBox.Max.X - view.CropBox.Min.X, expected_width, delta=1e-3
    )
setUp()

Skip family documents and open the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def setUp(self):
    """Skip family documents and open the transaction."""
    if revit.doc.IsFamilyDocument:
        self.skipTest("Requires model document, not family document")
    self.transaction = DB.Transaction(revit.doc, "create view helpers test")
    self.transaction.Start()
tearDown()

Roll back the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def tearDown(self):
    """Roll back the transaction."""
    self.transaction.RollBack()

CreateModel3dViewTests

Bases: RolledBackTestCase

Regression tests for #4023.

Methods:

test_model_elements_leave_out_sheets_and_cameras()

Sheets and cameras have extents far beyond the building.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_model_elements_leave_out_sheets_and_cameras(self):
    """Sheets and cameras have extents far beyond the building."""
    self._create_sheet_and_camera()
    excluded_ids = [
        DB.ElementId(DB.BuiltInCategory.OST_Sheets),
        DB.ElementId(DB.BuiltInCategory.OST_Cameras),
    ]
    existing = [
        element
        for element in DB.FilteredElementCollector(
            revit.doc
        ).WhereElementIsNotElementType()
        if element.Category is not None and element.Category.Id in excluded_ids
    ]
    found_categories = set(element.Category.Id for element in existing)
    self.assertEqual(
        len(found_categories),
        len(excluded_ids),
        "fixtures must create both a sheet and a camera",
    )
    leaked = [
        element
        for element in query.get_model_elements()
        if element.Category.Id in excluded_ids
    ]
    self.assertEqual(leaked, [])
test_section_box_hugs_the_model()

The default section box is the model's extents plus padding.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_section_box_hugs_the_model(self):
    """The default section box is the model's extents plus padding."""
    elements = query.get_model_elements()
    if not elements:
        self.skipTest("No model elements to frame")
    extents = query.get_elements_bounding_box(elements)
    view = create.create_model_3d_view()
    box = view.GetSectionBox()
    for axis in ("X", "Y", "Z"):
        model_size = getattr(extents.Max, axis) - getattr(extents.Min, axis)
        box_size = getattr(box.Max, axis) - getattr(box.Min, axis)
        self.assertLess(box_size, model_size + 10.0)
setUp()

Skip family documents and open the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def setUp(self):
    """Skip family documents and open the transaction."""
    if revit.doc.IsFamilyDocument:
        self.skipTest("Requires model document, not family document")
    self.transaction = DB.Transaction(revit.doc, "create view helpers test")
    self.transaction.Start()
tearDown()

Roll back the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def tearDown(self):
    """Roll back the transaction."""
    self.transaction.RollBack()

PlaceOnSheetTests

Bases: RolledBackTestCase

Regression tests for #4024.

Methods:

test_a_sheet_is_rejected_as_a_view()

Passing a sheet names it as a sheet instead of blaming the sheet it is on.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def test_a_sheet_is_rejected_as_a_view(self):
    """Passing a sheet names it as a sheet instead of blaming the sheet it is on."""
    sheet = DB.ViewSheet.CreatePlaceholder(revit.doc)
    other = DB.ViewSheet.CreatePlaceholder(revit.doc)
    with self.assertRaises(PyRevitException) as caught:
        create.place_on_sheet(sheet, other)
    self.assertIn("not a view", str(caught.exception))
setUp()

Skip family documents and open the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def setUp(self):
    """Skip family documents and open the transaction."""
    if revit.doc.IsFamilyDocument:
        self.skipTest("Requires model document, not family document")
    self.transaction = DB.Transaction(revit.doc, "create view helpers test")
    self.transaction.Start()
tearDown()

Roll back the transaction.

Source code in pyrevitlib/pyrevit/unittests/test_create_view_helpers.py
def tearDown(self):
    """Roll back the transaction."""
    self.transaction.RollBack()