Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.Common package

Subpackages

Submodules

duHast.Revit.Common.common module

Common Revit API utility functions.

duHast.Revit.Common.common.get_element_mark(e)

Returns the mark value of an element.

Parameters:

e (Autodesk.Revit.DB.Element) – The element.

Returns:

The element mark value. If an exception occurred, the message will be ‘Failed with exception: ‘ + the exception string.

Return type:

str

duHast.Revit.Common.common.element_ids_to_semicolon_delimited_text(element_ids)

Convert a list of ElementIds to a semicolon delimited string

Parameters:

element_ids (List[ElementId]) – List of ElementIds

Returns:

Semicolon delimited string of ElementIds

Return type:

str

duHast.Revit.Common.common.get_legend_components_in_model(doc, type_ids)

Returns all symbol (type) ids of families which have been placed as legend components and have match in list past in.

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

  • type_ids (list str) – List of typeIds to check against.

Raise:

Any exception will need to be managed by the function caller.

Returns:

Values are representing symbol (type) ids of legend components in models filtered by ids past in.

Return type:

list of str

duHast.Revit.Common.common.get_similar_type_families_by_type(doc, type_getter)

Returns a list of unique types its similar family (symbol) types.

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

  • type_getter (function) – The function which takes the document as an argument and returns a list of family symbols (types).

Raise:

Any exception will need to be managed by the function caller.

Returns:

list of Autodesk.Revit.DB.Symbol and Autodesk.Revit.DB.ElementId:

Return type:

List [[Autodesk.Revit.DB.ElementType, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,…],]

duHast.Revit.Common.common.check_unique_type_data(existing_types, new_type_data)

Compares two lists of types and their similar types (ids).

Assumes that second list past in has only one occurrence of type and its similar types Compares types by name and if match their similar types.

Parameters:
  • existing_types (List of List in format [[Autodesk.Revit.DB.ElementType , Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,...],]) – Source list

  • new_type_data (List in format [Autodesk.Revit.DB.ElementType, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,...]) – Comparison list

Returns:

True, if new type is not in list existing Types passed in or if ids of similar family types do not match any similar types already in list

Return type:

bool

duHast.Revit.Common.common.get_unused_type_ids_in_model(doc, type_getter, instance_getter)

Returns ID of unused family types in the model.

Used in purge code since it leaves at least one type behind (built in families require at least one type in the model)

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

  • type_getter (func) – Function accepting current document as argument and returning a collector of types in model

  • instance_getter (func) – Function accepting current document as argument and returning a list of instances in model

Returns:

List of type ids which can be purged from the model.

Return type:

list Autodesk.Revit.DB.ElementId

duHast.Revit.Common.common.get_not_placed_types(doc, get_types, get_instances)

returns a list of unused types foo by comparing type Ids of placed instances with types past in.

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

  • get_types (func (doc)) – Types getter function. Needs to accept doc as argument and return a collector of type foo

  • get_instances (func(doc)) – Instances getter function. Needs to accept doc as argument and return a collector of instances foo

Returns:

returns a list of unused types

Return type:

list of type foo

duHast.Revit.Common.common.check_group_for_type_ids(doc, group_type, type_ids)

Filters passed in list of type ids by type ids found in group and returns list of unmatched Id’s

This only returns valid data if at least one instance of the group is placed in the model, otherwise GetMemberIds() returns empty!!

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

  • group_type (Autodesk.Revit.DB.GroupType) – Group to be checked whether they contains elements of types past in.

  • type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group

Returns:

Returns all type ids not matched

Return type:

list of Autodesk.Revit.Db.ElementId

duHast.Revit.Common.common.check_groups_for_matching_type_ids(doc, group_types, type_ids)

Checks all elements in groups past in whether group includes element of which type Id is matching any type ids past in

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

  • group_types (list of Autodesk.Revit.DB.GroupType) – Groups to be checked whether they contains elements of types past in.

  • type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group

Returns:

Returns all type ids not matched

Return type:

list of Autodesk.Revit.Db.ElementId

duHast.Revit.Common.common.get_unused_type_ids_from_detail_groups(doc, type_ids)

Checks elements in nested detail groups and detail groups whether their type ElementId is in the list past in.

This only returns valid data if at least one instance of the group is placed in the model!!!

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

  • type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group

Returns:

Returns all type Ids from list past in not found in group definitions

Return type:

list of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.common.get_ids_from_element_collector(col)

This will return a list of all element ids in collector.

Any element in collector which is invalid will be ignored.

Parameters:

col (Autodesk.Revit.DB.FilteredElementCollector) – A filtered element collector.

Returns:

list of all element ids of valid elements in collector.

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.custom_element_filter module

Customizable element filter class.

This class takes as constructor arguments

  • a number of filter actions

  • a boolean indicating whether filters are logical and or OR filters

Filter actions checks whether a property matches or does not match provided values. Refer to module: custom_element_filter_actions. The actual property test is undertaken by another function. Samples of those can be found in module custom_element_filter_tests.

class duHast.Revit.Common.custom_element_filter.RevitCustomElementFilter(element_filters=[], is_logical_and_filter=True, **kwargs)

Bases: Base

Constructor: This takes a list of element filters and a flag whether this class instance is a logical AND filter (default)

Parameters:
  • element_filters (list of functions, optional) – List of element filter functions which will need to accept document and elementId as their arguments, defaults to []

  • is_logical_and_filter (bool, optional) – Flag indicating whether list of filters are logical AND filters or logical OR, defaults to True (logical AND)

check_element(doc, element_id)

Filter checking whether element meets criteria.

This function will loop over all the filters past in through the class constructor and test the element for each filter. Depending on whether these filters are logical and filters it will return True if all of them evaluate to True or, if logical or filter it will return True if one of them evaluates to True, otherwise False will be returned.

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

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be checked against the filter.

Returns:

True if it matches the filter(s), otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_actions module

Customizable element filter actions which can be used with the custom element filter class.

