Sample Code Revit Batch Processor 1.1.16 documentation

Contents:

This Page

duHast.Revit.Revisions package

Subpackages

Submodules

duHast.Revit.Revisions.new_revision module

This module contains a number of helper functions relating to creating new revit revisions.

duHast.Revit.Revisions.new_revision.new_revision_action_2022(doc, revision_data)

Creates a new revision in a revit document up to version 2022.

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

  • revision_data (revisionData) – Named tuple containing revision data

Returns:

Result class instance.

  • Revision created status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision created successfully.

  • result.result: will contain list with single entry: the new revision created

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.new_revision.new_revision_action_2023(doc, revision_data)

Creates a new revision in a revit document version 2023 and onwards.

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

  • revision_data (revisionData) – Named tuple containing revision data

Returns:

Result class instance.

  • Revision created status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision created successfully.

  • result.result: will contain list with single entry: the new revision created

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revision_schedules module

This module contains a number of helper functions relating to Revit revision schedules.

duHast.Revit.Revisions.revision_schedules.get_revision_schedule_from_sheet(doc, sheet)

Gets the revision schedule instance from a given sheet.

If no revision schedule is found, None is returned. If multiple are fopund, the first one is returned.

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

  • sheet (Autodesk.Revit.DB.ViewSheet) – Sheet to get revision schedule from.

Returns:

Revision schedule instance or None if not found.

Return type:

Autodesk.Revit.DB.ScheduleSheetInstance or None

duHast.Revit.Revisions.revisions module

This module contains a number of helper functions relating to Revit revisions.

duHast.Revit.Revisions.revisions.REVISION_DATA

alias of revisionData

duHast.Revit.Revisions.revisions.get_all_revisions(doc)

Returns all revisions in model as list of named tuples.

Parameters:

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

Returns:

list of named tuples containing revision data

Return type:

[ revisionData ]

duHast.Revit.Revisions.revisions.create_revision(doc, revision_data)

Creates a revision in the document.

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

  • revision_data (revisionData) – Named tuple containing revision data

Returns:

Result class instance.

  • Revision created status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision created successfully.

  • result.result: will contain list with single entry: the new revision created

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revisions.mark_revision_as_issued(doc, revision)

Sets a revision status to ‘Issued’.

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

  • revision (Autodesk.Revit.DB.Revision) – The revision

Returns:

Result class instance.

  • Revision status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision marked as issued successfully.

  • result.result: empty list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revisions.mark_revision_as_issued_by_revision_id(doc, revision_id)

Sets a revision, identified by its id, status to ‘Issued’.

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

  • revision_id (Autodesk.Revit.DB.ElementId) – The Id of the revision.

Returns:

Result class instance.

  • Revision marked as issued status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision marked as issued successfully.

  • result.result: empty list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revisions.add_revisions_to_sheet(doc, sheet, revision_ids)

Adds revisions to single sheet

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

  • sheet (Autodesk.Revit.DB.SheetView) – The sheet to add the revision to.

  • revision_ids ([Autodesk.Revit.ElementId]) – List of revision ids

Returns:

Result class instance.

  • Revision adding to sheet status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision added to sheet successfully.

  • result.result: empty list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revisions.get_issued_revisions(doc)

Get all issued revisions in a model.

Parameters:

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

Returns:

list of revision objects

Return type:

[Autodesk.Revit.DB.Revision]

duHast.Revit.Revisions.revisions.get_last_issued_revision(doc)

Get the last issued revision from a model.

Parameters:

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

Returns:

A revision object or None if no issued revision in the model

Return type:

Autodesk.Revit.DB.Revision or None

duHast.Revit.Revisions.revisions.change_revision_sequence_number(doc, revision, new_sequence_number)

Updates the revision sequence number of a revision.

Pop the revision from its current index in the revision sequence list. Insert it again at the new index

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

  • revision (Autodesk.Revit.DB.Revision) – the revision

  • new_sequence_number (int) – The new index (sequence number ) of the revision. 1 based!!

Returns:

Result class instance.

  • Revision re-ordering status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision re-ordered successfully.

  • result.result: new revision sequence list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

duHast.Revit.Revisions.revisions.re_order_revisions(doc, revision_sequence)

Attempts to replace the current revision sequence with the one past in.

Note: both sequences must contain the same revisions…just in a different order.

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

  • revision_sequence (IList<ElementId>) – List of revision element ids describing the new sequence.

Returns:

Result class instance.

  • Revision re-ordering status returned in result.status. False if an exception occurred, otherwise True.

  • result.message will contain the message revision re-ordered successfully.

  • result.result: new revision sequence list

