Sample Code Revit Batch Processor 1.1.16 documentation

Contents:

This Page

duHast.Data package

Subpackages

Submodules

duHast.Data.data_to_shapely module

Utility functions converting data retrieved from Revit into shapely geometry and processing it.

This module requires python >3.9 due to dependencies:

  • numpy

  • shapely

duHast.Data.data_to_shapely.get_translation_matrix(geometry_object)

Gets the rotation/ translation matrix from the geometry object

Parameters:

geometry_object (DataGeometry) – A data geometry object instance.

Returns:

A translation matrix.

Return type:

numpy array

duHast.Data.data_to_shapely.get_outer_loop_as_shapely_points(geometry_object, translation_matrix)

Returns the boundary loop of an object as list of shapely points.

Points are translated with passed in matrix. Any loops containing less then 3 points will be ignored. (Empty list will be returned)

Parameters:
  • geometry_object (DataGeometry) – A data geometry object instance.

  • translation_matrix (numpy array) – A translation matrix.

Returns:

List of shapely points defining a polygon. (Empty list will be returned if less then 3 points in loop.)

Return type:

List[shapely.point]

duHast.Data.data_to_shapely.get_inner_loops_as_shapely_points(geometry_object, translation_matrix)

Returns the inner loops (holes) of an object as list of lists of shapely points.

Points are translated with passed in matrix. Any inner loops containing less then 3 points will be ignored. (Empty list will be returned)

Parameters:
  • geoObject (DataGeometry) – A data geometry object instance.

  • translationM (numpy array) – A translation matrix.

Returns:

List of lists of shapely points defining a polygon.

Return type:

list [list[shapely.point]]

duHast.Data.data_to_shapely.build_shapely_polygon(shapely_polygons)

Creates shapely polygon with nested polygons from list of shapely polygons past in.

Assumptions is: first polygon describes the boundary loop and any subsequent polygons are describing holes within the boundary

Parameters:

shapely_polygons (list[shapely.polygon]) – list of shapely polygons

Returns:

A shapely polygon.

Return type:

shapely.polygon

duHast.Data.data_to_shapely.get_shapely_polygons_from_data_instance(data_instance)

Returns a list of of shapely polygons from data instances past in.

Polygons may contain holes

Parameters:

data_instance (A class with .geometry property returning a DataGeometry instance.) – _description_

Returns:

A list of shapely polygons.

Return type:

list [shapely.polygon]

duHast.Data.data_to_shapely.GEOMETRY_CONVERTER = {'ceiling': <function get_shapely_polygons_from_data_instance>, 'floor': <function get_shapely_polygons_from_data_instance>, 'room': <function get_shapely_polygons_from_data_instance>}

List of available geometry (from revit to shapely ) converters

duHast.Data.data_to_shapely.get_shapely_polygons_from_geo_object(geometry_objects, data_type)

Converts polygon points from DataGeometry instances to shapely polygon instances and returns them as a dictionary where:

  • key is the geometry objects id

  • value is a list of shapely polygons

Parameters:
  • geometry_objects (list[data object]) – A list of instances of the the same type (i.e DataRoom)

  • data_type (str) – string human readable identifying the data type ( each Data… class has this as a static field: dr.DataRoom.dataType)

Returns:

A dictionary.

Return type:

{int:[shapely.polygon]}

duHast.Data.process_ceilings_to_rooms module

Sample showing how to find which ceilings are in which rooms.

This module requires python >3.9 due to dependencies:

  • numpy

  • shapely

This module:

  • collects ceiling and room data instances by level ( assume a ceiling is always modelled as the room it is in )

  • converts room and ceiling outlines to shapely polygons

  • test for intersection of all ceilings on a given level with all rooms on a given level

  • stores any intersections found ( does a check how much area is intersecting…if to small its assumed its not an intended intersection)

  • reports all rooms and any associated ceiling(s) found

duHast.Data.process_ceilings_to_rooms.write_data_to_file(data, output_file_path, room_instance_property_keys=['Number', 'Name'], ceiling_type_property_keys=['Type Mark'], ceiling_instance_property_keys=['Height Offset From Level'])

Writes Room data to file.

Note:

  • Room data consists of fixed (always reported) instance properties and custom instance properties defined in room_instance_property_keys

  • Ceiling data consists of fixed (always reported) instance properties, custom type properties defined in ceiling_type_property_keys and custom instance properties defined in ceiling_instance_property_keys

  • the report contains a row per associated element per room ( if 2 ceilings are in a room, the report will contain 2 rows)

Parameters:
  • data ({str:[:class: .DataRoom]}) – A dictionary where key is the level name and values is a list of DataRoom instances.

  • output_file_path (str) – Fully qualified file path to output report file.

  • room_instance_property_keys (list, optional) – Names of room instance properties to be reported, defaults to [‘Number’, ‘Name’]

  • ceiling_type_property_keys (list, optional) – Names of ceiling type properties to be reported, defaults to [‘Type Mark’]

  • ceiling_instance_property_keys (list, optional) – Names of ceiling instance properties to be reported, defaults to [‘Height Offset From Level’]

