Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.SharedParameters package

Subpackages

Submodules

duHast.Revit.SharedParameters.purge_unused_shared_parameters_by_delete module

Revit purging not used shared parameters using purge by delete helper functions.

duHast.Revit.SharedParameters.purge_unused_shared_parameters_by_delete.get_shared_parameter_ids(doc, element_ids=None, element_ids_list_is_inclusive_filter=True)

Returns all shared parameter ids in the model with the exception of parameters which have a binding and are therefore assumed to be used.

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

  • element_ids ([Autodesk.Revit.DB.ElementId]) – optional list of shared parameter element ids

  • element_ids_list_is_inclusive_filter (bool) – If true and element_ids list has values only those parameters will be purged if possible. If false and element_ids list has values any parameters in the list will not be purged.

Returns:

A list of all shared parameter ids in the model.

Return type:

list of Autodesk.Revit.DB.ElementId

duHast.Revit.SharedParameters.purge_unused_shared_parameters_by_delete.purge_shared_parameters_by_delete(doc, progress_callback=None, debug=False, element_ids=None, element_ids_list_is_inclusive_filter=True)

Purge shared parameters by delete.

Note: This is a slow(ish) process and can take a few hours to complete depending on the size of the model and the number of shared parameters.

No parameters with a category binding will be deleted. (refer below for more details on this)

Observations:

  • any shared parameter which is bound to a category in a Revit model (but not used in a family etc) will report 2 elements as deleted:
    • the shared parameter itself

    • the binding (type or instance) to a category

  • any shared parameter which is not bound to a category in a Revit model, but used in a family etc will report
    • 1 element as deleted
      • the shared parameter itself

    • multiple changed elements:
      • the families (and any of its instances placed) the shared parameter is used in

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

  • progress_callback (callable) – Callback to report progress.

  • debug (bool) – Debug mode.

  • element_ids ([Autodesk.Revit.DB.ElementId]) – optional list of shared parameter element ids

  • element_ids_list_is_inclusive_filter (bool) – If true and element_ids list has values only those parameters will be purged if possible. If false and element_ids list has values any parameters in the list will not be purged.

Returns:

Result class instance.

  • .status True if unused shared parameters where deleted or nothing needed to be deleted. Otherwise False.

  • .message will contain deletion status.

duHast.Revit.SharedParameters.shared_parameter_add module

This module contains a function to bind a shared parameter to a category.

based on building coder article: https://thebuildingcoder.typepad.com/blog/2012/04/adding-a-category-to-a-shared-parameter-binding.html

duHast.Revit.SharedParameters.shared_parameter_add.load_shared_parameter_file(doc, path=None)

Loads a shared parameter file.

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

  • path (str) – (Optional) Fully qualified file path to shared parameter text file.

Returns:

The opened shared parameter file.

Return type:

Autodesk.Revit.DB.DefinitionFile

duHast.Revit.SharedParameters.shared_parameter_add.bind_shared_parameter(doc, category, parameter_name, group_name, parameter_type, is_visible, is_instance, parameter_grouping, shared_parameter_filepath)

Binds a shared parameter to a revit category.