On exception:

  • result.status (bool) will be False.

  • result.message will contain the exception message.

Return type:

Result

duHast.Revit.Revisions.revisions.are_revisions_by_sheet(doc)

Checks if revisions in the document are set to be ‘by sheet’. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document

Returns:

True if revisions are by sheet, False if revisions are ‘by project’.

Return type:

bool

duHast.Revit.Revisions.revisions.delete_all_revisions_in_model(doc, revision_description_filter=[])

Deletes all revision in file passing filter in one transaction.

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

  • revision_description_filter (list, optional) – list of filters, defaults to []

Returns:

Result class instance.

  • result.status. True if all possible revisions where deleted successfully, otherwise False.

  • result.message will contain the name(s) of the revisions excluded by filter and number of revisions deleted.

  • result.result empty list

On exception:

  • result.status (bool) will be False.

  • result.message will contain generic exception message.

  • result.result will be empty

Return type:

Result

duHast.Revit.Revisions.revisions_from_sheet module

This module contains helper functions for retrieving Revit revisions from sheets.

To get the complete revision history of a sheet, without using a revision schedule, use this module.

The flow is as follows:

  1. Check if revisions vary by sheet or are project-wide

  2. Get all revision IDs from the sheet using ViewSheet.GetAllRevisionIds()

  3. Loop over each revision ID and get the revision element using Document.GetElement(revisionId)

  4. For each revision: - Get the revision sequence ID using Revision.RevisionNumberingSequenceId - Determine the sequence type (Numeric, Alphanumeric, or None) - Create appropriate storage object based on sequence type:

    • Numeric: Uses prefix, suffix, start number, and minimum digits

    • Alphanumeric: Uses prefix, suffix, and predefined sequence

    • None: Uses the revision’s RevisionNumber property directly

    • Store the revision data with its index position on the sheet

  5. Build a dictionary with revision sequence ID as key and list of storage objects as values - Each storage object tracks:

    • The revision element

    • Its index on the sheet (for maintaining original order)

    • The sequence settings needed to generate the revision value

  6. Build the final revision data list by: - Iterating through sheet positions (0 to number of revisions) - Finding the matching storage object for each position - Generating the actual revision value using the storage object’s sequence counter - Pairing the revision value with its Revit element

  7. Return list of tuples: (revision_value, revision_element) in sheet order

General notes:

  • In alphanumeric mode: if the number of revisions exceeds the entries in the predefined sequence, the sequence continues with A,B,C…Z,AA,BB,CC,AAA,BBB,CCC and so on.

  • The module handles both “revisions vary by sheet” and “same revisions for all sheets” scenarios through the storage objects’ internal logic.

duHast.Revit.Revisions.revisions_from_sheet.build_revision_data(rev_dictionary, number_of_revs_on_sheet)

Builds the revision data list from the revision dictionary and number of revisions on sheet. :param rev_dictionary: The revision dictionary with sequence id as key and list of revision by sheet storage instances as value. :type rev_dictionary: dict :param number_of_revs_on_sheet: The number of revisions on the sheet. :type number_of_revs_on_sheet: int

Returns:

The list of revision data tuples (revision value, revision Revit element).

Return type:

[(str, Autodesk.Revit.DB.Revision)]

duHast.Revit.Revisions.revisions_from_sheet.get_revisions_from_sheet(doc, sheet)

Gets the revisions from a sheet.

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

  • sheet (Autodesk.Revit.DB.ViewSheet) – The Revit sheet (ViewSheet).

Returns:

The list of revision data tuples (revision value, revision Revit element).

Return type:

[(str, Autodesk.Revit.DB.Revision)]

duHast.Revit.Revisions.sequence module

This module contains a number of helper functions relating to revit revision sequences.

duHast.Revit.Revisions.sequence.get_revision_seq_of_name(doc, revision_sequence_name)

Gets a revision sequence by its name. If no match is found None is returned!

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

  • revision_sequence_name (str) – The sequence name

Returns:

The matching sequence or None

Return type:

Autodesk.Revit.DB.RevisionNumberingSequence

duHast.Revit.Revisions.sequence.create_revision_alpha_seq(doc, revision_sequence_name, alpha_settings=Autodesk.Revit.DB.AlphanumericRevisionSettings)

Creates a revision sequence with provided name and settings.

Will throw an exception if sequence creation failed.

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

  • revision_sequence_name (str) – The name of the sequence

  • alpha_settings (Autodesk.Revit.DB.AlphanumericRevisionSettings, optional) – Custom settings, defaults to rdb.AlphanumericRevisionSettings()

Returns:

The new sequence.

Return type:

Autodesk.Revit.DB.RevisionNumberingSequence

Module contents