Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.Categories package

Subpackages

Submodules

duHast.Revit.Categories.categories module

Revit category helper functions.

duHast.Revit.Categories.categories.CAT_RENAMING = {'Clearance Zones': 'AMAZING'}

subcategory renaming sampled dictionary key is the current subcategory name, value is the new subcategory name

duHast.Revit.Categories.categories.ELEMENTS_PARAS_SUB = [Autodesk.Revit.DB.BuiltInParameter.FAMILY_CURVE_GSTYLE_PLUS_INVISIBLE, Autodesk.Revit.DB.BuiltInParameter.FAMILY_CURVE_GSTYLE_PLUS_INVISIBLE_MINUS_ANALYTICAL, Autodesk.Revit.DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY, Autodesk.Revit.DB.BuiltInParameter.CLINE_SUBCATEGORY]

list of built in parameters attached to family elements containing subcategory ids

duHast.Revit.Categories.categories.get_main_sub_categories(doc)
Returns all subcategories of the family category in a dictionary where key: sub category name

value: sub category

Parameters:

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

Returns:

A dictionary.

Return type:

dictionary {str: Autodesk.Revit.DB.Category}

duHast.Revit.Categories.categories.does_main_sub_category_exists(doc, sub_cat_name)

Checks whether a given subcategory exists in the family.

Note: Only subcategory directly belonging to the family category will be checked for a match.

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

  • sub_cat_name (str) – The name of the subcategory to be checked against.

Returns:

True if subcategory exists in family, otherwise False

Return type:

bool

duHast.Revit.Categories.categories.delete_main_sub_category(doc, sub_cat_name)

Deletes a given subcategory from the family.

Note: Only subcategory directly belonging to the family category will be checked for a match.

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

  • sub_cat_name (str) – The name of the subcategory to be deleted.

Returns:

True if subcategory exists in family and was deleted successfully, otherwise False

Return type:

bool

duHast.Revit.Categories.categories.get_family_category(doc)
Gets the family category in a dictionary where key: category name

value: category

Parameters:

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

Returns:

A dictionary.

Return type:

dictionary {str: Autodesk.Revit.DB.Category}

duHast.Revit.Categories.categories.get_other_sub_categories(doc)

Returns all family subcategories which do not belong to the actual family category.

key: category name value: dictionary : key sub cat name, value: subcategory

Note: custom subcategories have an Id greater 0

Parameters:

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

Returns:

A dictionary.

Return type:

dictionary {str: {str:Autodesk.Revit.DB.Category} }

duHast.Revit.Categories.categories.get_other_custom_sub_categories(doc)

Returns all family custom subcategories which do not belong to the actual family category. Custom categories have an Id greater then 0.

key: category name value: dictionary : key sub cat name, value: subcategory

Note: custom subcategories have an Id greater 0

Parameters:

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

Returns:

A dictionary.

Return type:

dictionary {str: {str:Autodesk.Revit.DB.Category} }

duHast.Revit.Categories.categories.get_other_categories(doc)

Returns all family pre defined categories which do not belong to the actual family category.

Parameters:

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

Returns:

A list of categories.

Return type:

[Autodesk.Revit.DB.Category]

duHast.Revit.Categories.categories.get_category_by_built_in_def_name(doc, built_in_defs)

Returns categories by their built in definition

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

  • built_in_defs ([Autodesk.Revit.DB.BuiltInCategory]) – list of BuiltInCategory Enumeration values

Returns:

list of categories

Return type:

[Autodesk.Revit.DB.Category]

duHast.Revit.Categories.categories.set_family_category(doc, new_category_name)

Changes the family category to new one specified by name. (this will not re-instate any custom sub categories created under the new family category)

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

  • new_category_name (str) – The name of the new family category.

Returns:

True only if the category was changed successfully. Any other case False! (That includes situations when the family is already of the new category)

Return type:

bool

duHast.Revit.Categories.categories_model module

Revit category helper functions for project files.

class duHast.Revit.Categories.categories_model.category_data(category_name, sub_category_name, id)

Bases: tuple

Create new instance of category_data(category_name, sub_category_name, id)

category_name

Alias for field number 0

id

Alias for field number 2

sub_category_name

Alias for field number 1

duHast.Revit.Categories.categories_model.get_categories_in_model(doc)

Returns all categories and subcategories in a model

Parameters:

doc (Autodesk.Revit.DB.Document) – The current model document.

Returns:

List of named tuples of type category_data

