Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.Family.Data.Objects package

Submodules

duHast.Revit.Family.Data.Objects.family_base_data module

Family base data class.

class duHast.Revit.Family.Data.Objects.family_base_data.FamilyBaseData(root_path=None, root_category_path=None)

Bases: IFamilyData

Class constructor

Parameters:
  • rootPath (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • rootCategoryPath (str) – The path of the family category in a tree: rootCategoryName :: nestedCategoryNameOne :: nestedCategoryTwo This includes the actual category name as the last node.

process(doc, reference_file_path, family_out_directory_path, session_id)

Collects all base data from the document and stores it in the class property .data

Parameters:

doc (Autodesk.Revit.DB.Document) – Current family document

get_data()
add_data(storage_instance)

duHast.Revit.Family.Data.Objects.family_base_data_processor module

Family base data processor class.

class duHast.Revit.Family.Data.Objects.family_base_data_processor.FamilyBaseProcessor(reference_file_path=None, family_out_directory_path=None, session_id=None, pre_actions=None, post_actions=None)

Bases: IFamilyProcessor

Class constructor.

data_type = 'FamilyBaseProcessor'
process(doc, root_path, root_category_path)

Calls processor instance with the document and root path provided and adds processor instance to class property .data

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current family document.

  • rootPath (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • rootCategoryPath (str) – The path of the nested family in in terms of category in a tree: rootFamilyCategory :: nestedFamilyOneCategory :: nestedFamilyTwoCategory This includes the actual family category as the last node.

duHast.Revit.Family.Data.Objects.family_base_data_processor_defaults module

Family base data default names.

duHast.Revit.Family.Data.Objects.family_base_data_storage module

Class for family base data storage class.

class duHast.Revit.Family.Data.Objects.family_base_data_storage.FamilyBaseDataStorage(root_name_path, root_category_path, family_name, family_file_path, **kwargs)

Bases: IFamilyDataStorage

Class constructor

data_type = 'FamilyBase'
number_of_properties = 5

duHast.Revit.Family.Data.Objects.family_base_data_storage_used_by module

Class for family base data used by storage class.

Notes:

This is just for completeness, the class is not used in the current version of the software.

class duHast.Revit.Family.Data.Objects.family_base_data_storage_used_by.FamilyBaseDataStorageUsedBy(data_type, family_name, element_id, **kwargs)

Bases: IFamilyDataStorageUsedBy

Class constructor

data_type = 'FamilyBaseDataStorageUsedBy'

duHast.Revit.Family.Data.Objects.family_data_collector module

Family data collector class.

  • Collects data from current family document and then recursively from any nested family.

class duHast.Revit.Family.Data.Objects.family_data_collector.RevitFamilyDataCollector(data_processors)

Bases: Base

Class constructor taking a list of processor instances as argument.

Parameters:

data_processors ([IFamilyProcessor]) – List of processor instances

process_family(doc, root_name, root_category)

Entry point for recursive family looper.

Processes root family as well as actions any post processing.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – The family document.

  • root_name (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • root_category (str) – The path of the nested family category in a tree: rootFamilyCategory :: nestedFamilyOneCategory :: nestedFamilyTwoCategory This includes the actual family category as the last node.

Returns:

Result class instance.

  • .status True if all data processor instances ran without an exception. Otherwise False.

  • .message will contain each processor type and its processing status’

Return type:

Result

duHast.Revit.Family.Data.Objects.family_data_container module

Family data container class.

  • contains all instances of the following storage classes from reports read from files:

    • FamilyBaseDataStorage

    • CategoryDataStorage

    • WarningsDataStorage

    • LinePatternDataStorage

    • SharedParameterDataStorage

  • These storage instances belong to a specific family only identified by unique combination of family name nesting path and family category nesting path

class duHast.Revit.Family.Data.Objects.family_data_container.FamilyDataContainer(family_base_data_storage=None, category_data_storage=None, line_pattern_data_storage=None, shared_parameter_data_storage=None, warnings_data_storage=None, **kwargs)

Bases: Base

Family data container class.

Contains all instances of the following storage classes from reports read from files:

  • FamilyBaseDataStorage

  • CategoryDataStorage

  • WarningsDataStorage

  • LinePatternDataStorage

  • SharedParameterDataStorage

Note: There is the possibility that only one of the storage classes is populated, this is due to the fact that the data is read from separate files and not all data is always present in each file.

Parameters:
Raises:

ValueError – type mismatch if any of the past in lists are not of the correct type

add_family_base_data_storage(other)

Will add a family base data storage instance and infer some other class properties from it.

Note: if storage data properties root_name_path and root_category_path are different to the current values all other storage properties will be wiped to avoid mismatches!

Parameters:

other (FamilyBaseDataStorage) – A family base data storage instance added to this class

Raises:

TypeError – If other is not an instance of FamilyBaseDataStorage a type error will be raised.

add_category_data_storage(other)

Will add a category data storage instance.

Note: an exception will be raised if family_nesting_path and family_category_nesting_path do not match the current values!

Parameters:

other (FamilyCategoryDataStorage) – a data storage instance

Raises:

TypeError – If other is not an instance of FamilyCategoryDataStorage a type error will be raised.

add_line_pattern_data_storage(other)

Will add a line pattern data storage instance.

Note: an exception will be raised if family_nesting_path and family_category_nesting_path do not match the current values!

Parameters:

other (FamilyLinePatternDataStorage) – a data storage instance

Raises:

TypeError – If other is not an instance of FamilyLinePatternDataStorage a type error will be raised.

add_shared_parameter_data_storage(other)

Will add a shared parameter data storage instance.

Note: an exception will be raised if family_nesting_path and family_category_nesting_path do not match the current values!

Parameters:

other (FamilySharedParameterDataStorage) – a data storage instance

Raises:

TypeError – If other is not an instance of FamilySharedParameterDataStorage a type error will be raised.

add_warnings_data_storage(other)

Will add a warnings data storage instance.

Note: an exception will be raised if family_nesting_path and family_category_nesting_path do not match the current values!

Parameters:

other (FamilyWarningsDataStorage) – a data storage instance

Raises:

TypeError – If other is not an instance of FamilyWarningsDataStorage a type error will be raised.

add_data_storage(other)

Adds a new data storage instance to this container.

Parameters:

other (IFamilyDataStorage) – The new data storage instance.

Raises:

TypeError – If other is not an instance of IFamilyDataStorage a type error will be raised.

get_family_base_data_storage_as_string()

Returns all family base data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage instance

Return type:

{str:[[str]]}

get_family_category_data_storage_as_string()

Returns all family category data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage instance

Return type:

{str:[[str]]}

get_line_pattern_data_storage_as_string()

Returns all family line pattern data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage instance

Return type:

{str:[[str]]}

get_shared_parameter_data_storage_as_string()

Returns all family shared parameter data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage instance

Return type:

{str:[[str]]}

get_warnings_data_storage_as_string()

Returns all family warnings data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage instance

Return type:

{str:[[str]]}

get_data_string_list()

returns a dictionary where key is the storage data type and value is a list of string representing the data storage

get_family_base_data_storage_headers_as_string()

Returns all family base data instance storage property as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage property name

Return type:

{str:[[str]]}

get_family_category_data_storage_headers_as_string()

Returns all family category data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage property name

Return type:

{str:[[str]]}

get_line_pattern_data_storage_headers_as_string()

Returns all family line pattern data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage property name

Return type:

{str:[[str]]}

get_shared_parameter_data_storage_headers_as_string()

Returns all family shared parameter data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage property name

Return type:

{str:[[str]]}

get_warnings_data_storage_headers_as_string()

Returns all family warnings data instance storage as string

Returns:

A dictionary where key is the storage data type, and value is a nested list of strings representing each storage property name

Return type:

{str:[[str]]}

get_data_headers_list()

returns a dictionary where key is the storage data type and value is a nested list of list of string representing the data storage property names

Returns:

Dictionary

Return type:

{str:[[str]]}

duHast.Revit.Family.Data.Objects.family_data_family module

Family data class.

  • contains:

    • an entire family nesting tree structure represented as other FamilyDataFamily instances

    • all FamilyDataContainer instances belonging to this family only ( identified by unique combination on family name nesting path and family category nesting path )

class duHast.Revit.Family.Data.Objects.family_data_family.FamilyDataFamily(family_name=None, family_category=None, family_file_path=None, family_nesting_path=None, family_category_nesting_path=None, is_root_family=False, nested_families=None)

Bases: Base

Family data class.

  • contains an entire family nesting tree structure represented as family data container instances

Parameters:
  • family_name (str) – The name of the family.

  • family_category (str) – The Revit category of the family.

  • family_file_path (str) – The file path of the family.

compare_name_and_category(other)

Compares family_name and family_category properties only

Parameters:

other (FamilyDataFamily) – Another FamilyDataFamily instance

Returns:

True if family_name and family_category are equal otherwise false

Return type:

bool

get_longest_unique_nesting_path()

Get the longest unique family name nesting path(s) and family category nesting path(s) of the family data.

Returns:

The longest unique nesting path as a list of tuples, or None if family is not processed.

Return type:

list[(family_name_nesting, family_category_nesting)] or None

process()

Process the family data.

  • build the nesting by name path

  • build the nesting by level

add_data_container(data_container)

Add a data container to the family data.

add_nested_family_instance(nested_family_instance)

Add a nested family instance.

Parameters:

nested_family_instance (FamilyDataFamily) – The family instance to be added

Raises:

TypeError – If nested_family_instance is not an instance of FamilyDataFamily a type error will be raised.

get_all_storage_data_as_strings()

Returns the data storage within each storage container within this family as well as within the nested families as a a list of string.

Returns:

A dictionary where key is the data storage type, and value is a nested list of lists containing the data storage string value

Return type:

{key:[[str]]}

get_all_storage_headers_as_strings()

Returns all property names used in storage instances in containers within this family and any nested families.

Returns:

A dictionary where key is the data storage type, and value is a list containing the data storage properties as string values

Return type:

{key:[[str]]}

has_circular_nesting()

Check if the family data has circular nesting.

Circular nesting is defined as a situation where a nesting path property of a container contains the same family more than once.

returns a list of tuples in format:

  • 0 index the nesting level at which the circular nesting occurs

  • 1 index a string in format: family name :: family category

  • 2 the entire family name nesting path this circular reference appeared on

duHast.Revit.Family.Data.Objects.family_directive_base module

Base Class for family directive classes.

class duHast.Revit.Family.Data.Objects.family_directive_base.FamilyDirectiveBase(name, category)

Bases: Base

Class constructor

duHast.Revit.Family.Data.Objects.family_directive_copy module

Class for family rename directives.

class duHast.Revit.Family.Data.Objects.family_directive_copy.FamilyDirectiveCopy(name, category, source_file_path, target_directory, new_name)

Bases: FamilyDirectiveBase

Class constructor

COPY_DIRECTIVE_LIST_INDEX_CURRENT_FAMILY_NAME = 0
COPY_DIRECTIVE_INDEX_FAMILY_FILE_PATH = 1
COPY_DIRECTIVE_INDEX_CATEGORY = 2
COPY_DIRECTIVE_LIST_INDEX_NEW_FAMILY_NAME = 3
COPY_DIRECTIVE_LIST_INDEX_NEW_DIRECTORY = 4
COPY_DIRECTIVE_FILE_NAME_PREFIX = 'CopyDirective'
COPY_DIRECTIVE_FILE_EXTENSION = '.csv'
EXCEPTION_NO_COPY_DIRECTIVE_FILES = 'Copy directive file does not exist.'
EXCEPTION_EMPTY_COPY_DIRECTIVE_FILES = 'Empty copy directive file!'

duHast.Revit.Family.Data.Objects.family_directive_rename module

Class for family rename directives.

class duHast.Revit.Family.Data.Objects.family_directive_rename.FamilyDirectiveRename(name, category, file_path, new_name)

Bases: FamilyDirectiveBase

Class constructor

RENAME_DIRECTIVE_LIST_INDEX_CURRENT_FAMILY_NAME = 0
RENAME_DIRECTIVE_INDEX_FAMILY_FILE_PATH = 1
RENAME_DIRECTIVE_INDEX_CATEGORY = 2
RENAME_DIRECTIVE_LIST_INDEX_NEW_FAMILY_NAME = 3
RENAME_DIRECTIVE_FILE_NAME_PREFIX = 'RenameDirective'
RENAME_DIRECTIVE_FILE_EXTENSION = '.csv'
EXCEPTION_NO_RENAME_DIRECTIVE_FILES = 'Rename directive file does not exist.'
EXCEPTION_EMPTY_RENAME_DIRECTIVE_FILES = 'Empty rename directive file!'

duHast.Revit.Family.Data.Objects.family_type_data module

Family type data class.

class duHast.Revit.Family.Data.Objects.family_type_data.FamilyTypeData(root_path=None, root_category_path=None)

Bases: IFamilyData

Class constructor

Parameters:
  • rootPath (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • rootCategoryPath (str) – The path of the family category in a tree: rootCategoryName :: nestedCategoryNameOne :: nestedCategoryTwo This includes the actual category name as the last node.

process(doc, session_id)

Collects all base data from the document and stores it in the class property .data

Parameters:

doc (Autodesk.Revit.DB.Document) – Current family document

get_data()
add_data(storage_instance)

duHast.Revit.Family.Data.Objects.family_type_data_processor module

Family type data processor class.

class duHast.Revit.Family.Data.Objects.family_type_data_processor.FamilyTypeProcessor(session_id=None, pre_actions=None, post_actions=None)

Bases: IFamilyProcessor

Class constructor.

data_type = 'FamilyTypeProcessor'
process(doc, root_path, root_category_path)

Calls processor instance with the document and root path provided and adds processor instance to class property .data

Parameters:
  • doc (Autodesk.Revit.DB.Document) – Current family document.

  • rootPath (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • rootCategoryPath (str) – The path of the nested family in in terms of category in a tree: rootFamilyCategory :: nestedFamilyOneCategory :: nestedFamilyTwoCategory This includes the actual family category as the last node.

duHast.Revit.Family.Data.Objects.family_type_data_processor_defaults module

Family type data default names.

duHast.Revit.Family.Data.Objects.family_type_data_storage module

Class for family type data storage class.

class duHast.Revit.Family.Data.Objects.family_type_data_storage.FamilyTypeDataStorage(root_name_path, root_category_path, family_name, family_file_path, family_type_name, parameters, last_updated_date=None, last_updated_time=None, **kwargs)

Bases: IFamilyDataStorage

Class constructor

data_type = 'FamilyType'
number_of_properties = 5

duHast.Revit.Family.Data.Objects.family_type_parameter_data_storage module

Class for family parameter data storage class.

Used to store values of family parameters by family type.

class duHast.Revit.Family.Data.Objects.family_type_parameter_data_storage.FamilyTypeParameterDataStorage(name, type, type_of_parameter, units, value)

Bases: Base

Class constructor

data_type = 'FamilyTypeParameter'
number_of_properties = 5

duHast.Revit.Family.Data.Objects.ifamily_action module

Interface for family data storage / processing class.

class duHast.Revit.Family.Data.Objects.ifamily_action.IFamilyAction(action_type, **kwargs)

Bases: Base

Class constructor

process(doc)
get_data()

duHast.Revit.Family.Data.Objects.ifamily_data module

Interface for family data storage / processing class.

class duHast.Revit.Family.Data.Objects.ifamily_data.IFamilyData(root_path, root_category_path=None, data_type=None, **kwargs)

Bases: Base

Class constructor

process(doc)
get_data()
get_root_storage()

Get the root storage objects.

Returns:

The IFamilyDataStorage objects referring to the root family.

Return type:

list

get_property_names()

Get the property names of the storage object.

Returns:

The property names.

Return type:

list

update_data(identify_by_this_property_name, identify_by_this_property_value, update_dic)
add_data()

duHast.Revit.Family.Data.Objects.ifamily_data_storage module

Interface for family data storage class.

Notes:

  • any revit specific data types i.e. ElementId need to be converted to int or string for JSON to work and in order for these classes to be used outside the Revit API!

  • any string values need to be encoded to utf-8 and decoded back to utf-8 to avoid encoding issues

class duHast.Revit.Family.Data.Objects.ifamily_data_storage.IFamilyDataStorage(data_type, root_name_path, root_category_path, family_name, family_file_path, **kwargs)

Bases: Base

Class constructor

update_usage(other_storage)

Update the usage of this storage object with the usage of another storage object by:

  • adding the use counter of the other storage object to this storage object’s use counter

  • appending the root name path of the other storage object to this storage object’s used_by list

get_data()

Get the data from the object als dictionary.

Note data type fixing is applied to:

  • ElementIds

  • System.Byte values

get_data_values_as_list_of_strings()
get_property_names()
to_json()

Convert the instance of this class to json.

Returns:

A Json object.

Return type:

json

duHast.Revit.Family.Data.Objects.ifamily_data_storage_used_by module

Interface for family data storage used by class.

Notes:

used to store used by other nested families data in root family data storage class.

class duHast.Revit.Family.Data.Objects.ifamily_data_storage_used_by.IFamilyDataStorageUsedBy(data_type, family_name, element_id, j, **kwargs)

Bases: Base

Class constructor

duHast.Revit.Family.Data.Objects.ifamily_processor module

Interface for family processing class.

class duHast.Revit.Family.Data.Objects.ifamily_processor.IFamilyProcessor(data_type=None, pre_actions=None, post_actions=None, **kwargs)

Bases: Base

Class constructor

data_type_header = 'Data Type'
pre_process_actions(doc)

Actions any pre processing before family data will be collected.

Parameters:

doc (Autodesk.Revit.DB.Document) – The family document.

Returns:

_description_

Return type:

_type_

process(doc, root_path, root_category_path)

Gather data on the root family and any nested families

Parameters:
  • doc (Autodesk.Revit.DB.Document) – The family document.

  • root_path (str) – The path of the nested family in a tree: rootFamilyName :: nestedFamilyNameOne :: nestedFamilyTwo This includes the actual family name as the last node.

  • root_category_path (str) – The path of the nested family category in a tree: rootFamilyCategory :: nestedFamilyOneCategory :: nestedFamilyTwoCategory This includes the actual family category as the last node.

post_process_actions(doc)

Actions any post processing after family data has been collected.

Parameters:

doc (Autodesk.Revit.DB.Document) – The family document.

get_data()

Returns list of data storage instances.

Returns:

List of iFamilyStorage instances.

Return type:

[iFamilyStorage]

get_data_json()

Returns data objects as JSON formatted strings.

Returns:

JSON formatted string.

Return type:

str

get_data_string_list()

Returns data storage objects as nested list of strings, where each inner list represents the values of a data storage object.

  • Strings are UTF 8 encoded

Returns:

list of list of strings.

Return type:

[str]

get_data_headers()

Returns the headers of the data storage objects.

Returns:

list of strings.

Return type:

[str]

Module contents