Returns:

Result class instance.

  • Export status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the processing messages.

  • result.result will be an empty list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Data.process_ceilings_to_rooms.get_ceilings_by_room(data_source_path)

Reads Revit data from file and runs an intersection check of each ceiling on a level with each room on the same level.

Note: DataRoom instance will contain any ceilings in that room in associated elements property.

Parameters:

data_source_path (str) – Fully qualified file path to json formatted file containing DataRoom and DataCeiling objects.

Returns:

Result class instance.

  • result.status False if an exception occurred, otherwise True.

  • result.message will contain processing messages.

  • result.result A dictionary where key is the level name, value is a tuple of two lists: first one are rooms, second ones are ceiling data objects.

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

  • result.result will be an empty list

Return type:

Result

duHast.Data.process_floors_to_rooms module

Sample showing how to find which floors are in which rooms.

This module requires python >3.9 due to dependencies:

  • numpy

  • shapely

This module:

  • collects floor and room data instances by level (assumes a floor is always modelled within the room it belongs to)

  • converts room and floor outlines to shapely polygons

  • tests for intersection of all floors on a given level with all rooms on a given level

  • stores any intersections found (checks how much area is intersecting; if too small it is assumed not an intended intersection)

  • reports all rooms and any associated floor(s) found

duHast.Data.process_floors_to_rooms.write_data_to_file(data, output_file_path, room_instance_property_keys=['Number', 'Name'], floor_type_property_keys=['Type Mark'], floor_instance_property_keys=['Height Offset From Level'])

Writes room + associated floor data to a CSV file.

The report contains one row per associated floor per room.

Parameters:
  • data (dict{str: (list[DataRoom], list[DataFloor])}) – Dictionary keyed by level name, values are (rooms, floors) tuples.

  • output_file_path (str) – Fully qualified path for the output CSV file.

  • room_instance_property_keys (list[str], optional) – Room instance parameter names to report. Defaults to ['Number', 'Name'].

  • floor_type_property_keys (list[str], optional) – Floor type parameter names to report. Defaults to ['Type Mark'].

  • floor_instance_property_keys (list[str], optional) – Floor instance parameter names to report. Defaults to ['Height Offset From Level'].

Returns:

Result instance with status and messages.

Return type:

Result

duHast.Data.process_floors_to_rooms.get_floors_by_room(data_source_path)

Reads Revit data from file and runs an intersection check of each floor on a level with each room on the same level.

Any floor whose polygon overlaps a room by more than 0.1 % of the room area is added to that room’s associated_elements list.

Parameters:

data_source_path (str) – Fully qualified path to a json file containing DataRoom and DataFloor objects.

Returns:

Result class instance.

  • result.status: False if an exception occurred, otherwise True.

  • result.message: processing messages.

  • result.result: dictionary keyed by level name, values are (rooms, floors) tuples with rooms populated with associated floors.

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

  • result.result will be an empty list.

Return type:

Result

duHast.Data.process_items_to_rooms module

Sample showing how to find which items (furniture, equipment, etc.) belong to which rooms.

This module:

  • reads room and item data instances from a json file

  • matches each item to its room(s) using the room ids already stored on the item (populated during export via Revit’s phase-aware room lookup)

  • reports all rooms and any associated item(s) found

No shapely / numpy dependency — room membership is resolved by id, not by geometry.

duHast.Data.process_items_to_rooms.write_data_to_file(data, output_file_path, room_instance_property_keys=['Number', 'Name'], item_type_property_keys=['Type Mark'], item_instance_property_keys=[])

Writes room + associated item data to a CSV file.

The report contains one row per associated item per room.

Parameters:
  • data (dict{str: (list[DataRoom], list[DataItem])}) – Dictionary keyed by level name, values are (rooms, items) tuples.

  • output_file_path (str) – Fully qualified path for the output CSV file.

  • room_instance_property_keys (list[str], optional) – Room instance parameter names to report. Defaults to ['Number', 'Name'].

  • item_type_property_keys (list[str], optional) – Item type parameter names to report. Defaults to ['Type Mark'].

  • item_instance_property_keys (list[str], optional) – Item instance parameter names to report. Defaults to [].

Returns:

Result instance with status and messages.

Return type:

Result

duHast.Data.process_items_to_rooms.get_items_by_room(data_source_path)

Reads Revit data from file and matches each item to the room(s) it belongs to using the room ids already stored on the item.

Any matched item is added to that room’s associated_elements list.

Parameters:

data_source_path (str) – Fully qualified path to a json file containing DataRoom and DataItem objects.

Returns:

Result class instance.

  • result.status: False if an exception occurred, otherwise True.

  • result.message: processing messages.

  • result.result: dictionary keyed by level name, values are (rooms, items) tuples with rooms populated with associated items.

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

  • result.result will be an empty list.

Return type:

Result

Module contents