Return type:

[category_data]

duHast.Revit.Categories.categories_model.get_category_from_builtInCategory(doc, built_in_category)

Returns a category based on the build in category enum value.

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

  • built_in_category (Autodesk.Revit.DB.BuiltInCategory) – The built in category

Returns:

A category

Return type:

Autodesk.Revit.DB.Category

duHast.Revit.Categories.categories_model.get_builtInCategory_from_category(doc, category)

Returns a built in category enum value based on the category object.

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

  • category (Autodesk.Revit.DB.Category) – The category object

Returns:

The built in category enum value

Return type:

Autodesk.Revit.DB.BuiltInCategory

duHast.Revit.Categories.categories_model.get_category_by_names(doc, main_category_name, sub_category_name)

Retrieves a category object from a document based on the given main category name and optional sub category name.

Args:

doc (document object): The document object from which to retrieve the category. main_category_name (str): The name of the main category to search for. sub_category_name (str): The name of the sub category to search for within the main category.

Returns:

category object: The retrieved category object if a match is found. None: If no match is found.

duHast.Revit.Categories.categories_model.get_builtin_category_by_name(category_name)

Returns the built in category enum value based on the category name.(i.e. OST_Walls)

Parameters:

category_name (str) – The category name

Returns:

The built in category enum value

Return type:

Autodesk.Revit.DB.BuiltInCategory

duHast.Revit.Categories.categories_styles_model module

Revit category graphics helper functions for project files.

duHast.Revit.Categories.categories_styles_model.set_cut_style(doc, category, line_cut_style)

Sets line cut settings for a category object.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – A Revit Document object

  • category (Autodesk.Revit.DB.Category) – A Revit Category object

  • line_patterns ([AutoDesk.Revit.LinePatternElement]) – All line patterns in the model

  • line_cut_style (LineCut) – An overrides projections object instance.

duHast.Revit.Categories.categories_styles_model.get_cut_style(category, line_patterns)

Retrieves line cut settings from a category object.

Parameters:
  • category (Autodesk.Revit.DB.Category) – A Revit Category object

  • line_patterns ([AutoDesk.Revit.LinePatternElement]) – All line patterns in the model

Returns:

An overrides projections object instance.

Return type:

LineCut

duHast.Revit.Categories.categories_styles_model.set_projection_style(doc, category, line_projection_style)

Sets line projection settings for a category object.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – A Revit Document object

  • category (Autodesk.Revit.DB.Category) – A Revit Category object

  • line_patterns ([AutoDesk.Revit.LinePatternElement]) – All line patterns in the model

  • line_projection_style (LineProjection) – An overrides projections object instance.

duHast.Revit.Categories.categories_styles_model.get_projection_style(category, line_patterns)

Retrieves line projection settings from a category object.

Parameters:
  • category (Autodesk.Revit.DB.Category) – A Revit Category object

  • line_patterns ([AutoDesk.Revit.LinePatternElement]) – All line patterns in the model

Returns:

An overrides projections object instance.

Return type:

LineProjection

duHast.Revit.Categories.categories_styles_model.set_category_material_by_material_id(doc, category, material_id)

Sets the material of a category object.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – A Revit Document object

  • category (Autodesk.Revit.DB.Category) – A Revit Category object

  • material_id (int) – The id of the material to be set

duHast.Revit.Categories.categories_styles_model.set_category_style(doc, category_style_source, category_style_target)

Sets category graphics settings for a Revit model.

Parameters:
  • doc (Autodesk.Revit.DB.Document) – A Revit Document object

  • category_style_source ([ObjectStyle]) – A list of category graphics settings

  • category_style_target ([ObjectStyle]) – A list of category graphics settings

Returns:

A result object with the success status and the comparison result

Return type:

Result

duHast.Revit.Categories.categories_styles_model.get_category_styles(doc)

Retrieves all category graphics settings from a Revit model.

Parameters:

doc (Autodesk.Revit.DB.Document) – A Revit Document object

Returns:

A result object with the success status and the category graphics settings

Return type:

Result

duHast.Revit.Categories.categories_styles_model.get_all_used_line_patterns_ids_from_categories(categories)

Retrieves all line pattern ids as integer values from list of category graphics settings.

Parameters:

categories ([ObjectStyle]) – A list of category graphics settings

Returns:

A list of line pattern ids

Return type:

[int]

duHast.Revit.Categories.categories_styles_model.get_not_equal_category_styles(category_styles_1, category_styles_2)

