Sample Code Revit Batch Processor 1.1.11 documentation
Bases: Base
Class constructor.
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
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.
Purges all unplaced elements provided through a passed in element id getter method from a model.
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.
Result class instance.
.status True if all purge actions completed successfully. Otherwise False.
.message will be listing each purge action and its status
list containing purge action names and the purge action method
indentation for names of items purged
Calls all available purge actions defined in global list.
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.
Result class instance.
.status True if all purge actions completed successfully. Otherwise False.
.message will be listing each purge action and its status
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.
Function to execute on DocumentChanged event and inspect the modified & deleted elements. An unused element will have 1 deleted element and 0 modified elements.
Rolls back the processing if any warning is encountered
failures_accessor (FailuresAccessor) – The failures accessor to process
process_result (Result
) – A Result class instance used to store any failure messages only
The result of the failure processing
FailureProcessingResult
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
doc (Document) – The Revit document to purge line patterns from
DEBUG (bool) – Whether to print debug information or not. Optional. Defaults to False
Based on the building coder article: https://thebuildingcoder.typepad.com/blog/2022/03/purge-unused-and-the-autodesk-camel.html
Purges the document using the purge unused functionality of the eTransmit tool provided by Autodesk.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
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.