Skip to main content

Geometry selection

New in v14.10.0

The geometry selection fields, enable the user to select geometries in a IFCView or GeometryView (coming soon).

Select a geometry

The GeometrySelectField enables the user to select a (sub-)geometry in a geometric view, which is returned in the params as an identifier (string):

from viktor.parametrization import ViktorParametrization, GeometrySelectField


class Parametrization(ViktorParametrization):
selected_geometry = GeometrySelectField("Select a geometry")

Select multiple geometries

The GeometryMultiSelectField enables the user to select multiple (sub-)geometries in a geometric view, which is returned in the params as a list of identifiers (string):

from viktor.parametrization import ViktorParametrization, GeometryMultiSelectField


class Parametrization(ViktorParametrization):
selected_geometries = GeometryMultiSelectField("Select geometries")

Select a geometry in a DynamicArray

The GeometrySelectField and GeometryMultiSelectField can be used in combination with a DynamicArray to allow an arbitrary number of geometries or group of geometries to be selected and assign or group these with additional parameters:

from viktor.parametrization import ViktorParametrization, GeometrySelectField, DynamicArray, NumberField


class Parametrization(ViktorParametrization):
load_cases = DynamicArray("Load Cases")
load_cases.geometry = GeometrySelectField("Geometry")
load_cases.load = NumberField("Load", suffix="N")

Use a selected geometry

note

Geometry selection is currently only enabled for the IFCView. We will soon also enable geometry selection on the GeometryView.

When the user selects a geometry with these fields, the geometry is returned in the params as the provided identifier (string).

tip

To make use of Geometry Selection Fields, it is not mandatory to provide your own "identifiers" in your geometry model, however it is recommended to explicitly specify them for easier selection for the User and easier post-processing for the Developer.

If several objects have an identifier assigned, then only these objects will be selectable in the View. If none of the objects in the GeometryResult have an identifier assigned, default identifiers are assigned to all of them (enabling them for selection). Note: if there are multiple objects with the same name, a number will automatically be appended to enforce uniqueness.

from viktor import ViktorController
from viktor.parametrization import ViktorParametrization, GeometrySelectField, FileField
from viktor.views import IFCAndDataView, IFCAndDataResult, DataGroup, DataItem
...

class Parametrization(ViktorParametrization):
ifc = FileField("Please provide an IFC file")
selected_geometry = GeometrySelectField("Select a geometry")


class MyController(ViktorController):
label = 'My Entity Type'
parametrization = Parametrization
...

@IFCAndDataView("IFC", duration_guess=1, x_axis_to_right=True)
def get_ifc_and_data_view(self, params, **kwargs):
ifc_file = params.ifc.file

# parse your ifc file and map the ifc identifier with relevant properties,
# consider using ifcopenshell to parse your ifc file
parsed_ifc_file = {...}

# Calculate data
if params.selected_geometry: # If user has made a selection, add volume to `data`
volume = parsed_ifc_file[params.selected_geometry]["volume"]
data = DataGroup(DataItem('Geometry volume', volume, suffix="m3"))
else:
data = DataGroup(DataItem('No geometries selected', ''))
return IFCAndDataResult(ifc=ifc_file, data=data)