Sample Code Revit Batch Processor 1.1.11 documentation
global variable controlling debug output
Message snippets which indicate processing of a file went bad
Deletes all log marker files in a directory.
directory_path (str) – The directory path containing marker files to be deleted.
True if all files where deleted successfully, otherwise False.
bool
Removes chevrons and replace colons with underscores in session id supplied by revit batch processor so it can be used in a file name.
id (str) – Session id supplied by revit batch processor.
Re-formatted session id.
str
Re-introduces chevrons and replaces underscores with colons to match session Id format used in batch processor to a file name using a batch processor supplied id.
file_name_id (str) – A file name containing a session id with all illegal characters replaced.
A session id.
str
Writes out an empty marker file in given directory.
File is of type .txt
File name is the batch processor session_id used to identify the log file belonging to this process.
folder_path (str) – Directory of where the file will be written to.
session_id (str) – Session id supplied by revit batch processor.
True if marker file was written successfully, otherwise False.
bool
Returns file names of all text files in a given directory representing session Ids.
Files will be deleted immediately after reading
folder_path (str) – Directory of where test files are located
A list of ids in string format.
[str]
Returns a list of fully qualified filepath to log files matching the provided session Ids.
list_of_session_ids ([str]) – List of session ids.
List of fully qualified file path.
[str]
Reads the first two rows of a log file to get the session Id used.
file_path (str) – Fully qualified file path to log file
The session id, or if not not a log file: an empty string.
str
Extracts the session Id from logfile row.
sample: {“date”:{“local”:”17/12/2020”,”utc”:”17/12/2020”},”time”:{“local”:”16:49:27”,”utc”:”05:49:27”},”sessionId”:”235e2180-dc33-4d61-8773-1005a59344c0”,”message”:{“msgId”:””,”message”:”Session ID: <2020-12-17T05:49:27.559Z>”}}
Note: There are two session id fields in thi string!
TODO: Do some error handling!
row (str) – A json formatted string with the session id in chevrons.
The session id.
str
Returns text in between characters
text (str) – Text to parse
first (str) – String indicating start
last (str) – String indicating end
string in between start and end.
str
Returns the outer message string from json formatted message field in log file.
sample: {“date”:{“local”:”17/12/2020”,”utc”:”17/12/2020”},”time”:{“local”:”16:49:27”,”utc”:”05:49:27”},”sessionId”:”235e2180-dc33-4d61-8773-1005a59344c0”,”message”:{“msgId”:””,”message”:”Session ID: <2020-12-17T05:49:27.559Z>”}}
This includes leading tab characters
data (str) – json formatted row of logfile
The message string
str
Process revit batch processor session log file.
find Revit files processed:
check whether an exception occurred when processing any of the above files.
file_path (str) – Fully qualified file path to json formatted log file
returns list of arrays in format: [[processed Revit file name, status of processing (true or false), message]]
[[str]]
Reads a log file and checks whether any exception occurred when processing a specific revit file.
file_to_check (str) – Fully qualified file path of Revit file which was processed
log_file_path (str) – The fully qualified batch processor session log file path.
A process status and a message.
process status: True if no exception occurred during revit file processing, otherwise false
message: the exception message recorded in the log file.
bool, str
Extracts the file name from a process message block.
message_block ([str]) – list of json formatted rows representing all messages received during file process
The fully qualified file path of the file processed
str
Reads a batch processor logfile and extracts all file names of files processed.
file_path (str) – The fully qualified file path to log file.
a list lists containing The fully qualified file path for each file processed and their process status. True for no exception encountered, otherwise false. [[filepath, status]]
[[str, bool]]
Filters list of all files meant to be processed and returns the ones flagged as file not found.
files_processed ([[str, bool]]) – array of lists in format: [[filename, status as bool],[filename, status as bool],…]
array of lists in format: [[filename, status as bool],[filename, status as bool],…]
[[str, bool]]
Reads json formatted data into blocks per files processed.
Returns the message sections per row entry only.
json_data ([str]) – List of logfile rows in json data format
start_marker (str) – String in messages indicating start of block.
end_markers (str) – String in messages indicating end of block.
multiple_blocks (bool) – Flag indicating whether there are multiple data block in log file to be returned
List of list of str
[[str]]
Reads batch processor log file into lists of json objects.
{‘sessionId’: ‘778e87a5-4b94-4552-9e7e-c9ed38b5caee’, ‘time’: {‘local’: ‘09:35:45’, ‘utc’: ‘22:35:45’}, ‘date’: {‘local’: ‘25/11/2020’, ‘utc’: ‘24/11/2020’}, ‘message’: {‘msgId’: ‘’, ‘message’: ‘’}}
file_path (str) – The fully qualified file path to log file in json format
list of json objects
[json]
Loops over log files and checks whether any exceptions occurred during revit files processing.
folder_path (str) – Fully qualified directory path where marker files are stored.
debug (bool, optional) – Flag indicating whether this is running in debug mode which will output some debug messages, defaults to False
Result class instance.
Process status returned in result.status. False if an exception occurred, otherwise True.
result.message will contain message(s) for each revit file found in logs and whether an exception occurred during processing
result.result will be an empty list.
On exception:
result.status (bool) will be False.
result.message will contain the exception message.
result.status will be an empty list.
two values
whether a text value starts or does not start with a given text value
Decorator function to measure the time a function takes to execute and then print it to the console.
Use like @measure_time(should_output = show_benchmarking_output_bool) def function_to_measure():
should_output (bool) – Whether the elapsed time should be printed to the console
two values
whether a text value starts or does not start with a given text value
Returns True if valueOne does not match valueTwo. :param valueOne: a value :type valueOne: var :param valueTwo: another value :type valueTwo: var :return: True if valueOne does not match valueTwo, otherwise False :rtype: bool
Returns True if valueOne does match valueTwo. :param valueOne: a value :type valueOne: var :param valueTwo: another value :type valueTwo: var :return: True if valueOne does match valueTwo, otherwise False :rtype: bool
Returns True if valueOne starts with valueTwo. :param valueOne: a value :type valueOne: str :param valueTwo: another value :type valueTwo: str :return: True if valueOne starts with valueTwo, otherwise False :rtype: bool
Returns True if valueTwo does not starts with valueOne. :param valueOne: a value :type valueOne: str :param valueTwo: another value :type valueTwo: str :return: True if valueTwo does not starts with valueOne, otherwise False :rtype: bool
Compares two floats with a tolerance. Returns True if they are close enough, otherwise False
a (float) – A float
b (float) – A float
rel_tol (float, optional) – Relative tolerance used to compare the two floats, defaults to 1e-09
abs_tol (float, optional) – Absolute tolerance used to compare the two floats, defaults to 0.0
Returns True if they are close enough to be considered equal, otherwise False
bool
Default pip out method: print to console.
message (str) – A message
Print message to pipe.
Note:
If message is not a string it will convert it to a string.
Multi line strings will pe printed line by line.
strings containing [true] ot [false] will be padded to have [true] or [false] to the right hand side.
message (str, optional) – The message, defaults to ‘’
Print message to console.
Note:
The message will be prefixed with a date stamp in format ‘2022-08-09 19_09_19 :’
If message is not a string it will convert it to a string.
Multi line strings will pe printed line by line
strings containing [true] ot [false] will be padded to have [true] or [false] to the right hand side.
message (str, optional) – The message, defaults to ‘’
Prints header message to pipe.
Note:
If message is not a string it will convert it to a string.
message (str, optional) – The message, defaults to ‘’
Prints header message to pipe.
Note:
If message is not a string it will convert it to a string.
The header will be prefixed with a date stamp in format ‘2022-08-09 19_09_19 :’
message (str, optional) – The message, defaults to ‘’
date stamps (with varies formatting options)
file stamp date format using spaces as delimiter: 21 03 01
file stamp date format using spaces as delimiter: 2021 03 01
file stamp date format using underscores as delimiter: 2021_03_01
file stamp date time format using underscores as delimiter: 2021_03_01_18_59_59
time stamp using colons: 18:59:59
time stamp using colons: 18_59_59
Returns a date stamp formatted suitable for a file name. :param format: The date stamp format, defaults to FILE_DATE_STAMP_YY_MM_DD :type format: str, optional :return: datetime.now() string formatted using supplied format string :rtype: str
folder date format: no delimiter 210301
folder date format: no delimiter 20210301
folder date format: no delimiter 2021
Returns a date stamp formatted suitable for a folder name. :param format: The date stamp format, defaults to FOLDER_DATE_STAMP_YYYYMMDD :type format: str, optional :return: datetime.now() string formatted using supplied format string :rtype: str
Returns a date stamp formatted using past in format string. :param format: The date stamp format :type format: str :return: datetime.now() string formatted using supplied format string :rtype: str
Returns a time stamped output file name based on the past in file name and file extension. :param file_path: Fully qualified file path to file :type file_path: str :param file_extension: File extension needs to include ‘.’, defaults to ‘.txt’ :type file_extension: str, optional :param file_suffix: File suffix will be appended after the name but before the file extension, defaults to ‘’ :type file_suffix: str, optional :return: File name. :rtype: str
Check if a given path is a directory :param directory_path: Fully qualified directory path :type directory_path: str :return: True if directory, otherwise False :rtype: bool
Deletes an empty directory :param full_directory_path: Path to directory :type full_directory_path: str :return: True directory deleted, otherwise False :rtype: bool
Deletes a directory (even if it contains files) :param full_directory_path: Path to directory :type full_directory_path: str :return: True directory deleted, otherwise False :rtype: bool
Returns the immediate subdirectories of directory :param full_directory_path: Path to directory :type full_directory_path: str :return: any sub directories, empty list if none exist :rtype: list of str
Returns the parent directory of directory, or empty string if invalid directory :param full_directory_path: Path to directory :type full_directory_path: str :return: parent directory, or empty string :rtype: str
Create a folder. :param root: Directory path in which the new folder is to be created :type root: str :param folder_name: New folder name. :type folder_name: str :return: True if folder is created, otherwise False :rtype: bool
Create a folder. Checks whether folder exists and if not attempts to create it.
root (str) – Directory path in which the new folder is to be created
folder_name (str) – New folder name.
True if folder is created, otherwise False
bool
Check if a given directory exists :param directory_path: Fully qualified directory path :type directory_path: str :return: True if directory exists, otherwise False :rtype: bool
Function writing out report information as CSV file. :param file_name: The reports fully qualified file path. :type file_name: str :param header: list of column headers :type header: list of str :param data: list of list of strings representing row data :type data: [[str,str,..]] :param write_type: Flag indicating whether existing report file is to be overwritten ‘w’ or appended to ‘a’, defaults to ‘w’ :type write_type: str, optional :param enforce_ascci: Flag to enforce ASCII encoding on data. If True, data will be encoded to ASCII. Defaults to False. :type enforce_ascci: bool, optional :param encoding: Encoding used to write the file. Defaults to ‘utf-8’. :type encoding: str, optional :param bom: the byte order mark, Default is None (none will be written). BOM: “utf-16” = , “utf-16-le” = , utf-8 = :type bom: str, default is NoneType :param quoting: Quoting style used by the csv writer. Defaults to csv.QUOTE_NONE. Options are csv.QUOTE_ALL, csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERIC, csv.QUOTE_NONE :type quoting: int, optional
A Result object, with the result attribute set to True if the file was written successfully, False otherwise.
Read a column based text file, attempting to detect and handle encoding, including BOMs.
file_path (str) – The fully qualified file path to the csv file.
increase_max_field_size_limit (bool, optional) – Flag to increase the max field size limit. Defaults to False.
delimiter (str, optional) – The delimiter used in the text file. Defaults to ‘,’.
A Result object, with the result attribute set to a list of list of strings representing the data in each row.
Process a txt file by removing null bytes and then reading its content.
file_path (str) – The path to the CSV file to be processed.
delimiter (str, optional) – The delimiter used in the text file. Defaults to ‘,’.
A Result object, with the result attribute set to a list of list of strings representing the data in each row.
:class:`.Result
Read a csv file into a list of rows, where each row is another list.
Attempts to read the file with encoding first, then without encoding if that fails. Encoding is attempted first because it is more likely to be successful. The following encodings are attempted: ‘utf-8-sig’, ‘utf-16’.
file_path (str) – The fully qualified file path to the csv file.
increase_max_field_size_limit (bool, optional) – Flag to increase the max field size limit. Defaults to False.
delimiter (str, optional) – The delimiter used in the text file. Defaults to ‘,’.
A Result object, with the result attribute set to a list of list of strings representing the data in each row.
Reads the first line of a column based text file and returns it as a list of strings.
file_path (str) – The fully qualified file path.
delimiter (str, optional) – The delimiter used in the text file. Defaults to ‘,’.
encoding (str, optional) – Encoding used to read the file. Defaults to ‘utf-8’.
A Result object, with the first row of a text file in its result attribute.
Combines multiple text files into a single new file. Assumes:
files have a header row followed by data rows
same number of headers (columns) in each files.
files have the same header names per column
files are encoded in UTF-8!
The new file will be saved into the same folder as the original files.
folder_path (str) – Folder path from which to get files to be combined and to which the combined file will be saved.
file_prefix (str) – Filter: File name starts with this value
file_suffix (str) – Filter: File name ends with this value.
file_extension (str, format '.extension') – Filter: File needs to have this file extension
output_file_name (str, optional) – The file name of the combined file, defaults to ‘result.txt’
file_getter (func(folder_path, file_prefix, file_suffix, file_extension), optional) – Function returning list of files to be combined, defaults to GetFilesSingleFolder
delimiter (str, optional) – The delimiter used in the files (e.g., ‘,’ for CSV, ‘ ‘ for tab-separated), defaults to ‘,’
quoting (int, optional) – The quoting option for the CSV writer, defaults to csv.QUOTE_MINIMAL
A result object with status and message.
Appends one text file to another.
Assumes:
same number of headers (columns) in both files.
files are encoded in UTF-8!
source_file (str) – The fully qualified file path of the file to which the other file will be appended.
append_file (str) – The fully qualified file path of the file to be appended.
ignore_first_row (bool) – If True, first row of append file will not be appended to source file.( Assumed its a header row )
delimiter (str, optional) – The delimiter used in the files (e.g., ‘,’ for CSV, ‘ ‘ for tab-separated), defaults to ‘,’
quoting (int, optional) – The quoting option for the CSV writer, defaults to csv.QUOTE_MINIMAL
A result object with status and message.
Used to combine report files into one file, files may have different number / named columns.
Columns which are unique to some files will have as a value ‘N/A’ in files where those columns do not exist. File need to use <tab> character as column separator
folder_path (str) – Folder path from which to get files to be combined and to which the combined file will be saved.
file_prefix (str) – Filter: File name starts with this value
file_suffix (str) – Filter: File name ends with this value.
file_extension (str, format '.extension') – Filter: File needs to have this file extension
out_put_file_name (str, optional) – The file name of the combined file, defaults to ‘result.txt’
overwrite_existing (bool, optional) – Will overwrite an existing output file if set to True, defaults to False ( append to existing output file)
Used to combine report files into one file, files may have different number / named columns.
Columns which are unique to some files will have as a value ‘N/A’ in files where those columns do not exist. File need to use <,> character as column separator. (.CSV) Assumes all files have a header row!
folder_path (str) – Folder path from which to get files to be combined and to which the combined file will be saved.
file_prefix (str) – Filter: File name starts with this value
file_suffix (str) – Filter: File name ends with this value.
file_extension (str, format '.extension') – Filter: File needs to have this file extension
output_file_name (str, optional) – The file name of the combined file, defaults to ‘result.csv’
overwrite_existing (bool, optional) – Will overwrite an existing output file if set to True, defaults to False ( append to existing output file)
A result object with status and message.
Combines multiple json formatted text files into a single json list formatted file, where each file is a list entry. Assumes:
each file can contain a single line json formatted string
The new file will be saved into the same folder as the original files.
folder_path (str) – Folder path from which to get files to be combined and to which the combined file will be saved.
file_prefix (str) – Filter: File name starts with this value
file_suffix (str) – Filter: File name ends with this value.
file_extension (str, format '.extension') – Filter: File needs to have this file extension
out_put_file_name (str, optional) – The file name of the combined file, defaults to ‘result.txt’
file_getter (func(folder_path, file_prefix, file_suffix, file_extension), optional) – Function returning list of files to be combined, defaults to GetFilesSingleFolder
Gets a list of alphabetically sorted headers retrieved from text files. Assumes:
first row in each file is the header row
headers are separated by <tab> character
files (list of str) – List of file path from which the headers are to be returned.
List of headers.
list of str
Process a CSV file by removing null bytes and then reading its content.
file_path (str) – The path to the CSV file to be processed.
Read a csv file, attempting to detect and handle encoding, including BOMs.
filepathCSV (str) – The fully qualified file path to the csv file.
A list of list of strings representing the data in each row.
list of list of str
Read a csv file into a list of rows, where each row is another list.
filepathCSV (str) – The fully qualified file path to the csv file.
A list of list of strings representing the data in each row.
list of list of str
Reads the first line of a csv text file and returns it as a list of strings
:param filePath: The fully qualified file path.
:type filePath: str
:return: A Result object, with the result attribute set to True if the first row was retrieved successfully, False otherwise.
:rtype: Result
Function writing out report information as CSV file. :param file_name: The reports fully qualified file path. :type file_name: str :param header: list of column headers :type header: list of str :param data: list of list of strings representing row data :type data: [[str,str,..]] :param write_type: Flag indicating whether existing report file is to be overwritten ‘w’ or appended to ‘a’, defaults to ‘w’ :type write_type: str, optional :param enforce_ascci: Flag to enforce ASCII encoding on data. If True, data will be encoded to ASCII. Defaults to False. :type enforce_ascci: bool, optional :param encoding: Encoding used to write the file. Defaults to ‘utf-8’. :type encoding: str, optional :param bom: the byte order mark, Default is None (none will be written). BOM: “utf-16” = , “utf-16-le” = , utf-8 = :type bom: str, default is NoneType :param quoting: Quoting style used by the csv writer. Defaults to csv.QUOTE_NONE. Options are csv.QUOTE_ALL, csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERIC, csv.QUOTE_NONE :type quoting: int, optional
A Result object, with the result attribute set to True if the file was written successfully, False otherwise.
Get files from a folder filtered by file prefix, file suffix, file extension :param folder_path: Folder path from which to get files. :type folder_path: str :param file_prefix: Filter: File name starts with this value. :type file_prefix: str :param file_suffix: Filter: File name ends with this value. :type file_suffix: str :param file_extension: Filter: File needs to have this file extension :type file_extension: str, format ‘.extension’ :return: A list of all the files matching the supplied filters. :rtype: list str
Returns a list of all files in directory and nested sub directories where file name matches filters value. :param folder_path: Root folder path from which to get files. :type folder_path: str :param file_prefix: Filter: File name starts with this value :type file_prefix: str :param file_suffix: Filter: File name ends with this value. :type file_suffix: str :param file_extension: Filter: File needs to have this file extension :type file_extension: str, format ‘.extension’ :return: A list of all the files matching the supplied filters. :rtype: list str
Returns a list of all files in directory and nested subdirectories where file name matches file extension filter value :param folder_path: Root folder path from which to get files. :type folder_path: str :param file_extension: Filter: File needs to have this file extension :type file_extension: str, format ‘.extension’ :return: A list of all the files matching the supplied filters. :rtype: list str
Returns a dictionary of all files in directory and nested subdirectories where file name contains filter value. - key file name without extension - values: list of directories where this file occurs (based on file name only!) Use case: check for duplicates by file name only
folder_path (str) – Root folder path from which to get files.
file_prefix (str) – Filter: File name starts with this value
file_suffix (str) – Filter: File name ends with this value.
file_extension (str, format '.extension') – Filter: File needs to have this file extension
include_sub_dirs (bool, optional) – If True subdirectories will be included in search for files, defaults to False
A dictionary where the key is the file name without the file extension. Value is a list of fully qualified file path to instances of that file.
dictionary key: str value: lit of str
Gets a list of files from a given folder with a given file extension. (Returns the full path for each file!)
folder_path (str) – Folder path from which to get files to be combined and to which the combined file will be saved.
file_extension (str, optional) – Filter: File needs to have this file extension, defaults to ‘.rvt’
List of file path
list of str
Gets a list of files from a given folder with a given file extension and a matching a file name filter. (Returns the full path for each file!)
folder_path (str) – Folder path from which to get files.
file_extension (str, optional) – Filter: File needs to have this file extension, defaults to ‘.rvt’
filter (str, optional) – File name filter (‘something*’), defaults to ‘*’
List of file path
list of str
Gets all files in directory and nested subdirectories where file name contains filter value.
path (str) – Folder path from which to get files.
filter (str) – File name filter (‘something’)
List of file path
list of str
Checks whether a file exists :param full_file_path: Fully qualified file path :type full_file_path: str :return: True file exists, otherwise False :rtype: bool
Deletes file.
full_file_path (str) – Fully qualified file path
True if deleted, otherwise False
bool
Extracts directory from file path.
file_path (str) – A fully qualified file path.
If no exception occurs : A fully qualified directory path,else an empty string.
str
Renames a file. :param old_name: Fully qualified file path to file to be renamed. :type old_name: str :param new_name: Fully qualified new file name. :type new_name: str :return: True file renamed, otherwise False :rtype: bool
Copies a file :param old_name: Fully qualified file path to file to be copied. :type old_name: str :param new_name: Fully qualified path to new file location and name. :type new_name: str :return: True file copied, otherwise False :rtype: bool
Moves a file :param old_name: Fully qualified file path to file to be moved. :type old_name: str :param new_name: Fully qualified path to new file location and name. :type new_name: str :return: True file moved, otherwise False :rtype: bool
file size in KB conversion
file size in MB conversion
file size in GB conversion
Get the file size in given units (default is MB) :param file_path: Fully qualified file path :type file_path: str :param unit: the file size unit, defaults to FILE_SIZE_IN_MB :type unit: int :return: The file size. :rtype: float
removes ‘../..’ or ‘../’ from relative file path string and replaces it with full path derived path past in sample path. - relative path sample: ‘C:/temp/../myfile.ext’ - full file path sample: ‘C:/temp/Sample/someOtherFile.ext’ - returns: ‘C:/temp/Sample/myfile.ext’ :param relative_file_path: String containing relative file path annotation. :type relative_file_path: str :param full_file_path: A fully qualified file path of which the relative file path is a sub set. :type full_file_path: str :return: A fully qualified file path. :rtype: str
Returns the file name without the file extension.
file_path (str) – Fully qualified file path to file
The file name.
str
Returns the file extension of give file name.
file_path (str) – The file name. Can be just the file name or also the fully qualified file path.
The file extension in format ‘.extension’
str
Reads a text file and returns its content as a single string.
file_path (str) – The fully qualified file path.
The content of a text file.
str
Reads a text file and returns its content as a list of string.
It will return
one string per row
removed line break characters
file_path (str) – The fully qualified file path.
The content of a text file. Can be an empty list if an exception occurred during file read.
[str]
Reads the first line of a text file and returns it as a single string with any leading or trailing white spaces stripped!
file_path (str) – The fully qualified file path.
The first row of a text file.
str
Reads the first line of a text file and returns it as a single string.
Note this may contain a new line character at the end! (”n”)
file_path (str) – The fully qualified file path.
The first row of a text file.
str
Takes a list of revit files or full paths and removes any backup files from the list.
files (list) – List of revit files or full paths
List of revit files or full paths with backup files removed
list
Checks whether a file is a Revit back up file.
Backup files are usually in format ‘filename.01234.ext’
Method of checking:
splitting file name at every full stop
check whether a list with more more then 2 entries came back ?
- no:
not a back up
- yes:
check last list entry whether it is 4 characters in length and can it be convert it into an integer?
- yes:
backup file
- no
normal file
file_path (str) – A fully qualified file path.
True if a back up file, otherwise False.
bool
Remove null bytes from a source txt file and write to a temporary file.
file_path (str) – The path to the original txt file.
temp_file_path (str) – The path to the temporary file where cleaned data is written.
Check if the last character in a file is a newline character.
file_path (str) – The fully qualified file path.
True if the last character is a newline, otherwise False.
bool
Serialize the object for JSON output, using to_json() if available.
obj – The object to serialize.
A dictionary representation of the object.
Serialize the object for JSON output inluding utf 8, using to_json_utf() if available.
obj – The object to serialize.
A dictionary representation of the object.
Writes collected data to a new JSON formatted file.
json_data – A dictionary to be written to file.
data_output_file_path – Fully qualified file path to JSON data file.
enforce_utf8 – Will encode any string value as UTF-8, Default is True (recommended!!).
Result class instance with status and message.
Reads json from file
revit_file_path – Fully qualified file path of report file.
json object
{}
Gets a list of alphabetically sorted headers retrieved from text files. Assumes:
first row in each file is the header row
headers are separated by <tab> character
files (list of str) – List of file path from which the headers are to be returned.
List of headers.
list of str
Function writing out report information.
file_name (str) – The reports fully qualified file path.
header (list of str) – list of column headers
data ([[str,str,..]]) – list of list of strings representing row data
write_type (str, optional) – Flag indicating whether existing report file is to be overwritten ‘w’ or appended to ‘a’, defaults to ‘w’
enforce_ascci (bool, optional) – Flag to enforce ASCII encoding on data. If True, data will be encoded to ASCII. Defaults to False.
encoding (str, optional) – Encoding used to write the file. Defaults to ‘utf-8’.
bom (str, default is NoneType) – the byte order mark, Default is None (none will be written). BOM: “utf-16” = , “utf-16-le” = , utf-8 =
quoting (int, optional) – Quoting style used by the csv writer. Defaults to csv.QUOTE_NONE. Options are csv.QUOTE_ALL, csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERIC, csv.QUOTE_NONE
A Result object, with the result attribute set to True if the file was written successfully, False otherwise.
Read a tab separated text file into a list of rows, where each row is another list. :param file_path: The fully qualified file path to the tab separated text file. :type file_path: str :return: A list of list of strings representing the data in each row. :rtype: list of list of str
This is a decorator factory that returns a decorator that can be used to add logging to a function. Pass this function an instance of the LoggerObject class from duHast.Utilities.Objects.logger_object.py. Inherit and extend this class to the needs of your application. This will connect the decorator to the logger object application wide. Assign the return value to a variable called log or add_logger etc.
log_obj_inst (duHast.Utilities.Objects.logger_object.LoggerObject) – An instance of the LoggerObject class from duHast.Utilities.Objects.logger_object.py
errors_in_console (bool) – Whether to output errors to the console. Defaults to True. Turn off to handle in the application code
A decorator that can be used to add logging to a function
function
Bases: Filter
Filter to stop logs to file handler.
To use change your log call to something like: my_logger.info(“This is a console only output”, extra={“block”: “file”})
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
Determine if the specified record is to be logged.
Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.
Bases: Filter
Filter to stop logs to console handler.
To use change your log call to something like: my_logger.info(“This is a file only output”, extra={“block”: “console”})
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
Determine if the specified record is to be logged.
Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.
Standard output formatting for console and file handlers
Output formatting for presentation
Bases: StreamHandler
Initialize the handler.
If stream is not specified, sys.stderr is used.
Create file handler to obj.log_file_path location
Creates a console handler to output to stdout (console) displaying only the message as default
Sample output without a time stamp:
——————————header——————————
or with a time stamp:
23-04-30 20_31_07 : —————–header————————
how long is a padded row
Pads a header string to be centred in a row of dashes of a given length.
header_name (str) – The header
padding_length (int, optional) – the length of the padded header excluding time stamp, defaults to 70
A padded header row.
str
Pads a header string to be centred in a row of dashes of a given length.
Will also add a time stamp to the beginning of the message.
header_name (str) – The header
padding_length (int, optional) – the length of the padded header excluding time stamp, defaults to 70
A padded header row.
str
Pads a string message to be formatted: left hand side message, right hand side status (if any) Maximum length 70 characters (excludes time stamp!) If message is longer then 70-2 characters it will be returned un-changed.
message (str) – The message to be padded
padding_length (int, optional) – Length of message string after padding, defaults to 70
Padded message
str
List of imports:
Utility
The default install path for solibri ifc optimizer.
Function applying third party IFC optimizer to all ifc files in a given folder.
Original files will be deleted.
Note: Very large IFC files may fail to optimize. (size larger than approx 1.5GB) Those files will be ignored.
directory_path (str) – The directory path where IFC files are located
Result class instance.
Optimizer status returned in result.status. False if an exception occurred, otherwise True.
result.message will contain the fully qualified file path(s) of the optimized file(s).
On exception (handled by optimizer itself!):
result.status (bool) will be False.
result.message will contain generic exception message.
This function will optimize all IFC files in a given list of fully qualified file path to ifc files.
Will check whether Solibri IFC optimizer is installed.
ifc_files (list of str) – List containing fully qualified file path of ifc files to be optimized.
directory_path (str) – Directory of where the optimized IFC file(s) are to be saved.
Result class instance.
Optimizer status returned in result.status. False if an exception occurred, otherwise True.
result.message will contain the fully qualified file path(s) of the optimized file(s).
On exception (handled by optimizer itself!):
result.status (bool) will be False.
result.message will contain generic exception message.
This function will optimize all IFC files in a given list of fully qualified file path to ifc files.
Will not check whether Solibri IFC optimizer is installed.
ifc_files (list of str) – List containing fully qualified file path of ifc files to be optimized.
directory_path (str) – Directory of where the optimized IFC file(s) are to be saved.
Result class instance.
Optimizer status returned in result.status. False if an exception occurred, otherwise True.
result.message will contain the fully qualified file path(s) of the optimized file(s).
On exception (handled by optimizer itself!):
result.status (bool) will be False.
result.message will contain generic exception message.
Retrieves a list of all currently running processes.
a list in format: [[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
list of list
Filters a provided list of processes by process name
processNames (list of str) – List of names to filter by
processList ([[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]) – List of processes running.
returnMatch (bool, optional) – If true only matches will be returned, if false any non matches will be returned, defaults to True
List of processes
[[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
Filters a provided list of processes by process ids
processIds (_type_) – List of ids to filter by
processList ([[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]) – List of processes running
returnMatch (bool, optional) – If true only matches will be returned, if false any non matches will be returned, defaults to True
List of processes
[[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
Kills all processes in list provided
processList ([[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]) – List of processes to be killed.
True if all past in processes have been killed, otherwise False.
bool
Writes out process data to file
directoryPath (str) – The directory path to where the export is being saved.
processList ([[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]) – List of processes to be written to file.
fileName (str) – The file name under which the export is being saved (excluding file extension).
fileExtension (str) – in format ‘.extension’
True if the process data was written to file without an exception, otherwise False.
bool
Converts feet and inches to mm :param value: The value in feet to be converted :type value: float :return: The converted value :rtype: float
Converts square feet and inches to square m
value (float) – The value in square feet to be converted
The converted value
float
Converts cubic feet and inches to cubic m
value (float) – The value in cubic feet to be converted
The converted value
float
Convert a length value in millimeters to imperial feet.
length (float) – A float value representing the length in millimeters.
A float value representing the length in imperial feet.
Removes chevrons and replace colons with underscores in session id supplied by revit batch processor so it can be used in a file name.
id (str) – Session id supplied by revit batch processor.
Re-formatted session id.
str
Re-introduces chevrons and replaces underscores with colons to match session Id format used in batch processor to a file name using a batch processor supplied id.
file_name_id (str) – A file name containing a session id with all illegal characters replaced.
A session id.
str
Removes chevrons and replace colons, full stops, dashes with underscores in session id supplied by revit batch processor so it can be used in a folder name.
id (str) – Session id supplied by revit batch processor.
Re-formatted session id.
str
return directory path to local app data folder
Path to local app data
str
Returns the current user name
the user name
str
Converts a string to lower case and then to bool. Will throw an exception if it fails to do so.
( ‘true’ = True, ‘false’ = False)
text (str) – The string representing a bool.
Exception – If string to bool conversion fails the ‘String cant be converted to bool’ exception will be raised.
True or False
bool
two digit padding
three digit padding
Pads a single digit integer (past in as a string) with a leading zero (default)
numericString (str) – Integer as string.
format (str, optional) – The integer padding format, defaults to PAD_SINGLE_DIGIT_TO_TWO
The padded integer as string.
str
Encode a string as ascii and replaces all non ascii characters
If a non string is past in the value will be returned unchanged.
string (str) – The string to be ascii encoded.
ascii encoded string
str
Encode a string as utf-8 and replaces all non utf-8 characters
If a non string is past in the value will be returned unchanged.
string (str) – The string to be utf-8 encoded.
utf-8 encoded string
str
Returns the first value in a list matching condition. If no value found returns the specified default value.
iterable (iterable) – the list to be searched.
default (var) – The default value
condition (_type_, optional) – The condition to be checked, defaults to lambda x:True
First value matching condition, otherwise default value
var
Gets the index of item in list
list (list) – The list
item (var) – The item of which to return the index.
The index of the item in the list, if no match -1 will be returned
int
helper removes items from a source list
sourceList (list var) – The list containing items
removeIdsList (list var) – the list containing items to be removed
The filtered source list.
list var
Flattens a dictionary as per stack overflow
d (_type_) – _description_
parent_key (str, optional) – _description_, defaults to ‘’
sep (str, optional) – _description_, defaults to ‘_’
_description_
_type_
Function to flatten a nested list
lst (list) – The list to be flattened
The flattened list
list
Get all currently running worksharing monitor processes
_description_
[[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
Writes out all running worksharing monitor processes data to file
directory_path (str) – The directory path to where the marker file is to be saved.
Result class instance.
Export status returned in result.status. False if an exception occurred, otherwise True.
result.message will contain the fully qualified file path of the exported file.
On exception:
result.status (bool) will be False.
result.message will contain the exception message.
Deletes all WSM marker files in a directory.
WSM marker files got a specific file extension: Check: PROCESS_MARKER_FILE_EXTENSION
directory_path (str) – The directory path containing marker files to be deleted.
True if all files where deleted successfully, otherwise False.
bool
Reads all worksharing monitor processes data from marker file(s) in a given directory
WSM marker files got a specific file extension: Check: PROCESS_MARKER_FILE_EXTENSION
directory_path (str) – The directory path to where marker files are to be read from.
list of list of str
[[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
Returns Worksharing monitor process sessions filtered by provided list (not in list)
ws_ms_to_keep (List of list of str in format: [[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]) – List of worksharing monitor sessions to filter by. WSM included in this list will be removed from past in list.
Filtered list of list of str of worksharing monitor sessions
[[HandleCount, Name, Priority, ProcessId, ThreadCount, WorkingSetSize]]
Removes all wsm data marker files in a given directory.
WSM marker files got a specific file extension: Check: PROCESS_MARKER_FILE_EXTENSION.
directory_path (str) – The directory path containing the marker files to be deleted.
Result class instance.
Delete status returned in result.status. False if an exception occurred, otherwise True.
result.message will confirm successful deletion of all files.
On exception:
result.status (bool) will be False.
result.message will contain the exception message.
Kills all worksharing monitor processes currently active.
Unless marker files are used. In that case only worksharing monitor sessions identified in marker files will be killed.
directory_path (str) – The directory path to where marker files are to be read from.
ignore_marker_files (bool, optional) – True no marker file data will be read and all WSM sessions running will be killed., defaults to False
Result class instance.
Kill status returned in result.status. False if an exception occurred, otherwise True.
result.message will confirm successful killing of all WSM processes.
On exception:
result.status (bool) will be False.
result.message will contain the exception message.