Sample Code Revit Batch Processor 1.1.16 documentation

Contents:

This Page

duHast.pyRevit package

Subpackages

Submodules

duHast.pyRevit.console_output module

A number of helper functions relating to py pyrevit output to console duHast result class.

duHast.pyRevit.console_output.print_result(result, header=None)

Prints a result class instance to the pyRevit console.

Parameters:
  • result (Result) – The result instance to be printed.

  • header (str) – The header to be printed before the result.

duHast.pyRevit.console_output.print_header(header)

Prints a header to the pyRevit console.

Parameters:

header (str) – The header to be printed.

duHast.pyRevit.console_output.print_error(message)

Prints an error message to the pyRevit console.

Parameters:

message (str) – The error message to be printed.

duHast.pyRevit.directory_picker module

A number of helper functions relating to pyrevit directory selection.

duHast.pyRevit.directory_picker.get_user_options(forms)

Gets the user options for saving out families

Options are: save out to single directory, exclude existing families, overwrite existing families

Parameters:

forms (Forms) – the forms object

Returns:

the user options

Return type:

dict

duHast.pyRevit.directory_picker.get_process_directories(forms, form_title='Select directory')

Gets the directories to process

Parameters:

forms (Forms) – the forms object

Returns:

the directories to process

Return type:

list

duHast.pyRevit.directory_picker.get_process_directory(forms, form_title='Select directory')

Gets the directories to process

Parameters:

forms (Forms) – the forms object

Returns:

the directories to process

Return type:

list

duHast.pyRevit.file_picker module

This module contains a pyRevit file picker wrapper function.

duHast.pyRevit.file_picker.get_file_path_from_user(forms, title, file_extension, multi_file=False)

Very simple wrapper function to get a file path from the user.

Parameters:
  • forms (pyRevit forms module) – pyRevit forms

  • title (str) – The title of the file picker dialog.

  • file_extension (str) – The file extension to filter for. Example: “csv”

  • multi_file (bool, optional) – Single vs multi file selection, defaults to False (single file)

Returns:

The file path(s) selected by the user. None if no file was selected.

Return type:

str, [str],None

duHast.pyRevit.net_dll_loader module

duHast.pyRevit.net_dll_loader.get_bin_path(bin_directory=None)

Get the path to the bin directory of the extension. If a bin directory is provided, it will be used. Otherwise, the function will look for bin directories in the sys.path and return the shortest one.

Parameters:

bin_directory (str or None) – Optional path to the bin directory. If not provided, the function will search for bin directories in sys.path.

Returns:

Result object with status, message, and list of bin paths found.

Return type:

Result

duHast.pyRevit.net_dll_loader.find_dll_path(dll_name, bin_path, exact_match=True)

Find DLL path based on exact or startswith matching.

Parameters:
  • dll_name – Name of the DLL to find (e.g., “MyLibrary.dll”)

  • bin_path – Directory to search for the DLL

  • exact_match – If True, looks for an exact match of dll_name. If False, looks for files that start with dll_name.

Returns:

Full path to the DLL if found, otherwise None

duHast.pyRevit.net_dll_loader.is_assembly_loaded(assembly_name)

Check if an assembly with the given name is already loaded

Parameters:

assembly_name – Name of the assembly to check (e.g., “MyLibrary”)

Returns:

True if assembly is loaded, False otherwise

duHast.pyRevit.net_dll_loader.load_net_dll_path(dlls_to_load, bin_directory=None, exact_match=True)

Loads dlls from the libs folder of the duHast extension. Useful if a dll is not loaded through the startup script of a pyRevit extension.

expects the bin folder to be in the sys.path which means it needs to be located in the root folder of the extension: YourExtension.extensionbin

Parameters:

dlls_to_load (list) – List of dlls to load.

Returns:

Result object with status and message.

Return type:

Result

duHast.pyRevit.net_dll_loader.get_specific_path(full_path, target_folder, endswith=False)

Extract path up to and including target folder.

Args:

full_path: Full file or directory path target_folder: Folder name to search for (e.g., ‘lib’) endswith: If True, match folders ending with target_folder.

If False (default), exact match only.

Returns:

Path ending with target_folder + ‘' or None if target_folder not found

duHast.pyRevit.net_dll_loader.get_extension_path(full_path)

Extract path up to and including ‘lib’ directory.

Args:

full_path: Full file or directory path

Returns:

Path ending with ‘lib’ or None if ‘lib’ not found

duHast.pyRevit.net_dll_loader.get_lib_path(full_path)

Extract path up to and including ‘lib’ directory.

Args:

full_path: Full file or directory path

Returns:

Path ending with ‘lib’ or None if ‘lib’ not found

duHast.pyRevit.net_dll_loader.is_bin_after_extension(path)

Check if bin folder comes directly after a folder ending with .extension

Args:

path: Full directory path

Returns:

True if bin is directly after .extension folder

duHast.pyRevit.net_dll_loader.get_bin_path_from_script_path_within_extension(script_path)

Get the path to the bin directory based on the location of the script folder. Assumes that the bin folder is located in the root of the extension and that the script folder is located somewhere within the extension.

Args:

script_folder: Full path to the folder where the script is located

Returns:

Path to the bin directory if found, otherwise None

duHast.pyRevit.ui_element_selection module

This module contains a number of helper functions relating to py Revit element selection from list.

duHast.pyRevit.ui_element_selection.default_name_builder(element)

Deafult element name builder is used to build the element name shown in the UI by combining the element name and element Id

Parameters:

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

Returns:

A name of the element.

Return type:

str

duHast.pyRevit.ui_element_selection.get_element_selection_from_user(doc, forms, element_getter, element_selection_description, multiselect=True, ui_element_name_builder=<function default_name_builder>)

lists Elements provided by element getter function in UI and returns the users selection

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Ther current Revit model.

  • forms (_type_) – pyRevit forms

  • element_getter (_type_) – Function accpeting the document as the only argument returning a list of elements or empty list.

  • element_selection_description (str) – Text to be displayes on button to prompt user

Returns:

None if nothing was selected. Otherwise a list of element ids

Return type:

None or [Autodesk.Revit.ElementId]

Module contents