Sample Code Revit Batch Processor 1.1.11 documentation
get_edge_as_string()
UV_pt_list_from_crv_list()
point_in_polygon()
flatten_xyz_point_list()
flatten_xyz_point_list_of_lists()
get_coordinate_system_translation_and_rotation()
get_quadrant()
x_intercept()
adjust_delta()
is_point_within_polygon()
get_signed_polygon_area()
convert_edge_arrays_into_list_of_points()
get_edge_points()
check_duplicate_edge()
check_solid_is_zero_height()
check_edges_are_zero_height()
get_lowest_z_from_solid()
get_lowest_z_from_edges_point_collection()
edges_are_connected()
get_faces_sorted_by_area_from_solid()
pair_faces_by_area()
get_faces_with_lowest_z_from_pairs()
get_unique_horizontal_faces()
is_loop_within_other_loop_but_not_reference_loops()
build_loops_dictionary()
negate_vector()
merge_bounding_box_xyz()
rotate_point_around_z_with_origin()
transform_point_by_elem_transform()
sort_points_by_min_and_max()
get_point_as_doubles()
get_doubles_as_xyz()
get_rotation_around_z_as_xyz()
flatten_xyz_point()
are_points_identical()
check_duplicate_point()
on_which_side_of_line_is_point()
distance_between_two_points()
get_point_as_string()
convert_XYZ_to_point3()
convert_XYZ_to_point2()
convert_point3_to_xyz()
Returns the mark value of an element.
e (Autodesk.Revit.DB.Element) – The element.
The element mark value. If an exception occurred, the message will be ‘Failed with exception: ‘ + the exception string.
str
Convert a list of ElementIds to a semicolon delimited string
element_ids (List[ElementId]) – List of ElementIds
Semicolon delimited string of ElementIds
str
Returns all symbol (type) ids of families which have been placed as legend components and have match in list past in.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
type_ids (list str) – List of typeIds to check against.
Any exception will need to be managed by the function caller.
Values are representing symbol (type) ids of legend components in models filtered by ids past in.
list of str
Returns a list of unique types its similar family (symbol) types.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
type_getter (function) – The function which takes the document as an argument and returns a list of family symbols (types).
Any exception will need to be managed by the function caller.
list of Autodesk.Revit.DB.Symbol and Autodesk.Revit.DB.ElementId:
List [[Autodesk.Revit.DB.ElementType, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,…],]
Compares two lists of types and their similar types (ids).
Assumes that second list past in has only one occurrence of type and its similar types Compares types by name and if match their similar types.
existing_types (List of List in format [[Autodesk.Revit.DB.ElementType , Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,...],]) – Source list
new_type_data (List in format [Autodesk.Revit.DB.ElementType, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.ElementId,...]) – Comparison list
True, if new type is not in list existing Types passed in or if ids of similar family types do not match any similar types already in list
bool
Returns ID of unused family types in the model.
Used in purge code since it leaves at least one type behind (built in families require at least one type in the model)
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
type_getter (func) – Function accepting current document as argument and returning a collector of types in model
instance_getter (func) – Function accepting current document as argument and returning a list of instances in model
List of type ids which can be purged from the model.
list Autodesk.Revit.DB.ElementId
returns a list of unused types foo by comparing type Ids of placed instances with types past in.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
get_types (func (doc)) – Types getter function. Needs to accept doc as argument and return a collector of type foo
get_instances (func(doc)) – Instances getter function. Needs to accept doc as argument and return a collector of instances foo
returns a list of unused types
list of type foo
Filters passed in list of type ids by type ids found in group and returns list of unmatched Id’s
This only returns valid data if at least one instance of the group is placed in the model, otherwise GetMemberIds() returns empty!!
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
group_type (Autodesk.Revit.DB.GroupType) – Group to be checked whether they contains elements of types past in.
type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group
Returns all type ids not matched
list of Autodesk.Revit.Db.ElementId
Checks all elements in groups past in whether group includes element of which type Id is matching any type ids past in
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
group_types (list of Autodesk.Revit.DB.GroupType) – Groups to be checked whether they contains elements of types past in.
type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group
Returns all type ids not matched
list of Autodesk.Revit.Db.ElementId
Checks elements in nested detail groups and detail groups whether their type ElementId is in the list past in.
This only returns valid data if at least one instance of the group is placed in the model!!!
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
type_ids (list of Autodesk.Revit.Db.ElementId) – List of type ids to confirm whether they are in use a group
Returns all type Ids from list past in not found in group definitions
list of Autodesk.Revit.DB.ElementId
This will return a list of all element ids in collector.
Any element in collector which is invalid will be ignored.
col (Autodesk.Revit.DB.FilteredElementCollector) – A filtered element collector.
list of all element ids of valid elements in collector.
List of Autodesk.Revit.DB.ElementId
This class takes as constructor arguments
a number of filter actions
a boolean indicating whether filters are logical and or OR filters
Filter actions checks whether a property matches or does not match provided values. Refer to module: custom_element_filter_actions. The actual property test is undertaken by another function. Samples of those can be found in module custom_element_filter_tests.
Bases: Base
Constructor: This takes a list of element filters and a flag whether this class instance is a logical AND filter (default)
element_filters (list of functions, optional) – List of element filter functions which will need to accept document and elementId as their arguments, defaults to []
is_logical_and_filter (bool, optional) – Flag indicating whether list of filters are logical AND filters or logical OR, defaults to True (logical AND)
Filter checking whether element meets criteria.
This function will loop over all the filters past in through the class constructor and test the element for each filter. Depending on whether these filters are logical and filters it will return True if all of them evaluate to True or, if logical or filter it will return True if one of them evaluates to True, otherwise False will be returned.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be checked against the filter.
True if it matches the filter(s), otherwise False
bool
Thw two action in this module check whether:
a given property does contain / match a set of test value
a given property does not contain / match a set of test value
actions expect:
the test to be performed
the test values to be performed against
an output function to pipe any exception message to
Set up a function checking whether element name contains any of the test values.
Note: If element names does contain any of the test values, the function will return True, Otherwise False.
values ([str]) – List of values the element name may contain.
output (func(message)) – A function piping the string output to a required location.(console…)
Set up a function checking whether element name does not contains any of the test values.
Note: If element names does contain any of the test values, the function will return False, Otherwise True.
values ([str]) – List of values the element name may not contain.
output (func(message)) – A function piping the string output to a required location.(console…)
These tests are used in the custom element filter actions as an argument.
test expects:
the element of which is the test to be performed against
the test value
Check if provided value is in the element name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if part of the element name, otherwise False
bool
Check if provided value is equal to the elements workset name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if elements workset name matches, otherwise False
bool
Check if provided value is part of the elements Family name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if elements family name partly matches, otherwise False
bool
Check if provided value is part of the element type Family name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if elements family name partly matches, otherwise False
bool
Check if provided value is equal to the elements Family name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if elements family name matches, otherwise False
bool
Check if provided value is equal to the element type Family name.
value (str) – test value
element (Autodesk.Revit.DB.Element) – The element
True if elements family name matches, otherwise False
bool
Deletes elements in a list all at once.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
ids (list of Autodesk.Revit.DB.ElementId) – List containing IDs of all elements to be deleted.
transaction_name (str) – The transaction name used for the deletion.
element_name (str) – The element name added to the deletion status message.
Result class instance. - result (bool): True if all elements were successfully deleted, otherwise False. - message (str): Deletion status.
Deletes elements in a list one at a time.
Each element is deleted in its own transaction. If the deletion fails, the transaction is rolled back.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
ids (list of Autodesk.Revit.DB.ElementId) – List containing IDs of all elements to be deleted.
transaction_name (str) – The transaction name used for the deletion.
element_name (str) – The name of the element (not used).
Result class instance. - result (bool): True if all elements were successfully deleted, otherwise False. - message (str): Contains each ID and its deletion status.
header used in reports
Gets all design options in a model,
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Design options in current model
Autodesk.Revit.DB.FilteredElementCollector
Get the active design option in a model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Active design option in current model, or if no design option is active, None
Autodesk.Revit.DB.DesignOption
Returns the design set of the design option.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
design_option (Autodesk.Revit.DB.DesignOption) – a revit design option
A revit design set or None if no design option is active
_type_
Returns the design set of the current active design option.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A revit design set or None if no design option is active
_type_
Gets all the design sets in a model,
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Design sets in the current model
list of Autodesk.Revit.DB.Element
Gets all the design options grouped by design sets in a model,
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A dictionary where key is the Design sets name and value is a list of design options in that set
{str:[Autodesk.Revit.DB.Element]}
Checks whether a design option is the primary option within a design set.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
design_set_name (str) – The name of the design set the option belongs to,
design_option_name (str) – The name of the design option to be checked,
True if this option is primary otherwise False
bool
Get the design set, design option information of an element.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
element (Autodesk.Revit.DB.Element) – The element of which the design set/option data is to be returned.
Dictionary ( for keys refer to DesignSetPropertyNames
)
DesignSetName: (can be either Main Model or the design set name)
designOptionName: Design Option Name (empty string if Main Model
isPrimary: Indicating whether design option is primary (true also if Main Model)
Dictionary designSetName:str designOptionName:str isPrimary:bool
Get the design option ids of all primary options in a model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of design option ids of all primary options in the model.
list of Autodesk.Revit.DB.ElementId
Get the design option ids of all primary options in a model except the one where the design set contains a design option with the filter id.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
filter_Id (Autodesk.Revit.DB.ElementId) – Element Id of the filter.
List of design option ids of all primary options in the model except the one containing the filter id.
list of Autodesk.Revit.DB.ElementId
Checks whether an element is of the built in categories past in. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param element_id: The id of the element to be tested. :type element_id: Autodesk.Revit.DB.ElementId :param builtin_categories: The builtin category the element does needs to match. :type builtin_categories: Autodesk.Revit.DB.Definition :return: True if element’s builtin category does equals the test category, otherwise False. :rtype: bool
Checks whether an element is not of the built in categories past in. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param element_id: The id of the element to be tested. :type element_id: Autodesk.Revit.DB.ElementId :param builtin_categories: The builtin category the element does not needs to match. :type builtin_categories: Autodesk.Revit.DB.Definition :return: True if element’s builtin category does not equals the test category, otherwise False. :rtype: bool
Checks whether the family name of a given family instance matches filter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
family_name (str) – The string the name of the family needs to match.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.
True if family equals the test string, otherwise False.
bool
Checks whether the family name of a given family instance contains filter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
contains_value (str) – The string the name of the family instance is to be tested for.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.
True if family name does contain the test string, otherwise False.
bool
Checks whether the family name of a given family instance does not contains filter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
contains_value (str) – The string the name of the family instance is to be tested for.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.
True if family name does not contain the test string, otherwise False.
bool
Checks whether the family symbol name of a given family instance contains filter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
contains_value (str) – The string the name of the family instance is to be tested for.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.
: True if family name does contain the test string, otherwise False.
bool
Checks whether the family symbol name of a given family instance does not contains filter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
contains_value (string) – The string the name of the family is to be tested for.
element_id (Autodesk.Revit.DB.ElementId) – The id of the element to be tested.
True if symbol name does not contain the test string, otherwise False.
bool
Filter room separation lines by design option id.
doc (Document) – The Revit document.
elements ([]) – A list of Revit elements
design_option_id (Autodesk.Revit.ElementId) – The id of the design option to be filtered by. None will return either all room separation lines from the main model, if include main model is true, and / or all room separation lines from other primary design options.
include_main_model (bool) – Include room separation lines from the main model option.
include_other_primary (bool) – Include room separation lines from other primary design options in the model.
A list of room separation lines filtered by design option id.
list
Helps to suppress warning dialogues in Revit.
Creates a string representation of the information attached to a failure
failure (FailureMessage) – The failure to report
failure_definition (FailureDefinition) – The failure definition
The string representation of the failure information
str
Process the failures encountered when transacting with a Revit document
failures_accessor (FailuresAccessor) – The failures accessor to process
The result of the failure processing
FailureProcessingResult
Function to execute when Revit raises the FailuresProcessing event
Executes an action with Revit failure processing enabled by adding a handler to the FailuresProcessing event. This function will need to be wrapped in a transaction.
app (Application) – The Revit application to execute the action with
action (function) – The action to perform
The result of the action
object
Synchronizes a Revit central file.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
compact_central_file (bool, optional) – option to compact the central file, defaults to False
Result class instance. - .status True if successfully synced file. Otherwise False.
Saves a Revit project file as a workshared file. Save as options are: Workset configuration is : Ask users on open to specify. Any existing file will be overwritten. Number of backups is 5 File will bew compacted on save.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
full_file_name (string) – The fully qualified file path of where to save the file.
Result class instance. - .status True if successfully saved file, otherwise False.
Saves a family file under new name in given location.
doc (Autodesk.Revit.DB.Document) – Current Revit family document.
target_directory_path (str) – The directory path of where to save the file.
current_full_file_name (str) – The current (old) name of the file.
name_data (List of string arrays in format[[oldname, newName]]) – Old name and new name are Revit file names without file extension. Used to rename the family on save from old name to new name.
file_extension (str, optional) – The file extension used for the new file, defaults to ‘.rfa’
compact_file (bool, optional) – Flag whether family is to be compacted on save, defaults to False
.status True if successfully saved file, otherwise False.
Saves a project file under new name in given location.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
target_directory_path (str) – The directory path of where to save the file.
current_full_file_name (str) – The current (old) name of the file.
name_data (List of string arrays in format[[oldname, newName]]) – Old name and new name are revit file names without file extension. Used to rename the model on save from old name to new name.
file_extension (str, optional) – The file extension used for the new file, defaults to ‘.rvt’
Result class instance. - .status True if successfully saved file, otherwise False.
Saves a non workshared Revit file. To be used for families and non workshared revit files only.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
compact_file (bool, optional) – True file will be compacted on save, defaults to False
Result class instance. - .status True if file was saved successfully. Otherwise False. - .message = ‘Saved revit file!’ On exception: - result.status (bool) will be False. - result.message will contain exception message.
Enables worksharing in a non workshared revit project file. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param workset_name_grid_level: _description_, defaults to ‘Shared Levels and Grids’ :type workset_name_grid_level: str, optional :param workset_name: _description_, defaults to ‘Workset1’ :type workset_name: str, optional
Result class instance. - .status True if worksharing was enabled successfully. Otherwise False. - .message = ‘Successfully enabled worksharing.’ On exception: - result.status (bool) will be False. - result.message will contain exception message.
Get all model group types from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
list of model group types in the model
list of Autodesk.Revit.DB.
Get all model group instances in the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
collector of model group instances
Autodesk.Revit.DB.FilteredElementCollector
Get all model group instances in the model grouped by their type id.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Dictionary of model group instances by type id
{ElementId:[Autodesk.Revit.DB.Group]}
Get all elements from group instances in the model.
:
param doc: The Revit document.
:type doc: Document
:param group_names: The names of the groups to get elements from.
:type group_names: list[str]
:return: A list of group instances.
:rtype: list[Autodesk.Revit.DB.Group
]
Gets all detail groups in the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A list containing detail group types.
list
Gets all nested detail groups in the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A list containing nested detail group types.
list
Gets a list of all model group type ids in the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of model group type ids
List of Autodesk.Revit.DB.ElementId
Gets a list of all detail group types from the model.
This will not include any attached detail groups.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of detail group type ids
List of Autodesk.Revit.DB.ElementId
Gets a list of all nested detail group types from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of nested detail group type ids
List of Autodesk.Revit.DB.ElementId
Gets a list of unplaced groups from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
group_category (either BuiltInCategory.OST_IOSDetailGroups or BuiltInCategory.OST_IOSModelGroups) – A built in category defining the group category (model vs detail)
List of unplaced group types
list
Gets a list of unplaced detail groups from the model
This will not include any attached detail groups.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced detail group types
list
Gets a list of unplaced detail groups type Ids from the model.
This will not include any attached detail groups.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced detail group type ids
List of Autodesk.Revit.DB.ElementId
Gets a list of unplaced nested detail groups from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced nested detail group types
list
Gets a list of unplaced nested detail group Ids from the model.
This will not list any none nested detail groups.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced model group type ids
List of Autodesk.Revit.DB.ElementId
Gets a list of unplaced model groups types from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced model group types
list
Gets a list of unplaced model group type Ids from the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of unplaced model group type ids
List of Autodesk.Revit.DB.ElementId
Get all elements from group.
doc (Document
) – The Revit document.
group (Autodesk.Revit.DB.Group
) – The group to get elements from.
A list of elements.
list[Autodesk.Revit.DB.Element
]
Reflection to work out whether a property on a .net object exists (in case it has been removed)
obj (var) – A .net object
property_name (str) – The property name to check for
None if the property does not exist
_type_
Checks a parameter value based on passed in condition function.
This extracts the value of the past in parameter and compares it against a past in value using the also past in compare function. Note that values will be past into compare function as ASCII encoded.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be checked.
para_condition (function) – Function taking 2 arguments: First argument is the value to be checked against Second argument is the actual parameter value Needs to return a bool! Both arguments will be ASCII encoded at passing in.
condition_value (var) – The value to be checked for
Any exception will need to be managed by the function caller.
True if condition value is evaluated to be True by past in function paraCondition. Will return False if compare function returns None or a False.
bool
Used for parameters where the storage type is None
para (_type_) – _description_
Returns a parameter value of type double or integer as string.
para (Autodesk.Revit.DB.Parameter) – The parameter.
String representation of double or integer value. If value is empty it will return None
str or None
Returns a parameter value of type double as a double.
para (Autodesk.Revit.DB.Parameter) – The parameter.
Double value. If value is empty it will return None
Double or None
Returns a parameter value of type double to metric if required. Revit uses feet internally for any length value. Revit uses square feet for areas
para (Autodesk.Revit.DB.Parameter) – The parameter.
Double value. If value is empty it will return None
Double or None
Returns a parameter value of type integer as a integer.
para (Autodesk.Revit.DB.Parameter) – The parameter.
Integer value. If value is empty it will return None
Integer or None
Returns a parameter value of type string as a utf-8 formatted string.
para (Autodesk.Revit.DB.Parameter) – The parameter.
String value. If value is empty it will return None
String or None
Returns a parameter value of type string as a string.
para (Autodesk.Revit.DB.Parameter) – The parameter.
String value. If value is empty it will return None
String or None
Returns a parameter value of type element id as a string.
para (Autodesk.Revit.DB.Parameter) – The parameter.
String value. If value is empty it will return None
String or None
Returns a parameter value of type element id as a element id.
para (Autodesk.Revit.DB.Parameter) – The parameter.
Element id value. If value is empty it will return None
Element id or None
Returns a parameter value of type element id as an integer.
para (Autodesk.Revit.DB.Parameter) – The parameter.
Integer value. If value is empty it will return None
Integer or None
Returns a parameter value in format depending on storage type.
Storage type can be:
Double
Integer
String
ElementId
Will throw an exception if a storage type is not covered by parameter value getter functions.
para (Autodesk.Revit.DB.Parameter) – The Parameter.
parameter_value_getters ({Autodesk.Revit.DB.StorageType: func()}) – Dictionary containing the functions returning the parameter value depending on parameter storage type
The parameter value or if empty: None.
Depends on value getters functions
Returns a parameter value as string independent of its storage type.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.
If an exception occurs the exception message will be returned as the parameter value prefixed with ‘Exception: ‘
Default value is ‘no Value’ if parameter value is empty. Otherwise the actual parameter value. Will return ‘Exception: ‘ + exception message if an exception occurred.
str
Returns the parameter value as utf-8 string independent of its storage type.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.
If an exception occurs the exception message will be returned as the parameter value prefixed with ‘Exception: ‘
Default value is ‘no Value’ if parameter value is empty. Otherwise the actual parameter value. Will return ‘Exception: ‘ + exception message if an exception occurred.
str
Returns the parameter value as integer only if the storage type is integer. Otherwise -1 will be returned.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.
Any exception will need to be managed by the function caller.
Default value is -1 if parameter value is empty or storage type is not integer. Otherwise the actual parameter value.
int
Returns the parameter value as element Id only if the storage type is ElementId. Otherwise InvalidElementId (-1) will be returned.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be returned.
Any exception will need to be managed by the function caller.
Default value is -1 if parameter value is empty or storage type is not integer. Otherwise the actual parameter value.
int
Returns all parameters and their values as using custom value getter associated with provided element in form of a dictionary.
element (var) – The element
parameter_value_getters ({Autodesk.Revit.DB.StorageType: func()}) – Dictionary containing the functions returning the parameter value depending on parameter storage type
Dictionary where key is the parameter name, and the value is the parameter value.
{str:var}
Returns the built-in parameter value. Return value type depends on past in value getter function. Default is UTF-8 encoded string.
element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.
built_in_parameter_def (Autodesk.Revit.DB.Definition) – The parameters built-in definition of which the value is to be returned.
parameter_value_getter (function) – The function which takes the parameter as an argument and returns it’s value.
As per value getter method.
Default value is None if parameter does not exist on element. Otherwise the actual parameter value as per value getter method.
var
Returns the parameter value by parameter name.
Return value type depends on past in value getter function. Default is UTF-8 encoded string.
element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.
parameter_name (str) – The parameters name of which the value is to be returned.
parameter_value_getter (function) – The function which takes the parameter as an argument and returns it’s value.
As per value getter method.
Default value is None if parameter does not exist on element. Otherwise the actual parameter value as per value getter method.
var
Checks if a parameter is empty or null :param param: The parameter to check :type param: Parameter :return: True if the parameter is empty or null, False if it is not :rtype: bool
Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.
Changing a parameter value requires this action to run inside a transaction.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be set.
value_as_string (str) – The new parameter value.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
in_transaction (func(Autodesk.Revit.DB.Transaction, action(), Autodesk.Revit.DB.Document)) – The transaction wrapper function to be used.
Any exception will need to be managed by the function caller.
ToDo: This needs updating for Revit 2022+ to take into account changes in Revit API: Forge Parameters
Result class instance.
Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.
Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.
On exception:
Set parameter.status (bool) will be False.
Set parameter.message will contain the exception message.
Sets the built-in parameter value by trying to convert the past in string representing the value into the appropriate value type.
Changing a parameter value requires this action to run inside a transaction.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
element (Autodesk.Revit.DB.Element) – Element to which the built-in parameter belongs.
built_in_parameter_def (Autodesk.Revit.DB.Definition) – The parameters built-in definition of which the value is to be returned.
value_as_string (str) – The new parameter value.
parameter_value_setter (function) – The function which takes the parameter as an argument and changes it’s value to. The function needs to accept these args: parameter, new parameter value as string, document
As per value setter method.
ToDo: This needs updating for Revit 2022+ to take into account changes in Revit API: Forge Parameters
Result class instance.
Set parameter status (bool) returned in result.status. False if an exception occurred, or parameter does not exist on element, otherwise True.
Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.
On exception:
Set parameter.status (bool) will be False.
Set parameter.message will contain the exception message.
Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.
Changing a parameter value requires this action to run inside a transaction.
para (Autodesk.Revit.DB.Parameter) – Parameter of which the value is to be set.
value_as_string (str) – The new parameter value.
Any exception will need to be managed by the function caller.
Result class instance.
Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.
Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.
On exception:
Set parameter.status (bool) will be False.
Set parameter.message will contain the exception message.
Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.
Changing a parameter value requires this action to run inside a transaction.
element (Autodesk.Revit.DB.Element) – Element of which the parameter value is to be set.
parameter_name (str) – The name of the parameter of which the value is to be set.
parameter_value (any) – The new parameter value.
Result class instance.
Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.
Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.
On exception:
Set parameter.status (bool) will be False.
Set parameter.message will contain the exception message.
Sets the parameter value by trying to convert the past in string representing the value into the appropriate value type.
Changing a parameter value requires this action to run inside a transaction.
element (Autodesk.Revit.DB.Element) – Element of which the parameter value is to be set.
parameter_definition (Autodesk.Revit.DB.BuiltInParameter) – The parameter definition of which the value is to be set.
parameter_value (any) – The new parameter value.
Result class instance.
Set parameter status (bool) returned in result.status. False if an exception occurred, otherwise True.
Result.message property updated in format: Changed parameter value of type x [‘parameter name’] : ‘old value’ to: ‘new value’.
On exception:
Set parameter.status (bool) will be False.
Set parameter.message will contain the exception message.
Returns a dictionary where key is the id and value is the name of the phase.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A dictionary where key is the id and value is the name of the phase. Dictionary will be empty if no phases exist (family doc?)
dic{key Autodesk.Revit.DB.ElementId: value str}
Returns all phases in the order of oldest to newest.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A list of tuples ordered oldest to newest. Tuple properties are: 0 is the phase id and 1 is the phase name.
[(ElementId, str)]
Returns the name of a phase by Id
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
phase_id (Autodesk.Revit.DB.ElementId) – The phase element id.
Name of the phase, otherwise ‘No phase in document’ if no phase exists or ‘Invalid phase id.’ if no phase matching the id was found.
str
Returns a dictionary where key is the name and value is the phase.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A dictionary where key is the name and value is the phase. Dictionary will be empty if no phases exist (family doc?)
dic{key str: value Autodesk.Revit.DB.Phase}
Returns the id of the phase an element was created in.
element (Autodesk.Revit.DB.Element) – A Revit element
Phase id
Autodesk.Revit.DB.ElementId
Returns the id of the phase an element was demolished in.
element (Autodesk.Revit.DB.Element) – A Revit element
Phase id
Autodesk.Revit.DB.ElementId
Builds a dictionary from elementId s past in. Dictionary key is the element category and values are all the elements of that category. If no category can be found the key ‘invalid category’ will be used.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
element_ids (list of AutoDesk.Revit.DB.ElementId) – List of element id of which to build the dictionary from.
Dictionary key is the element category and values are all the elements of that category.
dictionary, key is string, value is list of AutoDesk.Revit.DB.Element
Check if element are orphaned legend components
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
element_ids (list of AutoDesk.Revit.DB.ElementId) – List of elements to check
True if all but one element are orphaned legend components.
bool
Attempts to filter out any warnings from ids supplied by checking the workset name of each element for ‘Reviewable Warnings’
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
dependent_elements (list of AutoDesk.Revit.DB.Element) – List of elements to check.
A list of elements id where the workset name of the element is not ‘Reviewable Warnings’
list of AutoDesk.Revit.DB.Element
Checks whether an element has dependent elements. The dependent elements are collected via Element.GetDependentElements(filter). This also includes a check as to whether elements returned as dependent are orphaned. (for lack of better words)
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
el (AutoDesk.Revit.DB.Element) – The element to be checked for dependent elements.
filter (Autodesk.Revit.DB.ElementFilter , optional) – What type of dependent elements to filter, defaults to None which will return all dependent elements
threshold (int, optional) – The number of how many dependant elements an element can have but still be considered not used, defaults to 2
returns 0 for no dependent elements, 1, for other elements depend on it, -1 if an exception occurred
int
Gets either the used or not used type Ids provided by typeIdGetter. Whether the used or unused type ids depends on the useType value. :param doc: Current Revit model document. :type doc: Autodesk.Revit.DB.Document :param type_id_getter: Function returning type ids :type type_id_getter: list of Autodesk.Revit.DB.ElementId :param use_type: 0, no dependent elements; 1: has dependent elements, defaults to 0 :type use_type: int, optional :param threshold: The number of how many dependant elements an element can have but still be considered not used, defaults to 2 :type threshold: int, optional :return: A list of either all used or unused element ids. Depends on useType. :rtype: list of Autodesk.Revit.DB.ElementId
Returns the revit version as an integer.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Revit version
int
Revit transaction wrapper.
This function is used to execute any actions requiring a transaction in the Revit api. On exception this will roll back the transaction.
tranny (Autodesk.Revit.DB.Transaction) – The transaction to be executed.
doc (Autodesk.Revit.DB.Document) – The current model document. (not used in this function)
action (action().) – The action to be nested within the transaction. This needs to return a Result class instance!
*args –
is just a placeholder in case this function is called with the same args than in_transaction_with_failure_handling
**kwargs –
is just a placeholder in case this function is called with the same args than in_transaction_with_failure_handling
Result class instance.
.status True if successfully executed transaction, otherwise False.
Executes an action within a Revit transaction with Revit failure processing enabled.
Example usage:
def main(revit_doc, foo, bar):
fail_config = FailureHandlingConfig() fail_config.print_warnings = False
- def add_func():
# Perform actions here return foo + bar
trans = Transaction(revit_doc, “Add the things together”) added_vals = in_transaction_with_failures(trans, add_func, fail_config)
transaction (Transaction) – The executing transaction to apply the failure handling to
action (function) – The action to be executed within the transaction
failure_config (FailureHandlingConfig) – Configuration for the failure handling (Optional)
failure_processing_func (function) – The function to process the failures (Optional)
Returns the element id of a workset identified by its name, otherwise invalid Id (-1) if no such workset exists
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
workset_name (str) – The name of the workset of which to retrieve the Element Id
The workset element id, otherwise invalid Id (-1) if no such workset exists
Autodesk.Revit.DB.ElementId
Returns the name of the workset identified by its Element Id, otherwise ‘unknown’ if no such workset exists
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
id_integer (int) – The element id as integer value.
The name of the workset identified by its Id, otherwise ‘unknown’
str
Gets all ids of all user defined worksets in a model
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of all user defined workset element ids
list Autodesk.Revit.DB.ElementId
Returns all user defined worksets in the model as list.
Will return a list of zero length if no worksets in the model.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
List of worksets
list of Autodesk.Revit.DB.Workset
Returns all user defined worksets in the model as collector.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
A filtered elements collector of user defined worksets
Autodesk.Revit.DB.FilteredElementCollector
This is based on a hack from the AutoDesk forum and an article from the building coder:
https://forums.autodesk.com/t5/revit-api-forum/open-closed-worksets-in-open-document/td-p/6238121
https://thebuildingcoder.typepad.com/blog/2018/03/switch-view-or-document-by-showing-elements.html
this method will open worksets in a model containing elements only
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
Attempts to change the worksets of elements provided through an element collector.
Will return false if target workset does not exist in file.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
default_workset_name (str) – The name of the workset the elements are to be moved to.
collector (Autodesk.Revit.DB.FilteredElementCollector) – The element collector containing the elements.
element_type_name (str) – A description used in the status message returned.
Result class instance.
.status = True if successfully moved all elements to new workset. Otherwise False.
.message will contain stats in format [success :: failure]
Contains the required action to change a single elements workset
el (Autodesk.Revit.DB.Element) – The element
default_id (Autodesk.Revit.DB.ElementId) – The workset element Id
Checks whether an element is on a given workset
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
el (Autodesk.Revit.DB.Element) – The element.
workset_id (Autodesk.Revit.DB.ElementId) – The workset element Id
True if element is on given workset, otherwise False
bool
Checks whether an element is on a workset identified by name
el (Autodesk.Revit.DB.Element) – The element
workset_name (str) – The name of the workset
True if element is on given workset, otherwise False
bool
Returns the name of the workset an element is on, or ‘invalid workset’.
el (Autodesk.Revit.DB.Element) – The element.
The name of the workset. If an exception occurred it wil return ‘invalid workset’.
str
Updates the default visibility of worksets based on a workset report file.
The data for the report files is generated by GetWorksetReportData() function in this module
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
report_path (str) – The fully qualified file path to tab separated report text file containing workset data.
revit_file_path (str) – The fully qualified file path of the Revit file. Will be used to identify the file in the report data.
Result class instance.
.status = True if:
successfully updated all workset default visibility where different to report
or none needed updating.
Otherwise False:
An exception occurred.
A workset has no matching data in the report.
Common:
.message will contain each workset and whether it needed updating or not
Creates a workset with a given name in a document.
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
workset_name (str) – The name of the workset to be created
Result class instance.
.status = True if:
successfully created the workset
Otherwise False:
An exception occurred.
A workset with that name already exists.
Document is not workshared
Common:
.message will contain each workset
.result will contain the workset element in a list if successfully created, otherwise an empty list.
deletes a workset given by name
if a move elements to workset name is provided, delete workset settings will be set accordingly
doc (Autodesk.Revit.DB.Document) – Current Revit model document.
delete_workset_name (str) – The name of the workset to be deleted
move_elements_to_workset_name (str (default is None)) – The name of the workset elements to be moved to. If None all elements on the workset will be deleted.
Result class instance.
.status = True if:
successfully deleted the workset
Otherwise False:
An exception occurred.
Revit cant delete the workset with the settings provided.
Document is not workshared
.result will contain an empty list.