Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.Purge package

Subpackages

Submodules

duHast.Revit.Purge.purge_action module

Purge action storage class for Revit purge unused.

class duHast.Revit.Purge.purge_action.PurgeAction(purgeTransactionName, purgeIdsGetter, purgeReportHeader, testReportHeader, testIdsGetter)

Bases: Base

Class constructor.

Parameters:
  • purgeTransactionName (str) – The name of the transaction to purge elements under.

  • purgeIdsGetter (func) – The function which returns all element ids to be purged

  • purgeReportHeader (str) – Human readable report header for each purge action

  • testReportHeader (str) – Human readable report header for each test action

  • testIdsGetter (func) – functions which returns all available type ids in model of same category as purge action. To be used to compare ids before and after code purge with ids before and after revit built in purge

duHast.Revit.Purge.purge_unused module

This module contains a purge unused function using standard revit api functions.

Some functionality provided here exceeds the Revit purge unused or e-transmit purge unused command:

  • view types

  • view templates

  • view filters

Others definitely lack:

  • Materials

  • Appearance assets

  • loadable Families

  • some MEP systems

Future: just provide improvements over e-transmit purge unused in this code section.

duHast.Revit.Purge.purge_unused.purge_unplaced_elements(doc, get_unused_element_ids, transaction_name, unused_element_name_header, is_debug=False)

Purges all unplaced elements provided through a passed in element id getter method from a model.

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

  • get_unused_element_ids (func (doc) returning list of Autodesk.Revit.DB.ElementId) – A function accepting the current document as the argument and returning element ids which can be purged.

  • transaction_name (str) – A human readable description of the transaction containing the purge action.

  • unused_element_name_header (str) – The text to be displayed at the start of the list containing the deleted element names.

  • is_debug (bool, optional) – True: will return detailed report and attempt to try to delete elements one by one if an exception occurs, defaults to False Will attempt to delete all elements at once.

Returns:

Result class instance.

  • .status True if all purge actions completed successfully. Otherwise False.

  • .message will be listing each purge action and its status

Return type:

Result