Refer building coder article referenced in header

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

  • category (Autodesk.Revit.DB.BuiltInCategory) – The built in category, to which the parameter will be bound.

  • parameter_name (str) – The parameter name.

  • group_name (str) – The group under which the parameter appears in shared parameter text file.

  • paramType (Autodesk.Revit.DB.ParameterType) – The parameter type. (Area, vs text vs… (deprecated in Revit 2022!)

  • is_visible (bool) – Is parameter visible in UI to users.

  • is_instance (bool) – True parameter is an instance parameter, otherwise type parameter.

  • parameter_grouping (str) – Where parameter appears in properties section in UI.

  • shared_parameter_filepath (str) – Fully qualified file path to shared parameter text file.

Returns:

Result class instance.

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

  • result.message will contain the name of the shared parameter.

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain exception message.

Return type:

Result

duHast.Revit.SharedParameters.shared_parameter_add.add_shared_parameter_to_family(para, mgr, doc, def_file)

Adds a shared parameter definition to a family document.

Parameters:
  • para (tuple (refer module RevitSharedParametersTuple)) – Tuple containing parameter info

  • mgr (Autodesk.Revit.DB.FamilyManager) – The family manager object

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

  • def_file (_type_) – The shared parameter definition file.

Returns:

Result class instance.

  • True if added successfully. False if an exception occurred.

  • result.message will contain the name of the shared parameter.

  • .result.result will contain the family parameter object.

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain exception message.

Return type:

Result

duHast.Revit.SharedParameters.shared_parameter_add.bind_shared_parameters_to_new_category(rvt_doc, target_params, target_cat, target_param_grp, type_binding=False)

Takes a list of shared parameter definitions and creates a binding to a new category. Will add category to an existing binding if one exists already :param rvt_doc: Revit document :type rvt_doc: Autodesk.Revit.DB.Document :param target_params: List of shared parameter definitions :type target_params: list[Autodesk.Revit.DB.ExternalDefinition] :param target_cat: Category to bind to :type target_cat: BuiltInCategory :param target_param_grp: Parameter Group new parameters will appear in :type target_param_grp: BuiltInParameterGroup :param type_binding: True if type binding, False if instance binding :type type_binding: bool :return: List of successful bindings, list of errors :rtype: tuple

duHast.Revit.SharedParameters.shared_parameter_swap module

This module contains a function to swap out one shard parameter for another.

The swap is done by: - changing current shared parameter to a family parameter (dummy) - deleting the old shared parameter definition - swapping the family parameter (dummy) to the new shared parameter.

Note: storage types of old and new shared parameter need to be identical.

Parameter change directives are read from a .csv file:

  • header row: yes

  • column 1: current shared parameter name

  • column 2: new shared parameter name

  • column 3: fully qualified file path of shared parameter file

  • column 4: Is parameter instance (True / False)

  • column 5: parameter grouping name ( refer to module: RevitParameterGrouping)

duHast.Revit.SharedParameters.shared_parameter_swap.PARAMETER_SETTINGS_DATA

alias of parameterSettingsData

duHast.Revit.SharedParameters.shared_parameter_swap.swap_shared_parameters(doc, change_directive_file_path)

Swaps out a shared parameter for another. (refer to module header for details)

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

  • change_directive_file_path (str) – Fully qualified file path to shared parameter change directive.

Returns:

Result class instance.

  • False if an exception occurred, otherwise True.

  • result.message will contain the names of the changed shared parameter(s).

  • result status will contain lists of new shared parameters

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain exception message.

Return type:

Result

duHast.Revit.SharedParameters.shared_parameter_type_change module

This module contains a number of helper functions relating to changing Revit shared parameters to family parameters and vise versa.

duHast.Revit.SharedParameters.shared_parameter_type_change.change_shared_parameter_to_family_parameter(doc, parameter_name, prefix='_')

Changes a shared family parameter to a standard family parameter.

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

  • parameter_name (str) – The shared parameter name.

  • prefix (str, optional) – Revit requires the new parameter to have a different name to the shard parameter, therefore a prefix to the name is applied, defaults to ‘_’

Returns:

Result class instance. - Parameter change status returned in result.status. False if an exception occurred, otherwise True. - result.message will contain the name of the shared parameter and the new family parameter name. - result.status will contain the new family parameter. On exception (handled by optimizer itself!): - result.status (bool) will be False. - result.message will contain generic exception message. - result.status will be an empty list

Return type:

Result

duHast.Revit.SharedParameters.shared_parameter_type_change.change_family_parameter_to_shared_parameter(doc, parameter_name, parameter_data, parameter_def)

Changes a family parameter to a shared parameter.

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

  • parameter_name (str) – The family parameter name.

  • parameter_data (RevitSharedParametersTuple.parameterData) – A named tup[le containing the shared parameter information

  • parameter_def (Autodesk.Revit.DB.ExternalDefinition) – The external definition of the shared parameter.

Returns:

Result class instance. - Parameter change status returned in result.status. False if an exception occurred, otherwise True. - result.message will contain the name of the family parameter and the new shared parameter name. - result.status will contain the new shared parameter. On exception (handled by optimizer itself!): - result.status (bool) will be False. - result.message will contain generic exception message. - result.status will be an empty list

Return type:

Result

duHast.Revit.SharedParameters.shared_parameters module

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

duHast.Revit.SharedParameters.shared_parameters.get_all_shared_parameters(doc)

Gets all shared parameters in a model

Parameters:

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

Returns:

A filtered element collector containing shared parameter elements

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.SharedParameters.shared_parameters.get_all_shared_parameters_from_file(rvt_doc, shared_param_file_path=None)

Gets all the shared parameter definitions from a shared parameter file. Can either be set manually or will be loaded from the default location which Revit is pointing at :param rvt_doc: Current Revit model document. :type rvt_doc: Autodesk.Revit.DB.Document :param shared_param_file_path: (Optional) The path to the shared parameter file. :type shared_param_file_path: str :return: A flat list of shared parameter definitions :rtype: list

duHast.Revit.SharedParameters.shared_parameters.get_family_shared_parameters(doc)

Gets all family parameters which are shared parameters.

Parameters:

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

Raises:

Exception – “Document is not a family document.” when a non family document is past in.

Returns:

A list of family parameters

Return type:

[Autodesk.Revit.DB.FamilyParameter]

duHast.Revit.SharedParameters.shared_parameters.get_family_parameters(doc)

Gets all family parameters.

Parameters:

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

Raises:

Exception – “Document is not a family document.” when a non family document is past in.

Returns:

A list of family parameters

Return type:

[Autodesk.Revit.DB.FamilyParameter]

duHast.Revit.SharedParameters.shared_parameters.check_whether_shared_parameters_are_in_file(doc, parameter_gui_ds)
Filters the past in list of shared parameter GUIDs by using the shared parameters in the document.

Only parameter in both will be returned.

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

  • parameter_gui_ds (list str) – list of shared parameter GUIDs as string values

Returns:

list of shared parameter GUIDs as string values

Return type:

list str

duHast.Revit.SharedParameters.shared_parameters.check_whether_shared_parameters_by_name_is_family_parameter(doc, parameter_name)

Checks, by name, whether a shared parameter exists as a family parameter in a family.

param doc: Current Revit family document. :type doc: Autodesk.Revit.DB.Document :param parameter_name: The name of the parameter. :type parameter_name: str

Returns:

A family parameter if match was found, otherwise None

Return type:

Autodesk.Revit.DB.FamilyParameter

duHast.Revit.SharedParameters.shared_parameters.is_shared_parameter_definition_used(doc, shared_para)

Tests if a shared parameter GUID is used by a family parameter.

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

  • shared_para (Autodesk.Revit.DB.SharedParameterElement) – A shared parameter

Returns:

True is match is found, otherwise False

Return type:

bool

duHast.Revit.SharedParameters.shared_parameters.get_unused_shared_parameter_definitions(doc)

Returns all unused shard parameter definitions in a family document.

Note: These shared parameters might be used in any nested family!

Parameters:

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

Returns:

A list of shared parameters

Return type:

[Autodesk.Revit.DB.SharedParameterElement]

duHast.Revit.SharedParameters.shared_parameters.get_shared_parameter_definition(parameter_name, def_file)

Returns a shared parameter definition from a shared parameter file.

Parameters:
  • parameter_name (str) – The shared parameter name.

  • def_file (Autodesk.Revit.DB.DefinitionFile) – The shared parameter file definition.

Returns:

The shared parameter definition. None if no parameter with a matching name was found.

Return type:

Autodesk.Revit.DB.ExternalDefinition

duHast.Revit.SharedParameters.shared_parameters.param_binding_exists(doc, param_name, param_type)

Gets all parameter bindings for a given parameter depending on revit version.

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

  • param_name (str) – The name of the parameter.

  • param_type (Autodesk.Revit.DB.ParameterType) – The parameter type. (Area, vs text vs… (deprecated in Revit 2022!)

Returns:

List of categories a parameter is attached to.

Return type:

list of str

duHast.Revit.SharedParameters.shared_parameters.param_binding_exists_2022(doc, param_name, param_type)

Gets all parameter bindings for a given parameter fro Revit versions up to 2022.

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

  • param_name (str) – The name of the parameter.

  • param_type (Autodesk.Revit.DB.ParameterType) – The parameter type. (Area, vs text vs… (deprecated in Revit 2022!)

Returns:

List of categories a parameter is attached to.

Return type:

list of str

duHast.Revit.SharedParameters.shared_parameters.param_binding_exists_2023(doc, param_name, type_id)

Gets all parameter bindings for a given parameter for Revit 2023 onwards

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

  • param_name (str) – The name of the parameter.

  • type_id (Autodesk.Revit.DB.ForgeTypeId) – Forge type id

Returns:

List of categories a parameter is attached to.

Return type:

list of str

duHast.Revit.SharedParameters.shared_parameters_delete module

This module contains a number of helper functions relating to deleting Revit shared parameters.

duHast.Revit.SharedParameters.shared_parameters_delete.delete_shared_parameter_by_name(doc, shared_parameter_name)

Deletes a single shared parameter based on a name provided.

param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param shared_parameter_name: The name of the shared parameter. :type shared_parameter_name: str :return: Result class instance.

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

  • result.message will contain the name of the shared parameter.

  • result.status will be an empty list.

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain generic exception message.

  • result.status will be an empty list

Return type:

Result

duHast.Revit.SharedParameters.shared_parameters_delete.delete_shared_parameter_by_guid(doc, guid)

Deletes a single shared parameter based on a guid provided.

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

  • guid (str) – A shared parameter GUID as string.

Returns:

Result class instance.

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

  • result.message will contain the name of the shared parameter.

  • result.status will be an empty list.

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain generic exception message.

  • result.status will be an empty list

Return type:

Result

duHast.Revit.SharedParameters.shared_parameters_delete.delete_shared_parameters(doc, parameter_guids)

Deletes shared parameters by GUID from document.

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

  • parameter_gui_ds (list str) – List of shared parameter GUIDs as string.

Returns:

Result class instance.

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

  • result.message will contain the name of the shared parameter deleted.

On exception (handled by optimizer itself!):

  • result.status (bool) will be False.

  • result.message will contain generic exception message.

Return type:

Result

duHast.Revit.SharedParameters.shared_parameters_tuple module

This module contains a tuple used to store settings retrieved from a file.

duHast.Revit.SharedParameters.shared_parameters_tuple.PARAMETER_DATA

alias of parameterData

Module contents