Sample Code Revit Batch Processor 1.1.14 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>, '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

Module contents