duHast.Revit.Purge.purge_unused.PURGE_ACTIONS = [PurgeAction(purge_transaction_name='Purge Unused Model Group(s)', purge_ids_getter=<function get_unplaced_model_group_ids>, purge_report_header='Model Group(s)', test_report_header='Model Group(s)', test_ids_getter=<function get_model_group_ids>), PurgeAction(purge_transaction_name='Purge Unused Detail Group(s)', purge_ids_getter=<function get_unplaced_detail_group_ids>, purge_report_header='Detail Group(s)', test_report_header='Detail Group(s)', test_ids_getter=<function get_detail_group_ids>), PurgeAction(purge_transaction_name='Purge Unused Nested Detail Group(s)', purge_ids_getter=<function get_unplaced_nested_detail_group_ids>, purge_report_header='Nested Detail Group(s)', test_report_header='Nested Detail Group(s)', test_ids_getter=<function get_nested_detail_group_ids>), PurgeAction(purge_transaction_name='Purge Unused View Family Types', purge_ids_getter=<function get_unused_view_type_ids>, purge_report_header='View Family Type(s)', test_report_header='View Family Type(s)', test_ids_getter=<function get_view_type_ids>), PurgeAction(purge_transaction_name='Purge Unused View Templates', purge_ids_getter=<function get_all_unused_view_template_ids>, purge_report_header='View Family Templates(s)', test_report_header='View Family Templates(s)', test_ids_getter=<function get_view_templates_ids>), PurgeAction(purge_transaction_name='Purge Unused View Filters', purge_ids_getter=<function get_all_unused_view_filters>, purge_report_header='View Filter(s)', test_report_header='View Filter(s)', test_ids_getter=<function get_all_filter_ids>), PurgeAction(purge_transaction_name='Purge Unused Image Links', purge_ids_getter=<function get_all_unused_image_type_ids_in_model>, purge_report_header='Images(s)', test_report_header='Images(s)', test_ids_getter=<function get_images_type_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Stacked Wall Types', purge_ids_getter=<function get_unused_stacked_wall_type_ids_to_purge>, purge_report_header='Stacked Wall Type(s)', test_report_header='Stacked Wall Type(s)', test_ids_getter=<function get_all_stacked_wall_type_ids>), PurgeAction(purge_transaction_name='Purge Unused InPlace Wall Types', purge_ids_getter=<function get_unused_in_place_wall_ids_for_purge>, purge_report_header='InPlace Wall Type(s)', test_report_header='InPlace Wall Type(s)', test_ids_getter=<function get_all_in_place_wall_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Curtain Wall Types', purge_ids_getter=<function get_unused_curtain_wall_type_ids_to_purge>, purge_report_header='Curtain Wall Type(s)', test_report_header='Curtain Wall Type(s)', test_ids_getter=<function get_all_curtain_wall_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Basic Types', purge_ids_getter=<function get_unused_basic_wall_type_ids_to_purge>, purge_report_header='Basic Wall Type(s)', test_report_header='Basic Wall Type(s)', test_ids_getter=<function get_all_basic_wall_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Curtain Wall Element Types', purge_ids_getter=<function get_unused_non_symbol_curtain_wall_element_type_ids_to_purge>, purge_report_header='Curtain Wall Element Type(s)', test_report_header='Curtain Wall Element Type(s)', test_ids_getter=<function get_all_curtain_wall_element_type_ids_by_category_excl_symbols>), PurgeAction(purge_transaction_name='Purge Unused Loadable Curtain Wall Symbol (Types)', purge_ids_getter=<function get_unused_curtain_wall_symbol_ids_for_purge>, purge_report_header='Curtain Wall Loadable Symbols (Type(s))', test_report_header='Curtain Wall Loadable Symbols (Type(s))', test_ids_getter=<function get_all_curtain_wall_non_shared_symbol_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused Ceiling Types', purge_ids_getter=<function get_unused_non_in_place_ceiling_type_ids_to_purge>, purge_report_header='Ceiling Type(s)', test_report_header='Ceiling Type(s)', test_ids_getter=<function get_all_ceiling_type_ids_in_model_by_class>), PurgeAction(purge_transaction_name='Purge Unused InPlace Ceiling Types', purge_ids_getter=<function get_unused_in_place_ceiling_ids_for_purge>, purge_report_header='InPlace Ceiling Type(s)', test_report_header='InPlace Ceiling Type(s)', test_ids_getter=<function get_all_in_place_ceiling_type_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Floor Types', purge_ids_getter=<function get_unused_non_in_place_floor_type_ids_to_purge>, purge_report_header='Floor Type(s)', test_report_header='Floor Type(s)', test_ids_getter=<function get_all_floor_type_ids_in_model_by_class>), PurgeAction(purge_transaction_name='Purge Unused InPlace Floor Types', purge_ids_getter=<function get_unused_in_place_floor_ids_for_purge>, purge_report_header='InPlace Floor Type(s)', test_report_header='InPlace Floor Type(s)', test_ids_getter=<function get_all_in_place_floor_type_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Roof Types', purge_ids_getter=<function get_unused_non_in_place_roof_type_ids_to_purge>, purge_report_header='Roof Type(s)', test_report_header='Roof Type(s)', test_ids_getter=<function get_all_roof_type_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused InPlace Roof Types', purge_ids_getter=<function get_unused_in_place_roof_type_ids_for_purge>, purge_report_header='InPlace Roof Type(s)', test_report_header='InPlace Roof Type(s)', test_ids_getter=<function get_all_in_place_roof_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Stair Types', purge_ids_getter=<function get_unused_non_in_place_stair_type_ids_to_purge>, purge_report_header='Stair Type(s)', test_report_header='Stair Type(s)', test_ids_getter=<function get_all_stair_type_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused Path Types', purge_ids_getter=<function get_unused_stair_path_type_ids_to_purge>, purge_report_header='Stair Path Type(s)', test_report_header='Stair Path Type(s)', test_ids_getter=<function get_stair_path_types_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused Landing Types', purge_ids_getter=<function get_unused_stair_landing_type_ids_to_purge>, purge_report_header='Stair Landing Type(s)', test_report_header='Stair Landing Type(s)', test_ids_getter=<function get_stair_landing_types_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused Run Types', purge_ids_getter=<function get_unused_stair_run_type_ids_to_purge>, purge_report_header='Stair Run Type(s)', test_report_header='Stair Run Type(s)', test_ids_getter=<function get_stair_run_types_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused Stringers and Carriage Types', purge_ids_getter=<function get_unused_stair_stringers_carriage_type_ids_to_purge>, purge_report_header='Stair Stringers and Carriage Type(s)', test_report_header='Stair Stringers and Carriage Type(s)', test_ids_getter=<function get_all_stair_stringers_carriage_type_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused InPlace Stair Types', purge_ids_getter=<function get_unused_in_place_stair_type_ids_for_purge>, purge_report_header='InPlace Stair Type(s)', test_report_header='InPlace Stair Type(s)', test_ids_getter=<function get_all_in_place_stair_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Ramp Types', purge_ids_getter=<function get_unused_non_in_place_ramp_type_ids_to_purge>, purge_report_header='Ramp Type(s)', test_report_header='Ramp Type(s)', test_ids_getter=<function get_all_ramp_types_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused Stair Cut Mark Types', purge_ids_getter=<function get_unused_stair_cut_mark_type_ids_to_purge>, purge_report_header='Stair Cut Mark Type(s)', test_report_header='Stair Cut Mark Type(s)', test_ids_getter=<function get_stair_cut_mark_types_ids_by_class>), PurgeAction(purge_transaction_name='Purge Unused Building Pad Types', purge_ids_getter=<function get_unused_non_in_place_building_pad_type_ids_to_purge>, purge_report_header='Building Pad Type(s)', test_report_header='Building Pad Type(s)', test_ids_getter=<function get_all_building_pad_type_ids_in_model_by_class>), PurgeAction(purge_transaction_name='Purge Unused Railing Types', purge_ids_getter=<function get_unused_non_in_place_railing_type_ids_to_purge>, purge_report_header='Railing Type(s)', test_report_header='Railing Type(s)', test_ids_getter=<function get_all_railing_type_ids_by_class_and_category>), PurgeAction(purge_transaction_name='Purge Unused InPlace Railing Types', purge_ids_getter=<function get_unused_in_place_railing_ids_for_purge>, purge_report_header='In Place Railing Type(s)', test_report_header='In Place Railing Type(s)', test_ids_getter=<function get_in_place_railing_type_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Baluster Types', purge_ids_getter=<function get_unused_baluster_type_ids_for_purge>, purge_report_header='Baluster Type(s)', test_report_header='Baluster Type(s)', test_ids_getter=<function get_all_baluster_symbols_ids>), PurgeAction(purge_transaction_name='Purge Unused Cable Tray Types', purge_ids_getter=<function get_unused_cable_tray_type_ids_to_purge>, purge_report_header='Cable Tray Type(s)', test_report_header='Cable Tray Type(s)', test_ids_getter=<function get_all_cable_tray_type_ids_in_model_by_category>), PurgeAction(purge_transaction_name='Purge Unused Conduit Types', purge_ids_getter=<function get_unused_conduit_type_ids_to_purge>, purge_report_header='Conduit Type(s)', test_report_header='Conduit Type(s)', test_ids_getter=<function get_all_conduit_type_ids_in_model_by_category>), PurgeAction(purge_transaction_name='Purge Unused Duct Types', purge_ids_getter=<function get_unused_duct_type_ids_to_purge>, purge_report_header='Duct Type(s)', test_report_header='Duct Type(s)', test_ids_getter=<function get_all_duct_type_ids_in_model_by_category>), PurgeAction(purge_transaction_name='Purge Unused Pipe Types', purge_ids_getter=<function get_unused_pipe_type_ids_to_purge>, purge_report_header='Pipe Type(s)', test_report_header='Pipe Type(s)', test_ids_getter=<function get_all_pipe_type_ids_in_model_by_category>), PurgeAction(purge_transaction_name='Purge Unused Cable Tray Symbols and Families', purge_ids_getter=<function get_unused_cable_tray_symbol_ids_for_purge>, purge_report_header='Cable Tray Symbols and Family(s)', test_report_header='Cable Tray Symbols and Family(s)', test_ids_getter=<function get_symbol_ids_for_cable_tray_types_in_model>), PurgeAction(purge_transaction_name='Purge Unused Conduit Symbols and Families', purge_ids_getter=<function get_unused_conduit_symbol_ids_for_purge>, purge_report_header='Conduit Symbols and Family(s)', test_report_header='Conduit Symbols and Family(s)', test_ids_getter=<function get_symbol_ids_for_conduit_types_in_model>), PurgeAction(purge_transaction_name='Purge Unused Duct Symbols and Families', purge_ids_getter=<function get_unused_duct_and_flex_duct_symbol_ids_for_purge>, purge_report_header='Duct Symbols and Family(s)', test_report_header='Duct Symbols and Family(s)', test_ids_getter=<function get_symbol_ids_for_duct_types_in_model>), PurgeAction(purge_transaction_name='Purge Unused Pipe Symbols and Families', purge_ids_getter=<function get_unused_pipe_symbol_ids_for_purge>, purge_report_header='Pipe Symbols and Family(s)', test_report_header='Pipe Symbols and Family(s)', test_ids_getter=<function get_symbol_ids_for_pipe_types_in_model>), PurgeAction(purge_transaction_name='Purge Unused Level Types', purge_ids_getter=<function get_unused_level_types_for_purge>, purge_report_header='Level Type(s)', test_report_header='Level Type(s)', test_ids_getter=<function get_all_level_type_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused Level Head Types', purge_ids_getter=<function get_unused_level_head_families_for_purge>, purge_report_header='Level Head family Type(s)', test_report_header='Level Head family Type(s)', test_ids_getter=<function get_all_level_head_family_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Grid Types', purge_ids_getter=<function get_unused_grid_types_for_purge>, purge_report_header='Grid Type(s)', test_report_header='Grid Type(s)', test_ids_getter=<function get_all_grid_type_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused Grid Head Types', purge_ids_getter=<function get_unused_grid_head_families_for_purge>, purge_report_header='Grid Head family Type(s)', test_report_header='Grid Head family Type(s)', test_ids_getter=<function get_all_grid_head_family_type_ids>), PurgeAction(purge_transaction_name='Purge Unused View Reference Types', purge_ids_getter=<function get_unused_view_reference_type_ids_for_purge>, purge_report_header='View Ref Type(s)', test_report_header='View Ref Type(s)', test_ids_getter=<function get_all_view_reference_type_id_data_as_list>), PurgeAction(purge_transaction_name='Purge Unused View Continuation Types', purge_ids_getter=<function get_unused_continuation_marker_type_ids_for_purge>, purge_report_header='View Continuation Type(s)', test_report_header='View Continuation Type(s)', test_ids_getter=<function get_all_view_continuation_type_ids>), PurgeAction(purge_transaction_name='Purge Unused View Reference Families', purge_ids_getter=<function get_unused_view_ref_and_continuation_marker_families_for_purge>, purge_report_header='View Ref and Continuation Marker families(s)', test_report_header='View Ref and Continuation Marker families(s)', test_ids_getter=<function get_all_view_reference_symbol_ids>), PurgeAction(purge_transaction_name='Purge Unused Repeating Details', purge_ids_getter=<function get_unused_repeating_detail_type_ids_for_purge>, purge_report_header='Repeating Detail Type(s)', test_report_header='Repeating Detail Type(s)', test_ids_getter=<function get_all_repeating_detail_type_ids_available>), PurgeAction(purge_transaction_name='Purge Unused Filled Regions', purge_ids_getter=<function get_unused_filled_region_type_ids_for_purge>, purge_report_header='Filled Region Type(s)', test_report_header='Filled Region Type(s)', test_ids_getter=<function get_all_filled_region_type_ids_available>), PurgeAction(purge_transaction_name='Purge Unused Details Symbols', purge_ids_getter=<function get_all_unused_detail_symbol_ids_for_purge>, purge_report_header='Detail Symbol(s)', test_report_header='Detail Symbol(s)', test_ids_getter=<function get_all_detail_symbol_ids_available>), PurgeAction(purge_transaction_name='Purge Unused MultiRef Dimension Types', purge_ids_getter=<function get_all_unused_multi_ref_dim_type_ids_in_model>, purge_report_header='MultiRef Dimension Type(s)', test_report_header='MultiRef Dimension Type(s)', test_ids_getter=<function get_all_multi_ref_annotation_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Dimension Types', purge_ids_getter=<function get_all_unused_dim_type_ids_in_model>, purge_report_header='Dimension Type(s)', test_report_header='Dimension Type(s)', test_ids_getter=<function get_dim_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Text Types', purge_ids_getter=<function get_all_unused_text_type_ids_in_model>, purge_report_header='Text Type(s)', test_report_header='Text Type(s)', test_ids_getter=<function get_all_text_type_ids>), PurgeAction(purge_transaction_name='Purge Unused Arrow Heads', purge_ids_getter=<function get_all_unused_arrow_type_ids_in_model>, purge_report_header='Arrow Head Type(s)', test_report_header='Arrow Head Type(s)', test_ids_getter=<function get_arrow_type_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Generic Annotation', purge_ids_getter=<function get_unused_generic_annotation_ids_for_purge>, purge_report_header='Generic Anno Type(s)', test_report_header='Generic Anno Type(s)', test_ids_getter=<function get_all_generic_annotation_type_ids_by_category>), PurgeAction(purge_transaction_name='Purge Unused SpotElevation Symbols', purge_ids_getter=<function get_unused_symbol_ids_from_spot_types_to_purge>, purge_report_header='Spot Elevation Symbol(s)', test_report_header='Spot Elevation Symbol(s)', test_ids_getter=<function get_all_spot_elevation_symbol_ids_in_model>), PurgeAction(purge_transaction_name='Purge Unused Loadable Family Types', purge_ids_getter=<function get_unused_non_shared_family_symbols_and_type_ids_to_purge>, purge_report_header='Loadable Non Shared Family Type(s)', test_report_header='Loadable Non Shared Family Type(s)', test_ids_getter=<function get_all_non_shared_family_symbol_ids>)]

list containing purge action names and the purge action method

duHast.Revit.Purge.purge_unused.SPACER = '...'

indentation for names of items purged

duHast.Revit.Purge.purge_unused.purge_unused(doc, revit_file_path, is_debug)

Calls all available purge actions defined in global list.

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

  • revit_file_path (str) – Fully qualified file path of current model document. (Not used)

  • is_debug (bool) – True: will return detailed report and attempt to try to delete elements one by one if an exception occurs. False Will attempt to delete all elements at once, less detailed purge report.

Returns:

Result class instance.

  • .status True if all purge actions completed successfully. Otherwise False.

  • .message will be listing each purge action and its status

Return type:

Result

duHast.Revit.Purge.purge_unused_by_delete module

Function to purge unused elements by delete test.

This purge approach deletes an element from the model and checks whether that deletion changed any other elements. If not, means the element is unused and can be deleted.

duHast.Revit.Purge.purge_unused_by_delete.document_change_purge_element(sender, e, doc, debug, deleted_elements_modifier, modified_elements_modifier, result)

Function to execute on DocumentChanged event and inspect the modified & deleted elements. An unused element will have 1 deleted element and 0 modified elements.

duHast.Revit.Purge.purge_unused_by_delete.pre_process_failures(failures_accessor, process_result)

Rolls back the processing if any warning is encountered

Parameters:
  • failures_accessor (FailuresAccessor) – The failures accessor to process

  • process_result (Result) – A Result class instance used to store any failure messages only

Returns:

The result of the failure processing

Return type:

FailureProcessingResult

duHast.Revit.Purge.purge_unused_by_delete.purge_unused_elements(doc, element_id_getter=None, deleted_elements_modifier=None, modified_elements_modifier=None, progress_callback=None, debug=False)

This script will ascertain elements not used in your model and delete them. It deletes the elements one by one and checks if there is modified elements which indicates another element was using the element. The transaction is rolled back if there is a modified element.

IMPORTANT: This has flushed out some corrupt families with unresolvable geometry so it is advisable to run on a detached copy of your model first and rectify any family errors

Credit for this script goes to Autodesk forum user so-chong from the below forum post https://forums.autodesk.com/t5/revit-api-forum/check-if-linepattern-is-in-use/td-p/7435014

Parameters:
  • doc (Document) – The Revit document to purge line patterns from

  • DEBUG (bool) – Whether to print debug information or not. Optional. Defaults to False

duHast.Revit.Purge.purge_unused_e_transmit module

This module contains a purge unused function using Autodesk’s own eTransmit plug in.

Based on the building coder article: https://thebuildingcoder.typepad.com/blog/2022/03/purge-unused-and-the-autodesk-camel.html

duHast.Revit.Purge.purge_unused_e_transmit.purge_unused_e_transmit(doc)

Purges the document using the purge unused functionality of the eTransmit tool provided by Autodesk.

Parameters:

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

Returns:

Result class instance.

  • Purge status returned in result.status. False if an exception occurred, purge command returned False, unsupported Revit version, otherwise True.

  • result.message will contain the purge status.

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

Module contents