Sample Code Revit Batch Processor 1.1.16 documentation

Contents:

This Page

duHast.Revit.Family.Export package

Submodules

duHast.Revit.Family.Export.to_data_item module

Covers placed family instances belonging to a caller-supplied list of categories (furniture, equipment, specialty equipment, etc.). ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

duHast.Revit.Family.Export.to_data_item.get_location_data(revit_family_instance)

Extracts the placement location and orientation of a family instance and returns them as a populated DataGeometryBase instance.

  • translation_coord - x/y/z position converted to metric mm (Point3)

  • rotation_coord - 3 x 3 rotation matrix derived from the instance’s

    local transform (each row is a basis vector [x, y, z])

Only Autodesk.Revit.DB.LocationPoint instances are supported. Line-based placements (LocationCurve) return None.

Parameters:

revit_family_instance (Autodesk.Revit.DB.FamilyInstance) – A placed Revit family instance.

Returns:

A populated location data object, or None if the location type is not a point.

Return type:

DataGeometryBase or None

duHast.Revit.Family.Export.to_data_item.get_room_ids(doc, revit_family_instance)

Returns a list of unique room element ids that the family instance belongs to, resolved across all project phases.

Lookup strategy (in order):

  1. Phase-aware - iterates doc.Phases and calls FamilyInstance.get_Room(phase) for each phase. This is the primary source and correctly handles items whose room assignment changes between construction phases.

  2. Direct property - FamilyInstance.Room is tried when the phase loop yields nothing (e.g. older family hosting types).

  3. Point fallback - if both of the above return nothing, the instance’s LocationPoint is used with Document.GetRoomAtPoint to perform a spatial lookup against the last project phase.

Note

Doors and windows should use FamilyInstance.FromRoom / FamilyInstance.ToRoom instead. Those categories are not included in DEFAULT_ITEM_CATEGORIES, so this function does not handle that case.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current Revit model document.

  • revit_family_instance (Autodesk.Revit.DB.FamilyInstance) – A placed Revit family instance.

Returns:

Unique room element ids (integers), may be empty.

Return type:

list[int]

duHast.Revit.Family.Export.to_data_item.get_level_data_by_bounding_box(doc, revit_family_instance)

Determines the nearest level below a family instance by comparing the lowest Z coordinate of its solid geometry against the ascending list of project levels.

Algorithm:

  1. Compute the solid-based bounding box of the instance.

  2. Take bbox.Min.Z (internal Revit feet) as the bottom of the item.

  3. Walk all levels sorted ascending by ProjectElevation and keep the last one whose elevation is at or below bbox.Min.Z.

  4. If the item sits below every level (e.g. underground) the lowest level is used as a fallback.

  5. offset_from_level = bbox.Min.Z - level.ProjectElevation, converted to metric mm.

Returns a default empty DataLevel when no solid geometry or no levels are found in the document.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current Revit model document.

  • revit_family_instance (Autodesk.Revit.DB.FamilyInstance) – A placed Revit family instance.

Returns:

A populated data level instance.

Return type:

DataLevel

duHast.Revit.Family.Export.to_data_item.populate_data_item_object(doc, revit_family_instance)

Returns a DataItem populated from a single placed family instance.

Populated fields:

  • instance id and instance parameters

  • type name and type parameters

  • level name, level id, and offset from level

  • location point (x/y/z in mm) and rotation matrix

  • phasing (created / demolished)

  • design set / option membership

  • model name

Returns None when the instance has no valid LocationPoint (e.g. line-based families).

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current Revit model document.

  • revit_family_instance (Autodesk.Revit.DB.FamilyInstance) – A placed Revit family instance.

Returns:

A populated data item object, or None.

Return type:

DataItem or None

duHast.Revit.Family.Export.to_data_item.get_all_item_data(doc, categories=None)

Collects all placed Autodesk.Revit.DB.FamilyInstance elements belonging to the given list of categories and returns a list of DataItem objects.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current Revit model document.

  • categories (list[Autodesk.Revit.DB.BuiltInCategory] or None) – List of Autodesk.Revit.DB.BuiltInCategory values to collect from. Defaults to DEFAULT_ITEM_CATEGORIES when None is supplied.

Returns:

A list of populated data item instances.

Return type:

list[DataItem]

Module contents