Sample Code Revit Batch Processor 1.1.11 documentation
FamilyDataContainer
FamilyDataContainer.add_family_base_data_storage()
FamilyDataContainer.add_category_data_storage()
FamilyDataContainer.add_line_pattern_data_storage()
FamilyDataContainer.add_shared_parameter_data_storage()
FamilyDataContainer.add_warnings_data_storage()
FamilyDataContainer.add_data_storage()
FamilyDataContainer.get_family_base_data_storage_as_string()
FamilyDataContainer.get_family_category_data_storage_as_string()
FamilyDataContainer.get_line_pattern_data_storage_as_string()
FamilyDataContainer.get_shared_parameter_data_storage_as_string()
FamilyDataContainer.get_warnings_data_storage_as_string()
FamilyDataContainer.get_data_string_list()
FamilyDataContainer.get_family_base_data_storage_headers_as_string()
FamilyDataContainer.get_family_category_data_storage_headers_as_string()
FamilyDataContainer.get_line_pattern_data_storage_headers_as_string()
FamilyDataContainer.get_shared_parameter_data_storage_headers_as_string()
FamilyDataContainer.get_warnings_data_storage_headers_as_string()
FamilyDataContainer.get_data_headers_list()
FamilyDataFamily
FamilyDataFamily.compare_name_and_category()
FamilyDataFamily.get_longest_unique_nesting_path()
FamilyDataFamily.process()
FamilyDataFamily.add_data_container()
FamilyDataFamily.add_nested_family_instance()
FamilyDataFamily.get_all_storage_data_as_strings()
FamilyDataFamily.get_all_storage_headers_as_strings()
FamilyDataFamily.has_circular_nesting()
FamilyDirectiveCopy
FamilyDirectiveCopy.COPY_DIRECTIVE_LIST_INDEX_CURRENT_FAMILY_NAME
FamilyDirectiveCopy.COPY_DIRECTIVE_INDEX_FAMILY_FILE_PATH
FamilyDirectiveCopy.COPY_DIRECTIVE_INDEX_CATEGORY
FamilyDirectiveCopy.COPY_DIRECTIVE_LIST_INDEX_NEW_FAMILY_NAME
FamilyDirectiveCopy.COPY_DIRECTIVE_LIST_INDEX_NEW_DIRECTORY
FamilyDirectiveCopy.COPY_DIRECTIVE_FILE_NAME_PREFIX
FamilyDirectiveCopy.COPY_DIRECTIVE_FILE_EXTENSION
FamilyDirectiveCopy.EXCEPTION_NO_COPY_DIRECTIVE_FILES
FamilyDirectiveCopy.EXCEPTION_EMPTY_COPY_DIRECTIVE_FILES
FamilyDirectiveRename
FamilyDirectiveRename.RENAME_DIRECTIVE_LIST_INDEX_CURRENT_FAMILY_NAME
FamilyDirectiveRename.RENAME_DIRECTIVE_INDEX_FAMILY_FILE_PATH
FamilyDirectiveRename.RENAME_DIRECTIVE_INDEX_CATEGORY
FamilyDirectiveRename.RENAME_DIRECTIVE_LIST_INDEX_NEW_FAMILY_NAME
FamilyDirectiveRename.RENAME_DIRECTIVE_FILE_NAME_PREFIX
FamilyDirectiveRename.RENAME_DIRECTIVE_FILE_EXTENSION
FamilyDirectiveRename.EXCEPTION_NO_RENAME_DIRECTIVE_FILES
FamilyDirectiveRename.EXCEPTION_EMPTY_RENAME_DIRECTIVE_FILES
A circular reference is when a family A has a family B nested but family B has also family A nested.
Algorithm description:
read families into data family objects
process them ( to get the internal nesting set up)
get the shortest path from each family
check for duplicates in those paths ( may need to get unique path for name and category!)
Function to find circular references in families.
family_data (list) – list of family data objects
result_list (list of tuples with two entries (0 index the family_data_family object, 1 index list of tuples with two entries in format, 0 index the nesting level as integer at which the circular nesting occurs, 1 index a string in format family name :: family category )) – list to store families with circular references
list of tuples containing family with circular references at 0 and circular family data at 1
Function to check if families have circular references.
family_base_data_report_file_path (str) – path to the family base data report file
result object
A missing family is a family which is not present in the family base data report as a root family but present as a nested family.
Algorithm description:
read base data file processing list
Function to retrieve unique nested families from a list of tuples representing longest unique name nesting path and matching longest unique category nesting path.
path_data (list[(family_name_nesting, family_category_nesting)]) – list of tuples representing longest unique name nesting path and matching longest unique category nesting path
list of tuples containing unique family name and category
list[(family_name, family_category)]
Function to retrieve unique root families from a list of family data objects.
family_data (list[FamilyDataFamily
]) – list of family data objects
list of tuples containing family name and category
list[(family_name, family_category)]
Function to find missing families from a list of root families and nested families.
root_families (list[(family_name, family_category)]) – list of tuples representing root family name and category
nested_families (list[(family_name, family_category)]) – list of tuples representing nested family name and category
list of tuples representing nested family name and category which does not have a matching root family
list[(family_name, family_category)]
Function to retrieve longest unique nesting path data from families.
family_data (list) – list of family data objects
result_list (list[(family, (family_name_nesting, family_category_nesting))]) – list to store longest unique path
list of tuples containing family data object at 0 and longest path at 1 (multiple entries per family possible). Longest path itself is a tuple of family name and category.
Processes a family base data report and identifies any nested families which have not been processed as a root family and therefore do not exist in the library.
family_base_data_report_file_path (str) – Fully qualified file path to family base data report file.
Result class instance.
result.status. True if missing families where found without an exception occurring.
result.message will contain the summary messages of the process including time stamps.
result.result [(nested_family_name, nested_family_category)]
On exception:
result.status (bool) will be False.
result.message will contain generic exception message.
result.result will be empty
Returns a list of FamilyDataFamily instances which represent the direct parents (host families) of the missing families.
families ([FamilyDataFamily
]) – List of family instances
missing_families ([(family name, family category)]) – List of tuples representing the name and category of a family missing (from the library and therefore not presented as root family)
List of family instances which represent the direct parents (host families) of the missing families
Returns a list of FamilyDataFamily instances which represent the direct parents (host families) of the missing families. Only processed root families which have a missing family as a direct nested family are returned. (any root families which contains a missing family nested further down the nesting tree are not returned)
family_base_data_report_file_path (str) – Fully qualified file path to family base data report file.
Result class instance.
result.status. True if host families of missing families where found without an exception occurring.
result.message will contain the summary messages of the process including time stamps.
result.result [FamilyDataFamily
]
On exception:
result.status (bool) will be False.
result.message will contain generic exception message.
result.result will be empty
read change list:
text file (tab separated) with columns:familyName familyFilePath categoryName
read overall family base data list
get direct parents of change list families
get next level parents of direct parents
loop direct parent list until empty:
remove any direct parents which also exist in next level parents
write direct parents to file
set next level parents as direct parents
find all direct parents of changed families in base data list
those reload lists will then be separated into work chunks by file list writer…
Processes a file change list and a family base data report. From both reports it builds a lists for reloading families bottom up in their nesting hierarchy.
change_list_file_path (str) – Fully qualified file path to family change list report file.
family_base_data_report_file_path (str) – Fully qualified file path to family base data report file.
load_lists_output_directory_path (str) – Fully qualified directory path to which the task output files will be written
Exception – “Infinite loop.” Will be raised if more then 20 task output files are written (representing a family nesting level of 20 deep…unlikely)
Reads family base data into two list of named tuples.
root_family:
name
category
filePath
parent
child
nested_family:
name
category
filePath
rootPath [str]
categoryPath [str]
Bases: tuple
Create new instance of root_family(name, category, filePath, parent, child, report_data)
Alias for field number 1
Alias for field number 4
Alias for field number 2
Alias for field number 0
Alias for field number 3
Alias for field number 5
Bases: tuple
Create new instance of nested_family(name, category, filePath, rootPath, categoryPath, hostFamily, report_data)
Alias for field number 1
Alias for field number 4
Alias for field number 2
Alias for field number 5
Alias for field number 0
Alias for field number 6
Alias for field number 3
Reads list of families from family base data report file into named tuples.
file_path (str) – Fully qualified file path to family base data report file.
Exception – “Families base data list files does not exist.”
Exception – “Empty Families base data list file!”
Two lists: first list of named tuples contain family root data, second list contains family nested data.
[root_family], [nested_family]
Reads the first family base data file it finds in a folder. Note: This method calls ReadOverallFamilyDataList(filePath) which will raise exceptions if files are empty or dont exist in specified folder.
directory_path (_str) – A fully qualified directory path containing family base data file(s)
Two lists: first list of named tuples contain family root data, second list contains family nested data.
[root_family], [nested_family]
Reads list of families from family base data report file into named tuples.
file_path (str) – Fully qualified file path to family base data report file.
Exception – “Families base data list files does not exist.”
Exception – “Empty Families base data list file!”
A list contains family nested data.
Reads the first family base data file it finds in a folder. Note: This method calls ReadOverallFamilyIntoNestedDataList(filePath) which will raise exceptions if files are empty or dont exist in specified folder.
directory_path (_str) – A fully qualified directory path containing family base data file(s)
A list contains family nested data.
Reduce base data families for parent / child finding purposes. Keep the nodes with the root path longes branch only.
Sample ( within a single data block)
famA :: famB :: famC FamA :: famB
The second of the above examples can be culled since the path is contained within the first example.
Sample ( across multiple data blocks)
famA :: famB :: famC famB :: famC
The second of the above examples can be culled since the first family (famB) in that sample is already in the first example.(nested Family)
overall_family_base_nested_data (_type_) – _description_
Returns a list of nested families for each root family.
root_families ([root_family]) – A list of tuples containing root family data.
nested_families ([nested_family]) – A list of tuples containing nested family data.
A dictionary where:
key is the root family name and category concatenated and
value is a list of tuples containing nested family data.
{str: [nested_family]}
Returns a list of root families not found in the nested family data set.
In order to reduce the number of families to be processed, this function can be used to find the root families which are not nested into any other family and therefore do contain the longest nesting path.
This is based on two assumptions:
The provided data set contains all families in the project (no missing families are reported)
As soon as a family is nested into another family, its nesting path will appear in the nested family data set and the root family data set.
root_families ([root_family]) – A list of tuples containing root family data.
nested_families ([nested_family]) – A list of tuples containing nested family data.
A list of tuples containing root family data.
Finds the direct hosts of the past in family in the base nested family data set.
nested_fam (nested_family) – A tuple containing nested family data.
overall_family_base_nested_data ([nested_family]) – List of tuples containing nested family data.
A dictionary where:
key is the family name and category concatenated and
value is a tuple in format 0: family name, 1: family category
{str: (str,str)}
Returns a dictionary of all direct host families of families past in.
families ([nested_family]) – A list of tuples containing nested family data.
overall_family_base_nested_data ([nested_family]) – List of tuples containing nested family data.
A dictionary.
{str: (str,str)}
Returns a list of tuples of type root_family matching the past in host families.
host_families ({str: (str,str)}) –
A dictionary where:
key is the family name and category concatenated and
value is a tuple in format 0: family name, 1: family category
overall_family_base_root_data ([root_family]) – List of tuples containing root family data.
List of root family tuples.
Reads family category data into list of named tuples.
root_family:
name
category
filePath
parent
child
subcategories
nested_family:
name
category
filePath
rootPath
categoryPath
hostFamily
subcategories
reads change category directives into list of named tuples:
change_family_category:
filePath
newCategoryName
Bases: tuple
Create new instance of change_family_category(filePath, newCategoryName)
Alias for field number 0
Alias for field number 1
Bases: tuple
Create new instance of change_family_sub_category(familyCategory, oldSubCategoryName, newSubCategoryName)
Alias for field number 0
Alias for field number 2
Alias for field number 1
Bases: tuple
Create new instance of graphic_property_rgb(red, green, blue)
Alias for field number 2
Alias for field number 1
Alias for field number 0
Bases: tuple
Create new instance of graphic_property_line_weight(cut, projection)
Alias for field number 0
Alias for field number 1
Bases: tuple
Create new instance of graphic_property_material(id, name)
Alias for field number 0
Alias for field number 1
alias of graphicProperty
alias of subCategoryProperties
Bases: tuple
Create new instance of sub_category(parentCategoryName, subCategoryName, subCategoryId, usageCounter, usedBy, subCategoryProperties)
Alias for field number 0
Alias for field number 2
Alias for field number 1
Alias for field number 5
Alias for field number 3
Alias for field number 4
Bases: tuple
Create new instance of root_family(name, category, filePath, parent, child, subcategories)
Alias for field number 1
Alias for field number 4
Alias for field number 2
Alias for field number 0
Alias for field number 3
Alias for field number 5
Bases: tuple
Create new instance of nested_family(name, category, filePath, rootPath, categoryPath, hostFamily, subcategories)
Alias for field number 1
Alias for field number 4
Alias for field number 2
Alias for field number 5
Alias for field number 0
Alias for field number 3
Alias for field number 6
dataRGB = graphic_property_rgb(120,120,120) dataLineWeight = graphic_property_line_weight(3,6) dataMaterial = graphic_property_material(-1,’’) dataGraphic = graphic_property_three_d_cut_projection(None,None,None) # combine into a container dataSubPropertiesContainer = sub_category_properties_container (dataRGB, dataLineWeight, dataMaterial, dataGraphic) # set up the actual sub category ( single row in report ) dataSubCatSample = sub_category(‘Parent Cat Name’, ‘subCat name’, 1234, dataSubPropertiesContainer) # set up a root family tuple dataRootFam = root_family(‘root family name’, ‘root family category’, ‘file path’, [], [], [dataSubCatSample]) # set up a nested family tuple dataNestedFam = nested_family(‘nested family name’, ‘nested family category’, ‘file path’, ‘root Path’, ‘category Path’,’host Family data’, [dataSubCatSample])
Reads list of families from family category data report file into named tuples.
file_path (str) – Fully qualified file path to family category data report file.
Exception – “Families category data list files does not exist.”
Exception – “Empty Families category data list file!”
Two lists: first list of named tuples contain family root data, second list contains family nested data.
[root_family], [nested_family]
Reads the first family category data file it finds in a folder. Note: This method calls ReadOverallFamilyDataList(filePath) which will raise exceptions if files are empty or dont exist in specified folder.
directory_path (_str) – A fully qualified directory path containing family category data file(s)
Two lists: first list of named tuples contain family root data, second list contains family nested data.
[root_family], [nested_family]
Reads list of family change category directives from files into named tuples.
file_path ([str]) – List of fully qualified file path to family change category directive file.
Exception – “Families change directive list files do not exist.”
Exception – “Empty Families category data list file!”
List of named tuples contain family category change directive.
Reads all category change directive file it finds in a folder. Note: This method calls ReadOverallFamilyDataList(filePath) which will raise exceptions if files are empty or dont exist in specified folder.
directory_path (_str) – A fully qualified directory path containing family category change directive file(s)
list of named tuples contain family category change directives.
Reads all subcategory change directive file it finds in a folder. Note: This method calls ReadOverallFamilyDataList(filePath) which will raise exceptions if files are empty or dont exist in specified folder.
directory_path (_str) – A fully qualified directory path containing family category change directive file(s)
list of named tuples contain family sub category change directives.
Reads list of family change subcategory directives from files into named tuples.
file_path ([str]) – List of fully qualified file path to family change category directive file.
Exception – _EXCEPTION_NO_FAMILY_SUBCATEGORY_DATA_FILES
Exception – _EXCEPTION_EMPTY_FAMILY_SUBCATEGORY_DATA_FILES
List of named tuples containing family subcategory change directive.
Returns a list of file path of root families containing subcategories requiring a rename.
Note: list of file path returned is unique: i.e. if a family has multiple matches for rename subcategory directives it will still only appear once in the list.
root_families ([root_family]) – List of tuples of root families.
sub_cat_change_directives ([change_family_sub_category]) – List of subcategory change directives.
List of family file path.
[str]
Processes family_data_family objects using multi threading ( testing has shown results in multi threading are not as expected, so single core processing is used for now)
This module provides utility functions to read and write reload task lists for the Revit Batch Processor.
Bases: tuple
Create new instance of changed_family(name, category, filePath)
Alias for field number 1
Alias for field number 2
Alias for field number 0
Writes task list file to disk. File contains single column of fully qualified file path.
reload_families ([baseFamily]) – List of tuples representing families requiring their nested families to be re-loaded.
directory_path (str) – Fully qualified directory path to which the task files will be written.
counter (int, optional) – Task file name suffix, defaults to 0
True if file was written successfully, otherwise False.
bool
Deletes all overall task files in given directory.
directory_path (str) – Fully qualified directory path containing the task files to be deleted.
True if all files got deleted successfully, otherwise False.
bool
Writes out an empty task list in case nothing is to be reloaded.
directory_path (str) – Fully qualified directory path to which the task files will be written.
counter (int, optional) – Task file name suffix, defaults to 0
True if file was written successfully, otherwise False.
bool
Reads list of changed families from file into named tuples.
file_path (str) – Fully qualified file path to change list file.
Exception – “Changed families list files does not exist.”
Exception – “Empty families list file!”
list of named tuples
This helper function expect a folder containing rename directive files. For format of those files refer to module RevitFamilyRenameFilesUtils
Note:
The revit category is not used when renaming files but when renaming nested families.
Any associated type catalogue files will also be renamed to match the new family name.
Rename directives may not have the filePath property set if the directive is only meant to be used on loaded families.
Entry point for this module. Will read rename directives files in given directory and attempt to rename family files and any associated catalogue files accordingly.
Note: for rename directive file structure refer to module family_rename_files_utils
directory_path (str) – Fully qualified directory path to where rename directive files are located.
Result class instance.
result.status. True if files where renamed successfully, otherwise False.
result.message will contain each rename messages in format ‘old name -> new name’.
result.result empty list
On exception:
result.status (bool) will be False.
result.message will contain an exception message.
result.result will be empty
read file rename change list:
text file (tab separated) with columns: currentFamilyName currentFamilyFilePath categoryName newFamilyName
note: current family file path could be blank in situations where just a rename of a nested family is required…
read base data file processing list (created by RevitFamilyBaseDataProcessor module)
extract all root families (no :: in root path)
extract all nested families ( :: in root path)
family at first nesting level is in rename list by name and category
extract root family name and add to identified host family list
loop over root families
find match in identified host families
write out root family date: family file path, family name, category
Finds all host families in data set containing nested families needing to be renamed.
input_directory_path (str) – Fully qualified directory path containing rename directives and family base data report.
Result class instance.
result.status: True if any host families are found with nested families needing renaming, otherwise False.
result.message: processing steps with time stamps
result.result: [rootFamily]
On exception:
result.status (bool) will be False.
result.message will contain an exception message
result.result will be empty
This helper function expect a folder containing rename directive files. For format of those files refer to module family_rename_files_utils.
Entry point for this module. Will read rename directives files in given directory and attempt to rename loaded families accordingly.
Note: for rename directive file structure refer to module family_rename_files_utils
directory_path (str) – Fully qualified directory path to where rename directive files are located.
Result class instance.
result.status. True if a single families was renamed successfully, otherwise False.
result.message will contain each rename messages in format ‘Renamed family from :’ +current Name + ‘ to ‘ + newName.
result.result empty list
On exception:
result.status (bool) will be False.
result.message will contain an exception message in format: ‘Failed to rename family from :’ + currentName + ‘ to ‘ + newName
result.result will be empty
Retrieves the storage data as list of strings sorted by storage type.
family_data ([FamilyDataFamily
]) – List of family instances.
A dictionary where the key is the storage data type, and value is a nested list of lists of strings representing the storage data.
{str:[[str]]}
Gets the storage property (report) headers
family_data ([FamilyDataFamily
]) – List of family instances.
A dictionary where the key is the storage data type, and value is a nested list of lists of strings representing the storage data property names.
{str:[[str]]}
Writes family data retrieved from report files back to file.
family_data ([FamilyDataFamily
]) – List of family instances
directory_path (str) – Fully qualified directory path to write report files to.
TypeError – family_data needs to be a list.
TypeError – directory_path needs to be a string.
ValueError – Directory: xyz does not exist.
ValueError – Failed to get any storage data from family data past in.
Result class instance.
result.status: Write report files status returned in result.status. False if an exception occurred, otherwise True.
result.message: Will contain the fully qualified file path of each of report files written.
result.result: Will be a fully qualified file path of each file written.
On exception
Reload.status (bool) will be False
Reload.message will contain the exception message
Convert the data rows into the target type of data storage object.
data_rows (list) – The data rows to be converted into the target type of data storage object.
target_type (IFamilyDataStorage) – The target type of data storage object to convert the data rows into.
A Result object containing the list of IFamilyDataStorage objects if successful.
Read the data from the file and return a list of IFamilyDataStorage objects.
file_path (str) – The path to the file to read the data from.
data_type (IFamilyDataStorage) – The type of data storage the file data is to be converted to.
A Result object containing the list of IFamilyDataStorage objects if successful.
Read the family base data from the file and return a list of FamilyBaseDataStorage objects.
file_path (str) – The path to the file to read the data from.
A Result object containing the list of FamilyBaseDataStorage objects if successful.
Read the family category data from the file and return a list of FamilyCategoryDataStorage objects as part of a result object
file_path (str) – The path to the file to read the data from.
A Result object containing the list of FamilyCategoryDataStorage objects if successful.
Read the family line pattern data from the file and return a list of FamilyLinePatternDataStorage objects as part of a result object
file_path (str) – The path to the file to read the data from.
A Result object containing the list of FamilyLinePatternDataStorage objects if successful.
Read the family shared parameter data from the file and return a list of FamilySharedParameterDataStorage objects as part of a result object
file_path (str) – The path to the file to read the data from.
A Result object containing the list of FamilySharedParameterDataStorage objects if successful.
Read the family warnings data from the file and return a list of FamilyWarningsDataStorage objects as part of a result object
file_path (str) – The path to the file to read the data from.
A Result object containing the list of FamilyWarningsDataStorage objects if successful.
Get all csv files in directory provided and attempts to read them into varies lists of data storage objects:
FamilyBaseDataStorage
FamilyCategoryDataStorage
FamilyLinePatternDataStorage
FamilySharedParameterDataStorage
FamilyWarningsDataStorage
These are then added to a family container object and returned. The family container object contains all storage instances of a specific root or nested family identified by a unique family name nesting path + family category nesting path
Note: The content of multiple csv files of the same data type will be combined into a single list of objects.
path_to_data – The path to the directory containing the csv files or fully qualified file path to a single data file.
A Result object containing the list of Family Containers objects if successful.
Result (list of FamilyDataContainer)
Read the data from the csv files in the directory and return a list of FamilyDataFamily objects.
path_to_data (str) – The path to the directory containing the csv files or fully qualified file path to single report csv file.
A Result object containing the list of FamilyDataFamily objects if successful.
Result (list of FamilyDataFamily)
This combines family reports:
reading reports into FamilyDataFamily instances
adding any new families found in the new reports
adding previous report families not found in new report families
This function checks at the end whether families still exist on file server. If not, they will be removed from the data set.
previous_report_path (str) – A fully qualified file path to the previous report file.
new_report_path (str) – A fully qualified file path to the new report file.
Result class instance.
.status True if successfully combined report(s). Otherwise False.
.message will contain count of new families added and previous families retained.
. result will contain list of FamilyDataFamily instances representing the combined data set
On exception:
result.status (bool) will be False.
result.message will contain generic exception message.
result.result will be empty
Reads family base data into two list of named tuples.
rootFamily:
name
category
filePath
nestedFamily:
name
category
filePath
rootPath [str]
categoryPath [str]
Bases: tuple
Create new instance of rootFamily(name, category, filePath)
Alias for field number 1
Alias for field number 2
Alias for field number 0
Bases: tuple
Create new instance of nestedFamily(name, category, filePath, rootPath, categoryPath)
Alias for field number 1
Alias for field number 4
Alias for field number 2
Alias for field number 0
Alias for field number 3
This combines two reports by:
building an aggregate data dictionary of each report (key root family file path, values lists containing the row data read from file for the root family as well as any nested families)
adding any new families found in the new report dictionary
updating any previous report families found with data matching the root family in the new report dictionary
All reports start with the following 2 columns: root rootCategory
First entry (after split at separator) in each of these columns identifies root family uniquely. Assume that new report only ever adds or substitutes entries in previous report but does not delete from it!
This function checks at the end whether families still exist on file server. If not, they will be removed from the data set.
previous_report_path (str) – A fully qualified file path to the previous report file.
new_report_path (str) – A fully qualified file path to the new report file.
list of lists of report rows
[[str]]