Sample Code Revit Batch Processor 1.1.11 documentation
This class provides some utility functions to all child classes:
__repr__() a way of providing detailed debug output through print
to_json() A json formatted dump of the class
Bases: object
Class constructor
Provides a formatted output of all class properties and their values without indentation.
A string representing all class properties and their values
str
formatted output including indentation
indent (int, optional) – The level of indentation, defaults to 0
indent_character (str) – the indentation character used, defaults to “ “
A string representing all class properties and their values
str
Convert the instance of this class to JSON, including public attributes and properties.
A JSON object.
str
Used to convert any properties stored as string to utf-8 in to json conversion of all class properties…
o (_type_) – _description_
_description_
_type_
Convert the instance of this class to json, any string properties are converted to utf-8
A Json object.
json
Returns all class properties and their values as a dictionary
A dictionary of all class properties names and their values
{str:var,}
Bases: object
Contains BOM values for different encodings.
The LoggerObject class is a custom logger class that extends both logging.Logger and Base. It is designed to handle logging with both file and console handlers, providing a structured and formatted logging mechanism.
Key Features: 1. Initialization:
The constructor initializes the logger with a specified name, output path, log levels, file format, and handlers for both file and console logging.
It creates the necessary directories and sets up the log file path.
Handlers are set up with specified formatters and added to the logger.
Methods: - clear_handlers(): Clears all existing handlers from the logger. - init_handlers(): Initializes and adds the file and console handlers to the logger. - get_logger_obj(): Returns the logger object. - update_log_level(log_level): Updates the log levels for both file and console handlers.
Usage: - The class can be used to create a logger that writes logs to a file and outputs them to the console
with specified formats.
It allows dynamic updating of log levels and ensures that handlers are properly managed.
Example Usage:
# Create a logger object logger = LoggerObject(log_name=”myLogger”, output_path=”/path/to/logs”)
# Get the logger object logger_obj = logger.get_logger_obj()
# Update log levels logger.update_log_level((logging.INFO, logging.ERROR))
# Log messages logger_obj.info(“This is an info message”) logger_obj.error(“This is an error message”)
Bases: Logger
, Base
Constructor for the LoggerObject class.
log_name (str) – The name of the log.
output_path (str) – The path to the output directory.
log_level (tuple) – The log levels for the file and console handlers.
file_format (str) – The file format for the log file.
fil_stream_hndlr (class) – The file stream handler class.
fil_stream_frmt (logging.Formatter) – The file stream formatter.
cons_stream_hndlr (class) – The console stream handler class.
cons_stream_frmt (logging.Formatter) – The console stream formatter.
Clears all handlers from the logger.
Initializes the file and console handlers for the logger.
Returns the logger object.
The logger object.
logging.Logger
Set the log levels for the file and console handlers.
log_level (tuple) – A tuple containing the log levels for the file and console handlers.
The updated logger object.
logging.Logger
The Result class is a subclass of the base.Base class and is used to store and manipulate the results of a process. It has fields for message, status, and result, and provides methods to update these fields.
result = Result() # Create a new instance of the Result class result.append_message(“An error occurred”) # Append a new message to the existing message result.update_status(False) # Update the status to False result.update_sep(True, “Process completed successfully”) # Update the status and append a new message print(result) # Print the result object
Initializes the Result object with default values for message, status, and result
Returns a string representation of the Result object, including the formatted message, status, and result
Appends a new line and new message string to the existing message
Updates the Result object using another Result object, updating the message, status, and result
Updates the status and message properties of the Result object
Updates the status property of the Result object
message: A string representing the message of the result status: A boolean representing the status of the result result: A list to store the result items
Bases: Base
Class constructor.
message default value is -
status default value is True
result default value is []
Appends a new line and new message string to the existing message.
First message appended will replace the default value of -
message (str) – The new message to be appended.
Will use the past in result instance to update the instance.
.status is using a logical AND
.message is using append (unless other message is default ‘-‘)
.result is looping over past in result and adding it one by one to this .result list (ignores None)
otherResult (SampleBatchProcessorCode.Result) – Another result class instance.
Updates the .status and .message property only.
.status is using a logical AND
.message is using append (unless other message is default ‘-‘)
status (bool) – The status to be added.
message (str) – The message to be appended.
Update .status only.
.status is using a logical AND
status (bool) – The status to be added.
time output formatting 2 digit padding
time output formatting default 3 digit padding
Bases: Exception
A custom exception used to report errors in use of Timer class
Bases: Base
A class that provides functionality to measure the elapsed time between starting and stopping the timer.
Example Usage:
`python
timer = Timer() # Create a new instance of the Timer class
timer.start() # Start the timer
# Perform some operations
timer.stop() # Stop the timer and get the elapsed time
`
Methods: - __init__(): Initializes a new instance of the Timer class. - start(): Starts a new timer. - stop(): Stops the timer and returns the elapsed time. - is_running(): Checks whether the timer is running.
Initializes a new instance of the Timer class.
Starts a new timer.
TimerError – When the timer is already running.
Stops the timer and returns the elapsed time.
TimerError – When the timer is not running yet.
The elapsed time since the timer has started.
str
Checks whether the timer is running.
True if the timer is running, False otherwise.
bool