Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.UI package

Subpackages

Submodules

duHast.UI.file_list module

Helper functions for the file selection GUI.

duHast.UI.file_list.get_revit_files_for_processing(location, include_sub_dirs, file_extension)
Extracts file data from varies sources:
  • bim 360 task text file

  • files on a local server directory

  • files on a local server directory and it’s subdirectories

  • local server based files provided through a task text file

Parameters:
  • location (str) – Can either be a directory, or a fully qualified file path.

  • includeSubDirs (bool) – If true and location is a directory, subdirectories will be included in file search.

  • fileExtension (str) – File type filter in ‘.ext’

Returns:

List of MyFileItem objects.

Return type:

MyFileItem

duHast.UI.file_list.get_files_from_csv_list_file(file_path_csv, file_extension)

Reads server based file data, the fully qualified file path, from a task file list file in csv format.

Parameters:
  • filePathCSV (str) – The fully qualified file path to the task list file.

  • fileExtension (str) – The file extension filter in format ‘.ext’

Returns:

A list of MyFileitem objects. If an exception occured an empty list will be returned.

Return type:

MyFileItem

duHast.UI.file_list.get_revit_files(directory, file_extension)

Returns files in a given directory and of a given file extension.

Parameters:
  • directory (str) – The fully qualified directory path.

  • file_extension (str) – The file extension filter in format ‘.ext’

Returns:

List of file items

Return type:

[FileItem]

duHast.UI.file_list.get_revit_files_incl_sub_dirs(directory, file_extension)

Returns files in a given directory and its sub directories of a given file extension.

Parameters:
  • directory (str) – The fully qualified directory path.

  • file_extension (str) – The file extension filter in format ‘.ext’

Returns:

List of file items

Return type:

[FileItem]

duHast.UI.file_list.get_file_size(item)

Helper used to define workload size (same as file size)

Parameters:

item (FileItem) – A file item object instance.

Returns:

The file size.

Return type:

int

duHast.UI.file_list.bucket_to_task_list_file_system(item)

Default task list content for files on a file server location.

Parameters:

item (FileItem) – A file item object instance.

Returns:

The item name.(fully qualified file path)

Return type:

str

duHast.UI.file_list.bucket_to_task_list_bim_360(item)

Default task list content for files on a BIM 360 cloud drive.

Parameters:

item (FileItem) – A file item object instance.

Returns:

The revit version, project guid, file guid separated by a space ‘ ‘

Return type:

str

duHast.UI.file_list.write_revit_task_file(file_name, bucket, get_data=<function bucket_to_task_list_file_system>)

Writes out a task list file.

Parameters:
  • file_name (str) – Fully qualified file path of the task file name including extension.

  • bucket (WorkloadBucket) – Workload bucket object instance.

  • get_data (func(FileItem) -> str, optional) – Returns data from file item object to be written to file, defaults to BucketToTaskListFileSystem

Returns:

Result class instance.

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

  • Result.message property contains fully qualified file path to task list file.

On exception:

  • .status (bool) will be False.

  • .message will contain the exception message.

Return type:

Result

duHast.UI.file_list.write_file_list(directory_path, file_extension, task_list_directory, task_files_number, file_getter, file_data_processor=<function bucket_to_task_list_file_system>)

Writes out all task list(s) to file(s).

Parameters:
  • directory_path (str) – Fully qualified directory path containing files to be added to task lists.

  • file_extension (str) – A file extension filter in format ‘.ext’

  • task_list_directory (str) – The fully qualified directory path where the task files will be written .

  • task_files_number (int) – The number of task files to be written.

  • file_getter (func(str, str) -> FileItem) – Function accepting a directory and file extension filter and returns file items from directory.

  • file_data_processor (func(FileItem) -> str, optional) – Function processing file item and returns a string to be written to task list file, defaults to BucketToTaskListFileSystem

Returns:

Result class instance.

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

  • Result.message property contains fully qualified file path for each task list file.

On exception:

  • .status (bool) will be False.

  • .message will contain the exception message.

Return type:

Result

duHast.UI.file_list.get_task_file_name(task_list_directory, counter)

Builds a fully qualified task file path.

Parameters:
  • taskListDirectory (str) – The fully qualified directory where the task file is (to be) located

  • counter (int) – A counter to be added to the task file name

Returns:

A fully qualified task file path

Return type:

str

duHast.UI.file_list.write_empty_task_list(file_name)

Writes out an empty task list.

Parameters:

fileName (str) – Fully qualified file path of the task file name including extension.

Returns:

Result class instance.

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

  • Result.message property contains fully qualified file path to empty task list file.

On exception:

  • .status (bool) will be False.

  • .message will contain the exception message.

Return type:

Result

duHast.UI.script module

The entry point for the file selection GUI.

duHast.UI.script.main(argv)

Entry point.

Parameters:

argv ([str]) – A list of string representing arguments past in.

duHast.UI.script.process_args(argv)

Processes past in arguments and checks whether inputs are valid.

Parameters:

argv (_type_) – List of arguments

Returns:

  • True if arguments past in are valid, otherwise False.

  • FIle select settings object instance.

Return type:

bool, FileSelectionSettings

duHast.UI.script.get_directory_from_file_path(file_path)

Returns the directory from a fully qualified file path.

Parameters:

file_path (str) – A fully qualified file path.

Returns:

A fully qualified directory path. On exception an empty string.

Return type:

str

duHast.UI.script.get_file_data(settings)

Retrieves Revit file data from either:

  • directory on a file server

  • a text file containing BIM 360 project data
    • text file needs to be a .csv

    • format:
      • 0 Revit Version:YYYY,Project GUID, File GUID, file size, BIM 360 file path

Parameters:

settings (FileSelectionSettings) – A file select settings object instance.

Returns:

List of file items

Return type:

[FileItem]

duHast.UI.script.get_files_from_list_file(file_path_csv)

Reads server based file data, the fully qualified file path, from a task file list file in csv format.

Parameters:

filePathCSV (str) – The fully qualified file path to the task list file.

Returns:

A list of MyFileItem objects. If an exception occurred an empty list will be returned.

Return type:

MyFileItem

duHast.UI.script.get_file_data_from_text_file(file_path)

Reads a file server based task list file. This file can either be a BIM360 task list file or a task list file containing file server based file path in a single column.

Parameters:

filePath (str) – The fully qualified file path to the task list file.

Returns:

A list of MyFileItem objects.

Return type:

MyFileItem

duHast.UI.script.is_bim_360_file(revit_files)

Checks whether the first item in a file item list belongs to a BIM 360 project.

Checks whether Project GUID property on file item object is None.

Parameters:

revit_files ([FileItem]) – List of file items.

Returns:

True if BIM360 file, otherwise False.

Return type:

bool

duHast.UI.script.CURRENT_SCRIPT_DIRECTORY = 'D:\\a\\SampleCodeRevitBatchProcessor\\SampleCodeRevitBatchProcessor\\src\\duHast\\UI'

the directory this script lives in

duHast.UI.script.XAML_FILE = 'ui.xaml'

xaml file name of file select UI

duHast.UI.script.XAML_FULL_FILE_NAME = 'D:\\a\\SampleCodeRevitBatchProcessor\\SampleCodeRevitBatchProcessor\\src\\duHast\\UI\\ui.xaml'

xaml full path

duHast.UI.ui_file_select module

A file selection GUI.

duHast.UI.ui_file_select.Mbox(title, text, style)

A simple win forms message box.

Parameters:
Returns:

A win form message box.

Return type:

_type_

class duHast.UI.ui_file_select.MyWindow(*args: Any, **kwargs: Any)

Bases: Window

Class constructor

Parameters:
  • xaml_full_file_name (str) – Fully qualified file path to wpf XAML file.

  • revitFiles ([str]) – List containing path to files.

  • settings (FileSelectionSettings) – A settings object.

TextBox_TextChanged(sender, e)

Event handler for text changed in TextBox.

BtnOK(sender, EventArgs)

Ok button event handler.

Gets the selected rows of files and adds them to .selectedFiles property Sets the dialog result value to True.

Parameters:
  • sender (_type_) – _description_

  • EventArgs (_type_) – _description_

BtnCancel(sender, EventArgs)

Cancel button event handler. Sets the dialogue result value to False.

Parameters:
  • sender (_type_) – _description_

  • EventArgs (_type_) – _description_

TextBoxSourcePath_TextChanged(sender, TextChangedEventArgs)

Source Path text box change event handler

Parameters:
  • sender (_type_) – _description_

  • TextChangedEventArgs (_type_) – _description_

CheckBoxSubDir_Checked(sender, RoutedEventArgs)

_summary_

Parameters:
  • sender (_type_) – _description_

  • RoutedEventArgs (_type_) – _description_

SubDirCheckBox_Unchecked(sender, RoutedEventArgs)

_summary_

Parameters:
  • sender (_type_) – _description_

  • RoutedEventArgs (_type_) – _description_

duHast.UI.workloader module

Helper functions to sort task evenly into workload buckets.

A bucket contains a number of files which will eventually be written into task files to be processed by batch processor. The below function attempt to fill these buckets evenly measured on file size.

duHast.UI.workloader.distribute_workload(number_of_buckets, items, getWorkloadSize)

Distributes a given number of items evenly by workload size into workload buckets.

Parameters:
  • numberOfBuckets (int) – The number of buckets items are to be distributed to

  • items ([foo]) – A list of items.

  • getWorkloadSize (func(foo) -> int) – A function returning the workload size from an item.

Returns:

A list of workload bucket objects containing items.

Return type:

list[ WorkloadBucket]

duHast.UI.workloader.sort(sub_li)

Python code to sort the tuples using second element of sublist. Inplace way to sort using sort().

Note: not sure a one liner warrants a method…?

Parameters:

sub_li (_type_) – _description_

Returns:

_description_

Return type:

_type_

Module contents