Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Added
- Added utility function to query wall_frame elements from selection

### Changed

Expand Down
60 changes: 40 additions & 20 deletions src/compas_cadwork/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from typing import List
from typing import Dict
from typing import Union
from typing import Generator
from typing import List
from typing import Union

import attribute_controller as ac
import cadwork
import utility_controller as uc
import element_controller as ec
import attribute_controller as ac
import utility_controller as uc
import visualization_controller as vc

from compas.geometry import Point
from compas_cadwork.conversions import point_to_compas
from compas_cadwork.datamodel import Dimension
from compas_cadwork.datamodel import Element
from compas_cadwork.datamodel import ElementGroup
from compas_cadwork.datamodel import Dimension
from compas_cadwork.conversions import point_to_compas

from .ifc_export import IFCExporter
from .ifc_export import IFCExportSettings
Expand Down Expand Up @@ -140,6 +139,27 @@ def get_element_groups(is_wall_frame: bool = True) -> Dict[str, ElementGroup]:
return groups_elements


def get_element_groups_from_selection(is_wall_frame: bool = True) -> Dict[str, ElementGroup]:
"""Return a dictionary of ElementGroups built from the currently selected elements."""

get_grouping_name = _get_grouping_func()

groups_elements = {}
for element_id in ec.get_active_identifiable_element_ids():
group_name = get_grouping_name(element_id)
if not group_name:
continue

if group_name not in groups_elements:
groups_elements[group_name] = ElementGroup(group_name)
groups_elements[group_name].add_element(Element(element_id))

if is_wall_frame:
_remove_wallless_groups(groups_elements)

return groups_elements


def _get_grouping_func() -> callable:
if ac.get_element_grouping_type() == cadwork.element_grouping_type.subgroup:
return ac.get_subgroup
Expand Down Expand Up @@ -342,29 +362,29 @@ def save_project_file():


__all__ = [
"IFCExporter",
"IFCExportSettings",
"get_plugin_home",
"get_filename",
"get_active_elements",
"get_element_groups",
"IFCExporter",
"activate_elements",
"hide_elements",
"lock_elements",
"unlock_elements",
"show_all_elements",
"hide_all_elements",
"disable_autorefresh",
"enable_autorefresh",
"force_refresh",
"get_active_elements",
"get_all_element_ids",
"get_all_elements",
"get_all_elements_with_attrib",
"remove_elements",
"save_project_file",
"zoom_active_elements",
"get_bounding_box_from_cadwork_object",
"get_dimensions",
"get_element_groups",
"get_filename",
"get_plugin_home",
"get_user_point",
"hide_all_elements",
"hide_elements",
"is_cadwork_window_in_dark_mode",
"lock_elements",
"remove_elements",
"save_project_file",
"show_all_elements",
"unlock_elements",
"zoom_active_elements",
]