def test_count_types(): with CATIADocHandler(cat_product) as caa: documents = caa.documents num = documents.count_types('.catpart') assert num == 1
def test_part(): with CATIADocHandler(cat_part_measurable) as caa: document = caa.document part = document.part() assert part.name == "cat_part_measurable" assert document.is_part assert not document.is_product
def test_add_documents(): with CATIADocHandler(new_document='Part') as caa: document = caa.document assert 'CATPart' in document.name with CATIADocHandler(new_document='Part') as caa: document = caa.document assert 'CATPart' in document.name with CATIADocHandler(new_document='Part') as caa: document = caa.document assert 'CATPart' in document.name with pytest.raises(ValueError): with CATIADocHandler(new_document='lala'): pass
def test_line_point_point(): length = 100 co_ord_1 = (0, 0, 0) co_ord_2 = (length, 0, 0) with CATIADocHandler(new_document='Part') as caa: document = caa.document part = document.part() hsf = part.hybrid_shape_factory hybrid_bodies = part.hybrid_bodies gs_new = hybrid_bodies.add() point_1 = hsf.add_new_point_coord(co_ord_1[0], co_ord_1[1], co_ord_1[2]) point_2 = hsf.add_new_point_coord(co_ord_2[0], co_ord_2[1], co_ord_2[2]) gs_new.append_hybrid_shape(point_1) gs_new.append_hybrid_shape(point_2) line = hsf.add_new_line_pt_pt(point_1, point_2) gs_new.append_hybrid_shape(line) part.update() line_ref = part.create_reference_from_object(line) spa_wb = document.spa_workbench() measurable = spa_wb.get_measurable(line_ref) assert measurable.length == length
def test_full_name(): """ :return: """ with CATIADocHandler(cat_part_measurable) as caa: document = caa.document assert str(cat_part_measurable) == document.full_name
def test_open_document(): # This assertion has been removed as my version of CATIA keeps an open link to ABQMaterialPropertiesCatalog.CATfct # once the document is closed. I don't know if this is a CATIA bug or `feature` to keep the linked item loaded. # assert documents.documents.Count == 0 with CATIADocHandler(cat_part_measurable) as caa: document = caa.document assert document.name == cat_part_measurable.name assert f'Document(name="{document.name}")' == document.__repr__()
def test_get_documents_names(): with CATIADocHandler(cat_product) as caa: documents = caa.documents expected_names = [ 'product_top.CATProduct', 'product_sub_2.CATProduct', 'part_measurable.CATPart', 'product_sub_1.CATProduct', ] assert documents.get_item_names() == expected_names
def test_export_document(): with CATIADocHandler(cat_part_measurable) as caa: document = caa.document export_type = 'igs' export_name = 'export_file' path = os.path.dirname(os.path.abspath(cat_part_measurable)) export_name = os.path.join(path, export_name) document.export_data(export_name, export_type) assert os.path.isfile(f'{export_name}.igs') os.remove(f'{export_name}.igs')
def test_saving(): new_filename = os.path.join(os.getcwd(), '__junk__/', (now_string + '.CATPart')) with CATIADocHandler(cat_part_measurable) as caa: document = caa.document document.save_as(new_filename) document.save() assert os.path.isfile(new_filename) with pytest.raises(FileExistsError): document.save_as(new_filename) os.remove(new_filename)
def test_is_saved(): with CATIADocHandler(cat_part_measurable) as caa: document = caa.document assert document.is_saved part = document.part() # create a new geometrical set to add point. geometrical_set = part.hybrid_bodies.add() geometrical_set.Name = 'lalalalalala' # just adding geometrical set isn't enough to trigger is_saved to be False # catia r21 bug? # so a new point is also added. factory = part.hybrid_shape_factory point = factory.add_new_point_coord(0, 1, 2) geometrical_set.append_hybrid_shape(point) part.update() assert not document.is_saved
def test_product(): with CATIADocHandler(cat_product) as caa: document = caa.document product = document.product() assert 'cat_product_1' in product.name assert document.is_product
def test_num_open(): with CATIADocHandler(cat_part_measurable) as caa: documents = caa.documents # see warning in documentation for num_open() assert documents.num_open() == 1
def test_item(): with CATIADocHandler(cat_product) as caa: documents = caa.documents doc_com1 = documents.item(cat_product.name) assert (doc_com1.name == cat_product.name)