Пример #1
0
def write_to_ifc(
    destination_file,
    a: Assembly,
    include_fem,
    return_file_obj=False,
    create_new_ifc_file=False,
) -> Union[None, StringIO]:
    from ada.ifc.utils import assembly_to_ifc_file

    if create_new_ifc_file:
        f = assembly_to_ifc_file(a)
    else:
        f = a.ifc_file

    for s in a.sections:
        f.add(s.ifc_profile)
        f.add(s.ifc_beam_type)

    for m in a.materials.name_map.values():
        f.add(m.ifc_mat)

    for p in a.get_all_parts_in_assembly(include_self=True):
        add_part_objects_to_ifc(p, f, a, include_fem)

    all_groups = [
        p.groups.values()
        for p in a.get_all_parts_in_assembly(include_self=True)
    ]
    for group in chain.from_iterable(all_groups):
        group.to_ifc(f)

    if len(a.presentation_layers) > 0:
        presentation_style = f.createIfcPresentationStyle("HiddenLayers")
        f.createIfcPresentationLayerWithStyle(
            "HiddenLayers",
            "Hidden Layers (ADA)",
            a.presentation_layers,
            "10",
            False,
            False,
            False,
            [presentation_style],
        )

    if return_file_obj:
        return StringIO(f.wrapped_data.to_string())

    dest = pathlib.Path(destination_file).with_suffix(".ifc")
    os.makedirs(dest.parent, exist_ok=True)
    f.write(str(dest))
    a._source_ifc_files = dict()
Пример #2
0
    def test_ifc_roundtrip(self):
        a = Assembly("my_test_assembly")
        a.add_part(SimpleStru("my_simple_stru"))
        a.to_ifc(test_folder / "my_test.ifc")

        b = Assembly("MyReImport")
        b.read_ifc(test_folder / "my_test.ifc")
        b.to_ifc(test_folder / "my_test_re_exported.ifc")

        all_parts = b.get_all_parts_in_assembly()
        assert len(all_parts) == 3
Пример #3
0
    def test_parts_list(self):
        a = Assembly("MyAssembly")
        # Level 1
        part = Part("my_part1")
        a.add_part(part)
        a.add_part(Part("my_part2"))
        # Level 2
        part.add_part(Part("my_part1_subpart1"))
        part.add_part(Part("my_part1_subpart2"))
        # Level 3
        subpart3 = Part("my_part1_subpart3")
        subpart3.add_part(Part("my_part1_subpart3_sub1"))
        part.add_part(subpart3)
        list_of_ps = a.get_all_parts_in_assembly()

        self.assertEqual(len(list_of_ps), 6)
Пример #4
0
def get_fem_model_from_assembly(assembly: Assembly) -> Part:
    """
    Scans the assembly tree for parts containing FEM elements. If multiple FEM objects are not empty,
    they will be merged
    """
    parts = list(
        filter(lambda p: p.fem.is_empty() is False,
               assembly.get_all_parts_in_assembly(True)))

    if len(parts) > 1:
        raise ValueError(
            "This method does not yet support multipart FEM. Please make sure your assembly only contain 1 FEM"
        )
    elif len(parts) == 0:
        raise ValueError("At least 1 part must have a FEM mesh ")

    return parts[0]