Sample Code Revit Batch Processor 1.1.15 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

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