Compares two lists of category graphics settings.

Notes:

  • The comparison is based on the main category name and sub category name.

  • if a style exists in list 1 but not in list 2 it will be reported as an equal style.

  • if a style exists in list 2 but not in list 1 it will not be reported.

Parameters:
  • category_styles_1 ([ObjectStyle]) – A list of category graphics settings

  • category_styles_2 ([ObjectStyle]) – A list of category graphics settings

Returns:

A result object with the success status and the comparison result

. result is a list of dictionaries with the main and sub category names as keys and the category graphics settings from both lists as values.

Return type:

Result

duHast.Revit.Categories.change_family_category module

Revit family change category helper functions.

duHast.Revit.Categories.change_family_category.change_family_category(doc, new_category_name)

Changes the current family category to the new one specified.

Revit’s default behavior when changing the category of a family is to discard all custom subcategories created and assign elements which are on those custom subcategories to the new family category. This function will also re-create any user-created subcategories under the new category and assign elements to them to match the subcategory they were on before the category change.

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

  • new_category_name (str) – The new family category.

Returns:

Result class instance. - result.status (bool): True if all custom subcategories were re-created under the new family category and elements were moved to those subcategories, otherwise False. - result.message (str): Confirmation of successful creation of subcategories and element move. - result.result (list): Empty list.

On exception:
  • result.status (bool): False.

  • result.message (str): Generic exception message.

  • result.result (list): Empty.

Return type:

Result

duHast.Revit.Categories.family_sub_categories module

Revit sub-category helper functions.

duHast.Revit.Categories.family_sub_categories.create_new_sub_category_to_family_category(doc, new_sub_category_name)

Creates a new subcategory to the family category and returns it.

Note: if a subcategory with the name provided already exist it will be returned instead of trying to create another one with the same name.

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

  • new_sub_category_name (str) – The new subcategory name

Returns:

The new subcategory. Exception “The name ‘xys’ is already in use” if subcategory with the same name is already in file.

Return type:

A category. (or str if exception occurred)

duHast.Revit.Categories.family_sub_categories.create_new_category_from_saved_properties(doc, new_cat_name, saved_cat_props, ignore_missing_cut_style=False)

Creates a new category and applies properties stored.

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

  • new_cat_name (str) – The new sub category name.

  • saved_cat_props (list of dictionaries in format as per GetCategoryProperties(cat) method.) – Dictionary containing subcategory properties.

  • ignore_missing_cut_style (bool) – If true will not flag an exception if applying styles fails on missing cut style.

Returns:

Result class instance. - result.status. True if category was created or already existed in file, otherwise False. - result.message will contain the name of the category created. - result.result returns new category, if category already exists in file it will return that On exception: - result.status (bool) will be False. - result.message will contain generic exception message. - result.result will be empty

Return type:

Result

duHast.Revit.Categories.family_sub_categories.create_new_category_and_transfer_properties(doc, new_cat_name, existing_cat_name)

Creates a new subcategory and transfer properties from existing subcategory.

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

  • new_cat_name (str) – The new sub category name.

  • existing_cat_name (str) – The existing subcategory name

Returns:

Result class instance. - result.status. True if category was created or already existed in file, otherwise False. - result.message will contain the name of the category created. - result.result returns new category, if category already exists in file it will return that On exception: - result.status (bool) will be False. - result.message will contain generic exception message. - result.result will be empty

Return type:

Result

duHast.Revit.Categories.family_sub_categories.rename_sub_category(doc, old_sub_cat_name, new_sub_cat_name)

Renames a family custom subcategory.

Note: Only subcategories directly belonging to the family category will be checked for a match.

  • The Revit API currently does not allow changing a subcategory name. This method instead:

  • Duplicates the old subcategory with the new name.

  • Moves all elements belonging to the old subcategory to the new subcategory.

  • Deletes the old subcategory.

  • If the new subcategory already exists in the file:

  • Moves all elements belonging to the old subcategory to the new subcategory.

  • Deletes the old subcategory.

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

  • old_sub_cat_name (str) – The subcategory name to be renamed.

  • new_sub_cat_name (str) – The new subcategory name.

Returns:

Result class instance. - result.status (bool): True if the subcategory was renamed successfully, otherwise False. - result.message (str): Rename process messages. - result.result (list): Empty list.

On exception:
  • result.status (bool): False.

  • result.message (str): Generic exception message.

  • result.result (list): Empty.

Return type:

Result

Module contents