Sample Code Revit Batch Processor 1.1.16 documentation

Contents:

This Page

duHast.Revit.Family.LibraryCleanUp.Utility package

Submodules

duHast.Revit.Family.LibraryCleanUp.Utility.defaults module

duHast.Revit.Family.LibraryCleanUp.Utility.directive_maintain_types_execute module

duHast.Revit.Family.LibraryCleanUp.Utility.directive_maintain_types_execute.update_type_catalogue_file(doc, maintain_types_list)

Updates the type catalogue file for a family document by removing types that are not in the maintain list.

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

  • maintain_types_list (list of nested lists, each containing two strings: [family_name, type_name]) – A list of types to maintain, where each entry is a tuple (family_name, type_name).

Returns:

Result object containing the status and messages.

Return type:

duHast.Utilities.Objects.result.Result

duHast.Revit.Family.LibraryCleanUp.Utility.directive_maintain_types_execute.get_names_of_types_to_keep(family_name, maintain_types_list)
duHast.Revit.Family.LibraryCleanUp.Utility.directive_maintain_types_execute.create_default_type(doc, types_to_delete)

Creates a default family type in the family document if a catalogue file is in use…

Parameters:

doc (Autodesk.Revit.DB.Document) – The family document to process.

Returns:

Result object containing the status and messages.

Return type:

duHast.Utilities.Objects.result.Result

duHast.Revit.Family.LibraryCleanUp.Utility.directive_maintain_types_execute.delete_non_conforming_types(doc, maintain_types_list)

Delete non-conforming types in a family document based on a list of types to maintain.

Note

Types reported might only live in a type catalogue file. In that case the family may only contain a place holder type with name “Refer To Catalog File” or similar.

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

  • maintain_types_list (list of nested lists, each containing two strings: [family_name, type_name]) – A list of types to maintain, where each entry is a tuple (family_name, type_name).

Returns:

Result object containing the status and messages.

Return type:

duHast.Utilities.Objects.result.Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_checks module

duHast.Revit.Family.LibraryCleanUp.Utility.directives_checks.verify_copy_directives_are_unique(copy_directives)

Verify that the copy directives are unique based on their new names.

Parameters:

copy_directives (list[FamilyDirectiveCopy]) – A list of copy directives to verify.

Returns:

True if all copy directives are unique, False otherwise.

Return type:

bool

duHast.Revit.Family.LibraryCleanUp.Utility.directives_checks.check_directives(output_path, copy_directives, families_with__missing_group_codes=None)

Check the copy directives for duplicates and missing group codes. :param output_path: The path where the output files will be written. :type output_path: str :param copy_directives: A list of copy directives to check. :type copy_directives: list[FamilyDirectiveCopy] :param families_with__missing_group_codes: A list of families with missing group codes. :type families_with__missing_group_codes: list[FamilyTypeDataStorageManager]

Returns:

A Result object containing the status and messages of the checks.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create module

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.get_code_to_use(full_code, group_code, code_to_descriptor_map)
duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.get_unique_group_codes_from_family(family_storage_data)

Get unique group codes from the family storage data.

will return a dictioanry where key is the full code and value is the group code without any sub codes. ITSE-002.01 will return {‘ITSE-002.01’: ‘ITSE-002’} ITSE-001 will return {‘ITSE-001’: ‘ITSE-001’}

Parameters:

family_storage_data (FamilyTypeDataStorageManager) – The family storage data from which to get the unique group codes.

Returns:

A dictionary of unique codes and their cleaned versions.

Return type:

{str:str}

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.create_copy_directive_catalogue_file(name, category, source_file_path, target_directory, new_name)

Create a copy directive for the catalogue file.

Parameters:
  • name (str) – The name of the catalogue file.

  • category (str) – The category of the family.

  • source_file_path (str) – The path to the source catalogue file.

  • target_directory (str) – The directory where the catalogue file will be copied to.

  • new_name (str) – The new name for the catalogue file.

Returns:

A copy directive for the catalogue file.

Return type:

FamilyDirectiveCopy or None if the source file does not exist.

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.create_copy_directives(family_storage_data, unique_group_codes, output_directory, code_to_descriptor_map, output)

Create copy directives for each unique group code in the family storage data.

Parameters:
  • family_storage_data (FamilyTypeDataStorageManager) – The family storage data from which to create copy directives. (takes the family name, category and file path from this data)

  • unique_group_codes (dictionary {str:str}) – A dictionary where key is the full code and value is the group code without any sub codes.

  • output_directory (str) – The directory where the copied families will be saved.

  • code_to_descriptor_map (dict[str, (str, str)]) – A mapping of grouping codes to their descriptions.

Returns:

A list of copy directives.

Return type:

list[FamilyDirectiveCopy]

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.create_type_maintained_lists(family_storage_data, unique_group_codes, copy_directives, code_to_descriptor_map)

Create lists of family types to be maintained in the new family based on unique group codes.

Parameters:
  • family_storage_data (FamilyTypeDataStorageManager) – The family storage data from which to create type maintained lists.

  • unique_group_codes (dictionary {str:str}) – A dictionary where key is the full code and value is the group code without any sub codes.

  • copy_directives (list[FamilyDirectiveCopy]) – A list of copy directives to be used for creating type maintained lists.

  • code_to_descriptor_map (dict[str, (str, str)]) – A mapping of grouping codes to their descriptions.

Returns:

A list of nested type maintained lists with two entries each: new family name, family type name to be maintained. ( a family with multiple times to be maintained will have multiple entries in the list )

Return type:

list[ list[str] ]

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.create_swap_directives(family_storage_data, unique_group_codes, copy_directives, code_to_descriptor_map)