Thw two action in this module check whether:

  • a given property does contain / match a set of test value

  • a given property does not contain / match a set of test value

actions expect:

  • the test to be performed

  • the test values to be performed against

  • an output function to pipe any exception message to

duHast.Revit.Common.custom_element_filter_actions.action_element_property_contains_any_of_values(test_values, test, output)

Set up a function checking whether element name contains any of the test values.

Note: If element names does contain any of the test values, the function will return True, Otherwise False.

Parameters:
  • values ([str]) – List of values the element name may contain.

  • output (func(message)) – A function piping the string output to a required location.(console…)

duHast.Revit.Common.custom_element_filter_actions.action_element_property_does_not_contains_any_of_values(test_values, test, output)

Set up a function checking whether element name does not contains any of the test values.

Note: If element names does contain any of the test values, the function will return False, Otherwise True.

Parameters:
  • values ([str]) – List of values the element name may not contain.

  • output (func(message)) – A function piping the string output to a required location.(console…)

duHast.Revit.Common.custom_element_filter_tests module

Customizable element filter tests which can be used with the custom element filter actions.

These tests are used in the custom element filter actions as an argument.

test expects:

  • the element of which is the test to be performed against

  • the test value

duHast.Revit.Common.custom_element_filter_tests.value_in_name(value, element)

Check if provided value is in the element name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if part of the element name, otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_tests.value_equals_workset_name(value, element)

Check if provided value is equal to the elements workset name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if elements workset name matches, otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_tests.value_in_family_name(value, element)

Check if provided value is part of the elements Family name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if elements family name partly matches, otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_tests.value_in_element_type_family_name(value, element)

Check if provided value is part of the element type Family name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if elements family name partly matches, otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_tests.value_is_family_name(value, element)

Check if provided value is equal to the elements Family name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if elements family name matches, otherwise False

Return type:

bool

duHast.Revit.Common.custom_element_filter_tests.value_is_element_type_family_name(value, element)

Check if provided value is equal to the element type Family name.

Parameters:
  • value (str) – test value

  • element (Autodesk.Revit.DB.Element) – The element

Returns:

True if elements family name matches, otherwise False

Return type:

bool

duHast.Revit.Common.delete module

Delete elements from model.

duHast.Revit.Common.delete.delete_by_element_ids(doc, ids, transaction_name, element_name)

Deletes elements in a list all at once.

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

  • ids (list of Autodesk.Revit.DB.ElementId) – List containing IDs of all elements to be deleted.

  • transaction_name (str) – The transaction name used for the deletion.

  • element_name (str) – The element name added to the deletion status message.

Returns:

Result class instance. - result (bool): True if all elements were successfully deleted, otherwise False. - message (str): Deletion status.

Return type:

Result

duHast.Revit.Common.delete.delete_by_element_ids_one_by_one(doc, ids, transaction_name, element_name)

Deletes elements in a list one at a time.

Each element is deleted in its own transaction. If the deletion fails, the transaction is rolled back.

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

  • ids (list of Autodesk.Revit.DB.ElementId) – List containing IDs of all elements to be deleted.

  • transaction_name (str) – The transaction name used for the deletion.

  • element_name (str) – The name of the element (not used).

Returns:

Result class instance. - result (bool): True if all elements were successfully deleted, otherwise False. - message (str): Contains each ID and its deletion status.

Return type:

Result

duHast.Revit.Common.design_set_options module

This module contains a number of functions around Revit Design Sets and Design Options.

duHast.Revit.Common.design_set_options.REPORT_DESIGNSET_HEADER = ['HOSTFILE', 'ID', 'NAME', 'PRIMARY OPTION', 'OTHER OPTIONS']

header used in reports

duHast.Revit.Common.design_set_options.get_design_options(doc)

Gets all design options in a model,

Parameters:

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

Returns:

Design options in current model

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Common.design_set_options.get_active_design_option(doc)

Get the active design option in a model.

Parameters:

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

Returns:

Active design option in current model, or if no design option is active, None

Return type:

Autodesk.Revit.DB.DesignOption

duHast.Revit.Common.design_set_options.get_design_set_from_option(doc, design_option)

Returns the design set of the design option.

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

  • design_option (Autodesk.Revit.DB.DesignOption) – a revit design option

Returns:

A revit design set or None if no design option is active

Return type:

_type_

duHast.Revit.Common.design_set_options.get_design_set_of_active_design_option(doc)

Returns the design set of the current active design option.

Parameters:

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

Returns:

A revit design set or None if no design option is active

Return type:

_type_

duHast.Revit.Common.design_set_options.get_design_sets(doc)

Gets all the design sets in a model,

Parameters:

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

Returns:

Design sets in the current model

Return type:

list of Autodesk.Revit.DB.Element

duHast.Revit.Common.design_set_options.get_design_options_by_design_set(doc)

Gets all the design options grouped by design sets in a model,

Parameters:

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

Returns:

A dictionary where key is the Design sets name and value is a list of design options in that set

Return type:

{str:[Autodesk.Revit.DB.Element]}

duHast.Revit.Common.design_set_options.is_design_option_primary(doc, design_set_name, design_option_name)

Checks whether a design option is the primary option within a design set.

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

  • design_set_name (str) – The name of the design set the option belongs to,

  • design_option_name (str) – The name of the design option to be checked,

Returns:

True if this option is primary otherwise False

Return type:

bool

duHast.Revit.Common.design_set_options.get_design_set_option_info(doc, element)

Get the design set, design option information of an element.

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

  • element (Autodesk.Revit.DB.Element) – The element of which the design set/option data is to be returned.

Returns:

Dictionary ( for keys refer to DesignSetPropertyNames ) DesignSetName: (can be either Main Model or the design set name) designOptionName: Design Option Name (empty string if Main Model isPrimary: Indicating whether design option is primary (true also if Main Model)

Return type:

Dictionary designSetName:str designOptionName:str isPrimary:bool

duHast.Revit.Common.design_set_options.get_design_option_ids_of_all_primary_options(doc)

Get the design option ids of all primary options in a model.

Parameters:

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

Returns:

List of design option ids of all primary options in the model.

Return type:

list of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.design_set_options.get_design_option_ids_of_all_primary_options_but_the_one_containing_filter_id(doc, filter_Id)

Get the design option ids of all primary options in a model except the one where the design set contains a design option with the filter id.

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

  • filter_Id (Autodesk.Revit.DB.ElementId) – Element Id of the filter.

Returns:

List of design option ids of all primary options in the model except the one containing the filter id.

Return type:

list of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.element_filtering module

Varies Element filter / check functions.

duHast.Revit.Common.element_filtering.is_element_of_built_in_category(doc, element_id, builtin_categories)

Checks whether an element is of the built in categories past in. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param element_id: The id of the element to be tested. :type element_id: Autodesk.Revit.DB.ElementId :param builtin_categories: The builtin category the element does needs to match. :type builtin_categories: Autodesk.Revit.DB.Definition :return: True if element’s builtin category does equals the test category, otherwise False. :rtype: bool

duHast.Revit.Common.element_filtering.is_element_not_of_built_in_category(doc, element_id, builtin_categories)

Checks whether an element is not of the built in categories past in. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param element_id: The id of the element to be tested. :type element_id: Autodesk.Revit.DB.ElementId :param builtin_categories: The builtin category the element does not needs to match. :type builtin_categories: Autodesk.Revit.DB.Definition :return: True if element’s builtin category does not equals the test category, otherwise False. :rtype: bool

duHast.Revit.Common.element_filtering.is_family_name_from_instance(doc, family_name, element_id)

Checks whether the family name of a given family instance matches filter value.

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

  • family_name (str) – The string the name of the family needs to match.

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.

Returns:

True if family equals the test string, otherwise False.

Return type:

bool

duHast.Revit.Common.element_filtering.is_family_name_from_instance_contains(doc, contains_value: str, element_id) bool

Checks whether the family name of a given family instance contains filter value.

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

  • contains_value (str) – The string the name of the family instance is to be tested for.

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.

Returns:

True if family name does contain the test string, otherwise False.

Return type:

bool

duHast.Revit.Common.element_filtering.is_family_name_from_instance_does_not_contains(doc, contains_value: str, element_id) bool

Checks whether the family name of a given family instance does not contains filter value.

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

  • contains_value (str) – The string the name of the family instance is to be tested for.

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.

Returns:

True if family name does not contain the test string, otherwise False.

Return type:

bool

duHast.Revit.Common.element_filtering.is_symbol_name_from_instance_contains(doc, contains_value: str, element_id) bool

Checks whether the family symbol name of a given family instance contains filter value.

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

  • contains_value (str) – The string the name of the family instance is to be tested for.

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.

Returns:

: True if family name does contain the test string, otherwise False.

Return type:

bool

duHast.Revit.Common.element_filtering.is_symbol_name_from_instance_does_not_contains(doc, contains_value: str, element_id) bool

Checks whether the family symbol name of a given family instance does not contains filter value.

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

  • contains_value (string) – The string the name of the family is to be tested for.

  • element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.

Returns:

True if symbol name does not contain the test string, otherwise False.

Return type:

bool

duHast.Revit.Common.element_filtering_by_design_option module

Element filter by design option id’s

duHast.Revit.Common.element_filtering_by_design_option.filter_elements_by_design_option_id(doc, elements, design_option_id, include_main_model=True, include_other_primary=True)

Filter room separation lines by design option id.

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

  • elements ([]) – A list of Revit elements

  • design_option_id (Autodesk.Revit.ElementId) – The id of the design option to be filtered by. None will return either all room separation lines from the main model, if include main model is true, and / or all room separation lines from other primary design options.

  • include_main_model (bool) – Include room separation lines from the main model option.

  • include_other_primary (bool) – Include room separation lines from other primary design options in the model.

Returns:

A list of room separation lines filtered by design option id.

Return type:

list

duHast.Revit.Common.failure_handling module

A number of helper functions regarding advanced failure handling

Helps to suppress warning dialogues in Revit.

duHast.Revit.Common.failure_handling.get_failure_warning_report(failure, failure_definition)

Creates a string representation of the information attached to a failure

Parameters:
  • failure (FailureMessage) – The failure to report

  • failure_definition (FailureDefinition) – The failure definition

Returns:

The string representation of the failure information

Return type:

str

duHast.Revit.Common.failure_handling.process_failures(failures_accessor, fail_config)

Process the failures encountered when transacting with a Revit document

Parameters:

failures_accessor (FailuresAccessor) – The failures accessor to process

Returns:

The result of the failure processing

Return type:

FailureProcessingResult

duHast.Revit.Common.failure_handling.FailuresProcessingEventHandler(sender, args, fail_config)

Function to execute when Revit raises the FailuresProcessing event

duHast.Revit.Common.failure_handling.with_failures_processing_handler(app, action, fail_config=FailureHandlingConfig(roll_back_on_warning=False, print_warnings=False, roll_back_on_error=False, print_errors=False, allowable_failures=None, set_forced_modal_handling=True, set_clear_after_rollback=True, output_function=<function output>))

Executes an action with Revit failure processing enabled by adding a handler to the FailuresProcessing event. This function will need to be wrapped in a transaction.

Parameters:
  • app (Application) – The Revit application to execute the action with

  • action (function) – The action to perform

Returns:

The result of the action

Return type:

object

duHast.Revit.Common.file_io module

Revit file operations utility functions.

duHast.Revit.Common.file_io.sync_file(doc, compact_central_file: bool = False) Result

Synchronizes a Revit central file.

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

  • compact_central_file (bool, optional) – option to compact the central file, defaults to False

Returns:

Result class instance. - .status True if successfully synced file. Otherwise False.

Return type:

Result

duHast.Revit.Common.file_io.saves_as_workshared_file(doc, full_file_name: str) Result

Saves a Revit project file as a workshared file. Save as options are: Workset configuration is : Ask users on open to specify. Any existing file will be overwritten. Number of backups is 5 File will bew compacted on save.

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

  • full_file_name (string) – The fully qualified file path of where to save the file.

Returns:

Result class instance. - .status True if successfully saved file, otherwise False.

Return type:

Result

duHast.Revit.Common.file_io.save_as_family(doc, target_directory_path, current_full_file_name, name_data, file_extension='.rfa', compact_file=False)

Saves a family file under new name in given location.

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

  • target_directory_path (str) – The directory path of where to save the file.

  • current_full_file_name (str) – The current (old) name of the file.

  • name_data (List of string arrays in format[[oldname, newName]]) – Old name and new name are Revit file names without file extension. Used to rename the family on save from old name to new name.

  • file_extension (str, optional) – The file extension used for the new file, defaults to ‘.rfa’

  • compact_file (bool, optional) – Flag whether family is to be compacted on save, defaults to False

Returns:

Result class instance.
  • .status True if successfully saved file, otherwise False.

Return type:

Result

duHast.Revit.Common.file_io.save_as(doc, target_directory_path, current_full_file_name, name_data, file_extension='.rvt')

Saves a project file under new name in given location.

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

  • target_directory_path (str) – The directory path of where to save the file.

  • current_full_file_name (str) – The current (old) name of the file.

  • name_data (List of string arrays in format[[oldname, newName]]) – Old name and new name are revit file names without file extension. Used to rename the model on save from old name to new name.

  • file_extension (str, optional) – The file extension used for the new file, defaults to ‘.rvt’

Returns:

Result class instance. - .status True if successfully saved file, otherwise False.

Return type:

Result

duHast.Revit.Common.file_io.save_file(doc, compact_file: bool = False) Result

Saves a non workshared Revit file. To be used for families and non workshared revit files only.

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

  • compact_file (bool, optional) – True file will be compacted on save, defaults to False

Returns:

Result class instance. - .status True if file was saved successfully. Otherwise False. - .message = ‘Saved revit file!’ On exception: - result.status (bool) will be False. - result.message will contain exception message.

Return type:

Result

duHast.Revit.Common.file_io.enable_worksharing(doc, workset_name_grid_level: str = 'Shared Levels and Grids', workset_name: str = 'Workset1') Result

Enables worksharing in a non workshared revit project file. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param workset_name_grid_level: _description_, defaults to ‘Shared Levels and Grids’ :type workset_name_grid_level: str, optional :param workset_name: _description_, defaults to ‘Workset1’ :type workset_name: str, optional

Returns:

Result class instance. - .status True if worksharing was enabled successfully. Otherwise False. - .message = ‘Successfully enabled worksharing.’ On exception: - result.status (bool) will be False. - result.message will contain exception message.

Return type:

Result

duHast.Revit.Common.groups module

Revit groups helper functions.

duHast.Revit.Common.groups.get_model_groups(doc)

Get all model group types from the model.

Parameters:

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

Returns:

list of model group types in the model

Return type:

list of Autodesk.Revit.DB.

duHast.Revit.Common.groups.get_model_group_instances(doc)

Get all model group instances in the model.

Parameters:

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

Returns:

collector of model group instances

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Common.groups.get_model_group_instances_by_type(doc)

Get all model group instances in the model grouped by their type id.

Parameters:

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

Returns:

Dictionary of model group instances by type id

Return type:

{ElementId:[Autodesk.Revit.DB.Group]}

duHast.Revit.Common.groups.get_model_group_instances_by_names(doc, group_names)

Get all elements from group instances in the model. : param doc: The Revit document. :type doc: Document :param group_names: The names of the groups to get elements from. :type group_names: list[str] :return: A list of group instances. :rtype: list[Autodesk.Revit.DB.Group]

duHast.Revit.Common.groups.get_detail_groups(doc)

Gets all detail groups in the model.

Parameters:

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

Returns:

A list containing detail group types.

Return type:

list

duHast.Revit.Common.groups.get_nested_detail_groups(doc)

Gets all nested detail groups in the model.

Parameters:

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

Returns:

A list containing nested detail group types.

Return type:

list

duHast.Revit.Common.groups.get_model_group_ids(doc)

Gets a list of all model group type ids in the model.

Parameters:

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

Returns:

List of model group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_detail_group_ids(doc)

Gets a list of all detail group types from the model.

This will not include any attached detail groups.

Parameters:

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

Returns:

List of detail group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_nested_detail_group_ids(doc)

Gets a list of all nested detail group types from the model.

Parameters:

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

Returns:

List of nested detail group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_unplaced_groups(doc, group_category)

Gets a list of unplaced groups from the model.

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

  • group_category (either BuiltInCategory.OST_IOSDetailGroups or BuiltInCategory.OST_IOSModelGroups) – A built in category defining the group category (model vs detail)

Returns:

List of unplaced group types

Return type:

list

duHast.Revit.Common.groups.get_unplaced_detail_groups(doc)

Gets a list of unplaced detail groups from the model

This will not include any attached detail groups.

Parameters:

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

Returns:

List of unplaced detail group types

Return type:

list

duHast.Revit.Common.groups.get_unplaced_detail_group_ids(doc)

Gets a list of unplaced detail groups type Ids from the model.

This will not include any attached detail groups.

Parameters:

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

Returns:

List of unplaced detail group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_unplaced_nested_detail_groups(doc)

Gets a list of unplaced nested detail groups from the model.

Parameters:

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

Returns:

List of unplaced nested detail group types

Return type:

list

duHast.Revit.Common.groups.get_unplaced_nested_detail_group_ids(doc)

Gets a list of unplaced nested detail group Ids from the model.

This will not list any none nested detail groups.

Parameters:

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

Returns:

List of unplaced model group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_unplaced_model_groups(doc)

Gets a list of unplaced model groups types from the model.

Parameters:

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

Returns:

List of unplaced model group types

Return type:

list

duHast.Revit.Common.groups.get_unplaced_model_group_ids(doc)

Gets a list of unplaced model group type Ids from the model.

Parameters:

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

Returns:

List of unplaced model group type ids

Return type:

List of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.groups.get_group_elements(doc, group)

Get all elements from group.

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

  • group (Autodesk.Revit.DB.Group) – The group to get elements from.

Returns:

A list of elements.

Return type:

list[Autodesk.Revit.DB.Element]

duHast.Revit.Common.parameter_get_utils module

Revit API utility functions to get parameter values.

duHast.Revit.Common.parameter_get_utils.has_property(obj, property_name)

Reflection to work out whether a property on a .net object exists (in case it has been removed)

Parameters:
  • obj (var) – A .net object

  • property_name (str) – The property name to check for

Returns:

None if the property does not exist

Return type:

_type_

duHast.Revit.Common.parameter_get_utils.check_parameter_value(para, para_condition: Callable[[str, str], bool], condition_value) bool

Checks a parameter value based on passed in condition function.

This extracts the value of the past in parameter and compares it against a past in value using the also past in compare function. Note that values will be past into compare function as ASCII encoded.

Parameters:
  • para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be checked.

  • para_condition (function) – Function taking 2 arguments: First argument is the value to be checked against Second argument is the actual parameter value Needs to return a bool! Both arguments will be ASCII encoded at passing in.

  • condition_value (var) – The value to be checked for

Raise:

Any exception will need to be managed by the function caller.

Returns:

True if condition value is evaluated to be True by past in function paraCondition. Will return False if compare function returns None or a False.

Return type:

bool

duHast.Revit.Common.parameter_get_utils.getter_none(para)

Used for parameters where the storage type is None

Parameters:

para (_type_) – _description_

duHast.Revit.Common.parameter_get_utils.getter_double_or_int_as_string(para)

Returns a parameter value of type double or integer as string.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

String representation of double or integer value. If value is empty it will return None

Return type:

str or None

duHast.Revit.Common.parameter_get_utils.getter_double_as_double(para)

Returns a parameter value of type double as a double.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

Double value. If value is empty it will return None

Return type:

Double or None

duHast.Revit.Common.parameter_get_utils.getter_double_as_double_converted_to_metric(para)

Returns a parameter value of type double to metric if required. Revit uses feet internally for any length value. Revit uses square feet for areas

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

Double value. If value is empty it will return None

Return type:

Double or None

duHast.Revit.Common.parameter_get_utils.getter_int_as_int(para)

Returns a parameter value of type integer as a integer.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

Integer value. If value is empty it will return None

Return type:

Integer or None

duHast.Revit.Common.parameter_get_utils.getter_string_as_UTF8_string(para)

Returns a parameter value of type string as a utf-8 formatted string.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

String value. If value is empty it will return None

Return type:

String or None

duHast.Revit.Common.parameter_get_utils.getter_string_as_string(para)

Returns a parameter value of type string as a string.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

String value. If value is empty it will return None

Return type:

String or None

duHast.Revit.Common.parameter_get_utils.getter_element_id_as_string(para)

Returns a parameter value of type element id as a string.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

String value. If value is empty it will return None

Return type:

String or None

duHast.Revit.Common.parameter_get_utils.getter_element_id_as_element_id(para)

Returns a parameter value of type element id as a element id.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

Element id value. If value is empty it will return None

Return type:

Element id or None

duHast.Revit.Common.parameter_get_utils.getter_element_id_as_element_int(para)

Returns a parameter value of type element id as an integer.

Parameters:

para (Autodesk.Revit.DB.Parameter) – The parameter.

Returns:

Integer value. If value is empty it will return None

Return type:

Integer or None

duHast.Revit.Common.parameter_get_utils.get_parameter_value_with_over_load(para, parameter_value_getters)

Returns a parameter value in format depending on storage type.

Storage type can be:

  • Double

  • Integer

  • String

  • ElementId

Will throw an exception if a storage type is not covered by parameter value getter functions.

Parameters:
  • para (Autodesk.Revit.DB.Parameter) – The Parameter.

  • parameter_value_getters ({Autodesk.Revit.DB.StorageType: func()}) – Dictionary containing the functions returning the parameter value depending on parameter storage type

Returns:

The parameter value or if empty: None.

Return type:

Depends on value getters functions

duHast.Revit.Common.parameter_get_utils.get_parameter_value(para) str

Returns a parameter value as string independent of its storage type.

Parameters:

para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.

Raise:

If an exception occurs the exception message will be returned as the parameter value prefixed with ‘Exception: ‘

Returns:

Default value is ‘no Value’ if parameter value is empty. Otherwise the actual parameter value. Will return ‘Exception: ‘ + exception message if an exception occurred.

Return type:

str

duHast.Revit.Common.parameter_get_utils.get_parameter_value_utf8_string(para) str

Returns the parameter value as utf-8 string independent of its storage type.

Parameters:

para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.

Raise:

If an exception occurs the exception message will be returned as the parameter value prefixed with ‘Exception: ‘

Returns:

Default value is ‘no Value’ if parameter value is empty. Otherwise the actual parameter value. Will return ‘Exception: ‘ + exception message if an exception occurred.

Return type:

str

duHast.Revit.Common.parameter_get_utils.get_parameter_value_as_integer(para) int

Returns the parameter value as integer only if the storage type is integer. Otherwise -1 will be returned.

Parameters:

para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.

Raise:

Any exception will need to be managed by the function caller.

Returns:

Default value is -1 if parameter value is empty or storage type is not integer. Otherwise the actual parameter value.

Return type:

int

duHast.Revit.Common.parameter_get_utils.get_parameter_value_as_element_id(para)

Returns the parameter value as element Id only if the storage type is ElementId. Otherwise InvalidElementId (-1) will be returned.

Parameters:

para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.

Raise:

Any exception will need to be managed by the function caller.

Returns:

Default value is -1 if parameter value is empty or storage type is not integer. Otherwise the actual parameter value.

Return type:

int

duHast.Revit.Common.parameter_get_utils.get_all_parameters_and_values_wit_custom_getters(element, parameter_value_getters)

Returns all parameters and their values as using custom value getter associated with provided element in form of a dictionary.

Parameters:
  • element (var) – The element

  • parameter_value_getters ({Autodesk.Revit.DB.StorageType: func()}) – Dictionary containing the functions returning the parameter value depending on parameter storage type

Returns:

Dictionary where key is the parameter name, and the value is the parameter value.

Return type:

{str:var}

duHast.Revit.Common.parameter_get_utils.get_built_in_parameter_value(element, built_in_parameter_def, parameter_value_getter=<function get_parameter_value_utf8_string>)

Returns the built-in parameter value. Return value type depends on past in value getter function. Default is UTF-8 encoded string.

Parameters:
  • element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.

  • built_in_parameter_def (Autodesk.Revit.DB.Definition) – The parameters built-in definition of which the value is to be returned.

  • parameter_value_getter (function) – The function which takes the parameter as an argument and returns it’s value.

Raise:

As per value getter method.

Returns:

Default value is None if parameter does not exist on element. Otherwise the actual parameter value as per value getter method.

Return type:

var

duHast.Revit.Common.parameter_get_utils.get_parameter_value_by_name(element, parameter_name, parameter_value_getter=<function get_parameter_value_utf8_string>)

Returns the parameter value by parameter name.

Return value type depends on past in value getter function. Default is UTF-8 encoded string.

Parameters:
  • element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.

  • parameter_name (str) – The parameters name of which the value is to be returned.

  • parameter_value_getter (function) – The function which takes the parameter as an argument and returns it’s value.

Raise:

As per value getter method.

Returns:

Default value is None if parameter does not exist on element. Otherwise the actual parameter value as per value getter method.

Return type:

var

duHast.Revit.Common.parameter_get_utils.param_is_empty_or_null(param)

Checks if a parameter is empty or null :param param: The parameter to check :type param: Parameter :return: True if the parameter is empty or null, False if it is not :rtype: bool

duHast.Revit.Common.parameter_grouping module

built in parameter grouping to human readable names.

duHast.Revit.Common.parameter_set_utils module

Revit API utility functions to set parameter values.

duHast.Revit.Common.parameter_set_utils.set_parameter_value(para, value_as_string, doc, in_transaction=<function in_transaction>)

Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.

Changing a parameter value requires this action to run inside a transaction.

Parameters:
  • para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be set.

  • value_as_string (str) – The new parameter value.

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

  • in_transaction (func(Autodesk.Revit.DB.Transaction, action(), Autodesk.Revit.DB.Document)) – The transaction wrapper function to be used.

Raise:

Any exception will need to be managed by the function caller.

ToDo: This needs updating for Revit 2022+ to take into account changes in Revit API: Forge Parameters

Returns:

Result class instance.

  • Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.

  • Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.

On exception:

  • Set parameter.status (bool) will be False.

  • Set parameter.message will contain the exception message.

Return type:

Result

duHast.Revit.Common.parameter_set_utils.set_built_in_parameter_value(doc, element, built_in_parameter_def, value_as_string, parameter_value_setter=<function set_parameter_value>)

Sets the built-in parameter value by trying to convert the past in string representing the value into the appropriate value type.

Changing a parameter value requires this action to run inside a transaction.

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

  • element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.

  • built_in_parameter_def (Autodesk.Revit.DB.Definition) – The parameters built-in definition of which the value is to be returned.

  • value_as_string (str) – The new parameter value.

  • parameter_value_setter (function) – The function which takes the parameter as an argument and changes it’s value to. The function needs to accept these args: parameter, new parameter value as string, document

Raise:

As per value setter method.

ToDo: This needs updating for Revit 2022+ to take into account changes in Revit API: Forge Parameters

Returns:

Result class instance.

  • Set parameter status (bool) returned in result.status. False if an exception occurred, or parameter does not exist on element, otherwise True.

  • Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.

On exception:

  • Set parameter.status (bool) will be False.

  • Set parameter.message will contain the exception message.

Return type:

Result

duHast.Revit.Common.parameter_set_utils.set_parameter_value_simple(para, value_as_string)

Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.

Changing a parameter value requires this action to run inside a transaction.

Parameters:
  • para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be set.

  • value_as_string (str) – The new parameter value.

Raise:

Any exception will need to be managed by the function caller.

Returns:

Result class instance.

  • Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.

  • Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.

On exception:

  • Set parameter.status (bool) will be False.

  • Set parameter.message will contain the exception message.

Return type:

Result

duHast.Revit.Common.parameter_set_utils.set_parameter_without_transaction_wrapper_by_name(element, parameter_name, parameter_value)

Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.

Changing a parameter value requires this action to run inside a transaction.

Parameters:
  • element (Autodesk.Revit.DB.Element) – Element of which the parameter value is to be set.

  • parameter_name (str) – The name of the parameter of which the value is to be set.

  • parameter_value (any) – The new parameter value.

Returns:

Result class instance.

  • Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.

  • Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.

On exception:

  • Set parameter.status (bool) will be False.

  • Set parameter.message will contain the exception message.

duHast.Revit.Common.parameter_set_utils.set_builtin_parameter_without_transaction_wrapper_by_name(element, parameter_definition, parameter_value)

Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.

Changing a parameter value requires this action to run inside a transaction.

Parameters:
  • element (Autodesk.Revit.DB.Element) – Element of which the parameter value is to be set.

  • parameter_definition (Autodesk.Revit.DB.BuiltInParameter) – The parameter definition of which the value is to be set.

  • parameter_value (any) – The new parameter value.

Returns:

Result class instance.

  • Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.

  • Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.

On exception:

  • Set parameter.status (bool) will be False.

  • Set parameter.message will contain the exception message.

duHast.Revit.Common.phases module

Model phase functions.

duHast.Revit.Common.phases.get_all_phases(doc)

Returns a dictionary where key is the id and value is the name of the phase.

Parameters:

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

Returns:

A dictionary where key is the id and value is the name of the phase. Dictionary will be empty if no phases exist (family doc?)

Return type:

dic{key Autodesk.Revit.DB.ElementId: value str}

duHast.Revit.Common.phases.get_all_phases_in_order(doc)

Returns all phases in the order of oldest to newest.

Parameters:

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

Returns:

A list of tuples ordered oldest to newest. Tuple properties are: 0 is the phase id and 1 is the phase name.

Return type:

[(ElementId, str)]

duHast.Revit.Common.phases.get_phase_name_by_id(doc, phase_id)

Returns the name of a phase by Id

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

  • phase_id (Autodesk.Revit.DB.ElementId) – The phase element id.

Returns:

Name of the phase, otherwise ‘No phase in document’ if no phase exists or ‘Invalid phase id.’ if no phase matching the id was found.

Return type:

str

duHast.Revit.Common.phases.get_name_to_phase_dict(rvt_doc)

Returns a dictionary where key is the name and value is the phase.

Parameters:

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

Returns:

A dictionary where key is the name and value is the phase. Dictionary will be empty if no phases exist (family doc?)

Return type:

dic{key str: value Autodesk.Revit.DB.Phase}

duHast.Revit.Common.phases.get_phase_id_created(element)

Returns the id of the phase an element was created in.

Parameters:

element (Autodesk.Revit.DB.Element) – A Revit element

Returns:

Phase id

Return type:

Autodesk.Revit.DB.ElementId

duHast.Revit.Common.phases.get_phase_id_demolished(element)

Returns the id of the phase an element was demolished in.

Parameters:

element (Autodesk.Revit.DB.Element) – A Revit element

Returns:

Phase id

Return type:

Autodesk.Revit.DB.ElementId

duHast.Revit.Common.purge_utils module

Revit purge utility functions.

duHast.Revit.Common.purge_utils.build_category_dictionary(doc, element_ids)

Builds a dictionary from elementId s past in. Dictionary key is the element category and values are all the elements of that category. If no category can be found the key ‘invalid category’ will be used.

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

  • element_ids (list of AutoDesk.Revit.DB.ElementId) – List of element id of which to build the dictionary from.

Returns:

Dictionary key is the element category and values are all the elements of that category.

Return type:

dictionary, key is string, value is list of AutoDesk.Revit.DB.Element

duHast.Revit.Common.purge_utils.check_whether_dependent_elements_are_multiple_orphaned_legend_components(doc, element_ids)

Check if element are orphaned legend components

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

  • element_ids (list of AutoDesk.Revit.DB.ElementId) – List of elements to check

Returns:

True if all but one element are orphaned legend components.

Return type:

bool

duHast.Revit.Common.purge_utils.filter_out_warnings(doc, dependent_elements)

Attempts to filter out any warnings from ids supplied by checking the workset name of each element for ‘Reviewable Warnings’

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

  • dependent_elements (list of AutoDesk.Revit.DB.Element) – List of elements to check.

Returns:

A list of elements id where the workset name of the element is not ‘Reviewable Warnings’

Return type:

list of AutoDesk.Revit.DB.Element

duHast.Revit.Common.purge_utils.has_dependent_elements(doc, el, filter=None, threshold=2)

Checks whether an element has dependent elements. The dependent elements are collected via Element.GetDependentElements(filter). This also includes a check as to whether elements returned as dependent are orphaned. (for lack of better words)

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

  • el (AutoDesk.Revit.DB.Element) – The element to be checked for dependent elements.

  • filter (Autodesk.Revit.DB.ElementFilter , optional) – What type of dependent elements to filter, defaults to None which will return all dependent elements

  • threshold (int, optional) – The number of how many dependant elements an element can have but still be considered not used, defaults to 2

Returns:

returns 0 for no dependent elements, 1, for other elements depend on it, -1 if an exception occurred

Return type:

int

duHast.Revit.Common.purge_utils.get_used_unused_type_ids(doc, type_id_getter, use_type=0, threshold=2)

Gets either the used or not used type Ids provided by typeIdGetter. Whether the used or unused type ids depends on the useType value. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param type_id_getter: Function returning type ids :type type_id_getter: list of Autodesk.Revit.DB.ElementId :param use_type: 0, no dependent elements; 1: has dependent elements, defaults to 0 :type use_type: int, optional :param threshold: The number of how many dependant elements an element can have but still be considered not used, defaults to 2 :type threshold: int, optional :return: A list of either all used or unused element ids. Depends on useType. :rtype: list of Autodesk.Revit.DB.ElementId

duHast.Revit.Common.revit_version module

duHast.Revit.Common.revit_version.get_revit_version_number(doc)

Returns the revit version as an integer.

Parameters:

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

Returns:

Revit version

Return type:

int

duHast.Revit.Common.transaction module

Revit transaction wrapper utility functions.

duHast.Revit.Common.transaction.in_transaction(tranny, action, *args, **kwargs)

Revit transaction wrapper.

This function is used to execute any actions requiring a transaction in the Revit api. On exception this will roll back the transaction.

Parameters:
  • tranny (Autodesk.Revit.DB.Transaction) – The transaction to be executed.

  • doc (Autodesk.Revit.DB.Document) – The current model document. (not used in this function)

  • action (action().) – The action to be nested within the transaction. This needs to return a Result class instance!

  • *args

    is just a placeholder in case this function is called with the same args than in_transaction_with_failure_handling

  • **kwargs

    is just a placeholder in case this function is called with the same args than in_transaction_with_failure_handling

Returns:

Result class instance.

  • .status True if successfully executed transaction, otherwise False.

Return type:

Result

duHast.Revit.Common.transaction.in_transaction_with_failure_handling(transaction, action, failure_config=FailureHandlingConfig(roll_back_on_warning=False, print_warnings=False, roll_back_on_error=False, print_errors=False, allowable_failures=None, set_forced_modal_handling=True, set_clear_after_rollback=True, output_function=<function output>), failure_processing_func=<function process_failures>)

Executes an action within a Revit transaction with Revit failure processing enabled.

Example usage:

def main(revit_doc, foo, bar):

fail_config = FailureHandlingConfig() fail_config.print_warnings = False

def add_func():

# Perform actions here return foo + bar

trans = Transaction(revit_doc, “Add the things together”) added_vals = in_transaction_with_failures(trans, add_func, fail_config)

Parameters:
  • transaction (Transaction) – The executing transaction to apply the failure handling to

  • action (function) – The action to be executed within the transaction

  • failure_config (FailureHandlingConfig) – Configuration for the failure handling (Optional)

  • failure_processing_func (function) – The function to process the failures (Optional)

duHast.Revit.Common.worksets module

A number of helper functions relating to Revit worksets.

duHast.Revit.Common.worksets.get_workset_id_by_name(doc, workset_name)

Returns the element id of a workset identified by its name, otherwise invalid Id (-1) if no such workset exists

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

  • workset_name (str) – The name of the workset of which to retrieve the Element Id

Returns:

The workset element id, otherwise invalid Id (-1) if no such workset exists

Return type:

Autodesk.Revit.DB.ElementId

duHast.Revit.Common.worksets.get_workset_name_by_id(doc, id_integer)

Returns the name of the workset identified by its Element Id, otherwise ‘unknown’ if no such workset exists

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

  • id_integer (int) – The element id as integer value.

Returns:

The name of the workset identified by its Id, otherwise ‘unknown’

Return type:

str

duHast.Revit.Common.worksets.get_workset_ids(doc)

Gets all ids of all user defined worksets in a model

Parameters:

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

Returns:

List of all user defined workset element ids

Return type:

list Autodesk.Revit.DB.ElementId

duHast.Revit.Common.worksets.get_worksets(doc)

Returns all user defined worksets in the model as list.

Will return a list of zero length if no worksets in the model.

Parameters:

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

Returns:

List of worksets

Return type:

list of Autodesk.Revit.DB.Workset

duHast.Revit.Common.worksets.get_worksets_from_collector(doc)

Returns all user defined worksets in the model as collector.

Parameters:

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

Returns:

A filtered elements collector of user defined worksets

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Common.worksets.open_worksets_with_elements_hack(doc, ui_doc)

This is based on a hack from the AutoDesk forum and an article from the building coder:

this method will open worksets in a model containing elements only

Parameters:

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

duHast.Revit.Common.worksets.modify_element_workset(doc, default_workset_name, collector, element_type_name)

Attempts to change the worksets of elements provided through an element collector.

Will return false if target workset does not exist in file.

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

  • default_workset_name (str) – The name of the workset the elements are to be moved to.

  • collector (Autodesk.Revit.DB.FilteredElementCollector) – The element collector containing the elements.

  • element_type_name (str) – A description used in the status message returned.

Returns:

Result class instance.

  • .status = True if successfully moved all elements to new workset. Otherwise False.

  • .message will contain stats in format [success :: failure]

Return type:

Result

duHast.Revit.Common.worksets.get_action_change_element_workset(el, default_id)

Contains the required action to change a single elements workset

Parameters:
  • el (Autodesk.Revit.DB.Element) – The element

  • default_id (Autodesk.Revit.DB.ElementId) – The workset element Id

duHast.Revit.Common.worksets.is_element_on_workset_by_id(doc, el, workset_id)

Checks whether an element is on a given workset

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

  • el (Autodesk.Revit.DB.Element) – The element.

  • workset_id (Autodesk.Revit.DB.ElementId) – The workset element Id

Returns:

True if element is on given workset, otherwise False

Return type:

bool

duHast.Revit.Common.worksets.is_element_on_workset_by_name(el, workset_name)

Checks whether an element is on a workset identified by name

Parameters:
  • el (Autodesk.Revit.DB.Element) – The element

  • workset_name (str) – The name of the workset

Returns:

True if element is on given workset, otherwise False

Return type:

bool

duHast.Revit.Common.worksets.get_element_workset_name(el)

Returns the name of the workset an element is on, or ‘invalid workset’.

Parameters:

el (Autodesk.Revit.DB.Element) – The element.

Returns:

The name of the workset. If an exception occurred it wil return ‘invalid workset’.

Return type:

str

duHast.Revit.Common.worksets.update_workset_default_visibility_from_report(doc, report_path, revit_file_path)

Updates the default visibility of worksets based on a workset report file.

The data for the report files is generated by GetWorksetReportData() function in this module

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

  • report_path (str) – The fully qualified file path to tab separated report text file containing workset data.

  • revit_file_path (str) – The fully qualified file path of the Revit file. Will be used to identify the file in the report data.

Returns:

Result class instance.

  • .status = True if:

    • successfully updated all workset default visibility where different to report

    • or none needed updating.

  • Otherwise False:

    • An exception occurred.

    • A workset has no matching data in the report.

  • Common:

    • .message will contain each workset and whether it needed updating or not

Return type:

Result

duHast.Revit.Common.worksets.create_workset(doc, workset_name)

Creates a workset with a given name in a document.

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

  • workset_name (str) – The name of the workset to be created

Returns:

Result class instance.

  • .status = True if:

    • successfully created the workset

  • Otherwise False:

    • An exception occurred.

    • A workset with that name already exists.

    • Document is not workshared

  • Common:

    • .message will contain each workset

.result will contain the workset element in a list if successfully created, otherwise an empty list.

Return type:

Result

duHast.Revit.Common.worksets.delete_workset(doc, delete_workset_name, move_elements_to_workset_name=None)

deletes a workset given by name

if a move elements to workset name is provided, delete workset settings will be set accordingly

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

  • delete_workset_name (str) – The name of the workset to be deleted

  • move_elements_to_workset_name (str (default is None)) – The name of the workset elements to be moved to. If None all elements on the workset will be deleted.

Returns:

Result class instance.

  • .status = True if:

    • successfully deleted the workset

  • Otherwise False:

    • An exception occurred.

    • Revit cant delete the workset with the settings provided.

    • Document is not workshared

.result will contain an empty list.

Return type:

Result

Module contents