Create swap directives for each unique group code in the family storage data.

Parameters:
  • family_storage_data (FamilyTypeDataStorageManager) – The family storage data from which to create swap directives.

  • unique_group_codes (list[str]) – A list of unique group codes to create swap directives for.

  • copy_directives (list[FamilyDirectiveCopy]) – A list of copy directives to be used for creating swap directives.

  • code_to_descriptor_map (dict[str, (str, str)]) – A mapping of grouping codes to their descriptions.

Returns:

A list of swap directives.

Return type:

list[FamilyDirectiveSwap]

duHast.Revit.Family.LibraryCleanUp.Utility.directives_create.create_directives(family_storage_data_list, output_directory, code_descriptor_path, output)

Create directives based on family storage data.

Parameters:

family_storage_data (a list of FamilyTypeDataStorageManager) – The family storage data from which to create directives.

Returns:

Result class instance.

  • result.status: Directive creation status will be returned in result.status. False if an exception occurred, otherwise True.

  • result.message will be a log of conversion steps.

  • result.result will be a list containing the following items:
    • A list of FamilyDirectiveCopy directives for copying families.

    • A list of lists containing family type names to be maintained in the new family.

    • A list of FamilyDirectiveSwap directives for swapping family instances of types.

    • A list of family storage instances that had missing group codes in the code description mapping.

On exception

  • Reload.status (bool) will be False

  • Reload.message will contain the exception message

  • Reload.result will be an empty list

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_execute module

duHast.Revit.Family.LibraryCleanUp.Utility.directives_execute.execute_copy_directives_for_library_families(copy_directives)

Executes the copy directives for library families.

Parameters:

copy_directives (list) – List of copy directives to execute.

Returns:

Result object containing the status and messages.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_read_from_file module

duHast.Revit.Family.LibraryCleanUp.Utility.directives_read_from_file.read_maintain_types(directory_path)

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file module

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_maintain_list(maintain_file_list, output_directory)

Writes a list of maintain directives to a specified file.

Parameters:
  • maintain_file_list (list) – List of maintain directives to write.

  • output_directory (str) – Directory where the file will be written.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_swap_directives(swap_directives, output_directory)

Writes swap directives to a specified file.

Parameters:
  • swap_directives (list) – List of swap directives to write.

  • output_directory (str) – Directory where the file will be written.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_copy_directives(copy_directives, output_directory)

Writes copy directives to a specified file.

Parameters:
  • copy_directives – List of copy directives to write.

  • output_directory (str) – Directory where the file will be written.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_duplicate_directives_to_file(copy_directives, output_directory)

Writes duplicate directives to a specified file.

Parameters:
  • copy_directives (list) – List of duplicate directives to write.

  • output_directory (str) – Directory where the file will be written.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_directives_to_file(swap_directives, copy_directives, output_directory)

Writes directives to a specified file.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.directives_write_to_file.write_families_with_missing_group_codes(family_instances, output_directory)

Writes a list of families with missing group codes to a specified file.

Parameters:
  • family_instances ([FamilyTypeDataStorage]) – List of family instances with missing group codes.

  • output_directory (str) – Directory where the file will be written.

Returns:

Result object indicating success or failure.

Return type:

Result

duHast.Revit.Family.LibraryCleanUp.Utility.family_file_name module

duHast.Revit.Family.LibraryCleanUp.Utility.family_file_name.clean_up_family_name(fam_name)

Cleans up the family name by removing any dashes and spaces, replacing them with underscores.

Parameters:

fam_name (str) – The family name to clean up.

Returns:

The cleaned up family name.

Return type:

str

duHast.Revit.Family.LibraryCleanUp.Utility.family_file_name.build_family_name_from_descriptor(description, code_to_use, output)

Builds a family name from the given description by cleaning it up.

Description is in format

MAJOR CATEGORY: description part, description part, description part

Parameters:

description (str) – The description to build the family name from.

Returns:

The cleaned up family name.

Return type:

str

duHast.Revit.Family.LibraryCleanUp.Utility.family_load module

duHast.Revit.Family.LibraryCleanUp.Utility.family_load.get_families_to_be_loaded_for_swapping(doc, swap_directives)

Loads families to be swapped into the document.

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

  • swap_directives (list of dict) – The swap directives containing family names and paths.

Returns:

List of loaded family symbols.

Return type:

list of Autodesk.Revit.DB.FamilySymbol

duHast.Revit.Family.LibraryCleanUp.Utility.family_load.load_families_required_for_swapping(doc, swap_directives, library_directory)

Loads families required for swapping into the document.

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

  • swap_directives (list of dict) – The swap directives containing family names and paths.

Returns:

List of loaded family symbols.

Return type:

list of Autodesk.Revit.DB.FamilySymbol

duHast.Revit.Family.LibraryCleanUp.Utility.grouping_code module

duHast.Revit.Family.LibraryCleanUp.Utility.grouping_code.clean_code(code)

Cleans the grouping code by removing any sub codes after a dot.

duHast.Revit.Family.LibraryCleanUp.Utility.grouping_code.convert_to_file_name_code(code)

Converts the grouping code to a file name safe format.

duHast.Revit.Family.LibraryCleanUp.Utility.grouping_code.load_group_code_description(file_path)

Loads the grouping code and description from a CSV file.

Parameters:

file_path – The path to the CSV file containing the grouping codes and descriptions.

Returns:

A dictionary mapping cleaned grouping codes to their descriptions.

duHast.Revit.Family.LibraryCleanUp.Utility.write_task_lists module

duHast.Revit.Family.LibraryCleanUp.Utility.write_task_lists.write_task_lists(family_directory, task_list_directory, number_of_task_lists)

Module contents