Sample Code Revit Batch Processor 1.1.11 documentation

Contents:

This Page

duHast.Revit.Grids package

Subpackages

Submodules

duHast.Revit.Grids.grids module

Revit grids helper functions.

duHast.Revit.Grids.grids.get_grids_in_model(doc)

Get all grids in model

Parameters:

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

Returns:

A collector with all grids in model.

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_multi_segmented_grids(doc)

Get all multi segmented grids in model

Parameters:

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

Returns:

A collector with all multi segmented grids in model.

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_grids_in_view(doc, view)

Get all grids in a view

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

  • view (Autodesk.Revit.DB.View) – The view to get grids from.

Returns:

A collector with all grids in view.

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_multi_segmented_grids_in_view(doc, view)

Get all multi segmented grids in a view

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

  • view (Autodesk.Revit.DB.View) – The view to get grids from.

Returns:

A collector with all multi segmented grids in view.

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_all_segment_grid_ids(multi_segment_grids)

Gets a unique list of grids id’s making up the multi segment grids past in.

Parameters:

multi_segment_grids ([_type_]) – List of multi segment grids

Returns:

List of individual grid ids.

:rtype:[Autodesk.Revit.DB.ElementId]

duHast.Revit.Grids.grids.get_linear_grids_in_model_by_view(doc, view)

Returns only linear grid visible in view.

Will exclude multi segment grids and arc based grids.

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

  • view (Autodesk.Revit.DB.View) – The view.

Returns:

List of linear grids.

Return type:

[Autodesk.Revit.DB.Grid]

duHast.Revit.Grids.grids.get_all_grid_heads_by_category(doc)

Gets all grid head types in the model.

Parameters:

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

Returns:

A filtered element collector with grid head types

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_all_grid_types_by_category(doc)

Gets all grid types in the model

Parameters:

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

Returns:

A filtered element collector with grid types

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_all_grid_type_ids_by_category(doc)

Gets all grid types ids in the model.

Parameters:

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

Returns:

A filtered element collector with grid type ids

Return type:

Autodesk.Revit.DB.FilteredElementCollector

duHast.Revit.Grids.grids.get_grid_type_names(doc, g)

Gets all valid grid types, based on a past in grid, available in model.

Uses grid.GetValidTypes() to get the grid types.

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

  • g (Autodesk.Revit.DB.Grid) – A grid

Returns:

A nested set of lists containing grid type id and grid type name

Return type:

list of lists [[GridTypeId as Revit ElementId, grid type name as string],[…]]

duHast.Revit.Grids.grids.get_grid_type_name(doc, g)

Gets the grid type name of a grid.

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

  • g (Autodesk.Revit.DB.Grid) – A grid.

Returns:

The grid type name.

Return type:

str

duHast.Revit.Grids.grids.get_grid_type_id_by_name(doc, grid_type_name)

Gets the grid type Id based on it’s name, if no match found it returns the Revit Invalid Element Id

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

  • grid_type_name (str) – The grid type name.

Returns:

The grids type Id or if not match is found Autodesk.Revit.DB.ElementId.InvalidElementId

Return type:

Autodesk.Revit.DB.ElementId

duHast.Revit.Grids.grids.grid_check_parameter_value(g, para_name, para_condition, condition_value)

Returns true if a given parameter on a grid has a value meeting the parameter condition.

Parameters:
  • g (Autodesk.Revit.DB.Grid) – A grid.

  • para_name (str) – A parameter Name.

  • para_condition (func(arg1,arg2)) – A function evaluating the parameter value. First argument is the value to be checked against. Second argument is the actual parameter value.

  • condition_value (var) – The value to be checked against.

Returns:

True if parameter value is evaluated to True otherwise False.

Return type:

bool

duHast.Revit.Grids.grids.get_max_extent_as_string(g)

Gets the maximum extent of a grid.

Parameters:

g (Autodesk.Revit.DB.Grid) – A grid.

Returns:

A string in format [maxX,maxY,maxZ]

Return type:

str

duHast.Revit.Grids.grids.get_min_extent_as_string(g)

Gets the minimum extent of a grid.

Parameters:

g (Autodesk.Revit.DB.Grid) – A grid.

Returns:

A string in format [minX,minY,minZ]

Return type:

str

duHast.Revit.Grids.grids.get_all_grid_head_family_type_ids(doc)

This will return all ids grid head family types in the model

duHast.Revit.Grids.grids.get_grid_curves_from_view(grid, view)

Gets grid curve (line from a view. Will return none if grid is out of view scope

Parameters:
  • grid (Autodesk.Revit.DB.Grid) – The grid element.

  • view (Autodesk.Revit.DB.View) – The view of which the get the grid extend from.

Returns:

A curve object if grid is visible in view, otherwise None

Return type:

[Autodesk.Revit.DB.Curve] or None

duHast.Revit.Grids.grids.get_grid_plane_z_value(grids, view)

Get the z value of Grid plane by view based on first grid found visible in view.

Parameters:
  • grids ([Autodesk.Revit.DB.Grid]) – Grids in the model

  • view (Autodesk.Revit.DB.View) – the view

Returns:

The view plane Z value or 0.0 if no grid found in view.

Return type:

float

duHast.Revit.Grids.grids_appearance module

Revit grids appearance modifier functions.

Note: Any grid appearance modification in a view will throw an exception if the grid is not actually visible in the view.

duHast.Revit.Grids.grids_appearance.change_grids_2D(doc, grids, view)

Changes all grids in view to 2D

Note: Any grid past in, which is not visible in the view, will throw an exception when attempting to set to 2D.

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

  • grids ([Autodesk.Revit.DB.Grid]) – List of grids to be changed to 2D.

  • view (Autodesk.Revit.DB.View) – The view in which to change the grids

Returns:

Result class instance. - result.status. True if all grids where set to 2D, otherwise False. - result.message will contain the name(s) of the grid(s) changed to 2D - result.result empty list On exception: - result.status (bool) will be False. - result.message will contain generic exception message including the grid name. - result.result will be empty

Return type:

Result

duHast.Revit.Grids.grids_appearance.show_bubble_end(doc, grid, view, end_identifier, show_bubble)

Toggles grid bubble visibility on the specified end for a given grid.

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

  • grid (Autodesk.Revit.DB.Grid) – The grid of which a bubble’s visibility is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which a grid bubble’s visibility is to be toggled.

  • end_identifier (Autodesk.Revit.DB.DatumEnds) – An enumerated type representing ends of a datum plane.

  • show_bubble (bool) – True if the bubble will be switched on, False if it will be switched off.

Returns:

Result class instance.

  • result.status (bool): True if the grid bubble(s) visibility was set successfully, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was set.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.hide_both_bubbles(doc, grids, view)

Hides both bubbles of grids in the given view.

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

  • grid (Autodesk.Revit.DB.Grid) – The grid for which bubble visibility is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

Returns:

Result class instance.

  • result.status (bool): True if all grid bubble(s) visibility was switched off successfully, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was set.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.show_bubble_zero_end(doc, grids, view)

Turns on grid bubbles at the zero end in the specified view.

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

  • grid (List[Autodesk.Revit.DB.Grid]) – The grids for which bubble visibility is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

Returns:

Result class instance.

  • result.status (bool): True if all grid bubble(s) visibility at the zero end was set to visible successfully, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was set.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.show_bubble_one_end(doc, grids, view)

Turns on grid bubbles at one end in the specified view.

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

  • grid (List[Autodesk.Revit.DB.Grid]) – The grids for which bubble visibility is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

Returns:

Result class instance.

  • result.status (bool): True if all grid bubble(s) visibility at one end was set to visible successfully, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was set.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.toggle_bubble_end(doc, grid, view, end_identifier)

Toggles grid bubble visibility on a specified end for a given grid in given views.

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

  • grid (Autodesk.Revit.DB.Grid) – The grid of which bubble visibility is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

  • end_identifier (Autodesk.Revit.DB.DatumEnds) – The end of the grid to be modified.

Returns:

Result class instance.

  • result.status (bool): True if the grid bubble(s) visibility was changed successfully, otherwise False.

  • result.message (str): Contains the name of the grid where bubble visibility was changed.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.toggle_bubble_one_end(doc, grids, view)

Toggles grid bubble visibility on one end for given grids.

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

  • grids (List[Autodesk.Revit.DB.Grid]) – The grids of which bubble visibility at one end is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

Returns:

Result class instance.

  • result.status (bool): True if the bubble visibility at one end was changed successfully for all grids, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was changed.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_appearance.toggle_bubble_zero_end(doc, grids, view)

Toggles grid bubble visibility on zero end for given grids.

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

  • grids (List[Autodesk.Revit.DB.Grid]) – The grids of which bubble visibility at zero end is to be toggled.

  • view (Autodesk.Revit.DB.View) – The view in which grid bubble visibility is to be toggled.

Returns:

Result class instance.

  • result.status (bool): True if the bubble visibility at zero end was changed successfully for all grids, otherwise False.

  • result.message (str): Contains the name(s) of the grid(s) where bubble visibility was changed.

  • result.result (list): Empty list.

On exception:

  • result.status (bool) will be False.

  • result.message (str) will contain a generic exception message including the grid name.

  • result.result (list) will be empty.

Return type:

Result

duHast.Revit.Grids.grids_extend_to_view_crop module

Revit grids extend to view crop.

duHast.Revit.Grids.grids_extend_to_view_crop.extend_linear_grids_to_crop_box_of_view(doc, view)

Extends all linear grids to intersection points with crop box on active view.

Parameters:

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

Returns:

Result class instance.

  • result.status. True if all grids in active view got extended successfully, otherwise False.

  • result.message will contain the name(s) of the grids extended.

  • result.result empty list

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.Grids.grids_propagate_visbility_and_extends module

Revit propagate grids extend visibility, and graphics to other views.

class duHast.Revit.Grids.grids_propagate_visbility_and_extends.grid_properties(is_grid_in_scope, datum_extent_type_zero, datum_extent_type_one, grid_curve, end_zero_bubble, end_one_bubble, is_grid_hidden)

Bases: tuple

Create new instance of grid_properties(is_grid_in_scope, datum_extent_type_zero, datum_extent_type_one, grid_curve, end_zero_bubble, end_one_bubble, is_grid_hidden)

datum_extent_type_one

Alias for field number 2

datum_extent_type_zero

Alias for field number 1

end_one_bubble

Alias for field number 5

end_zero_bubble

Alias for field number 4

grid_curve

Alias for field number 3

is_grid_hidden

Alias for field number 6

is_grid_in_scope

Alias for field number 0

duHast.Revit.Grids.grids_propagate_visbility_and_extends.get_active_view_grid_data(active_view, grids_in_model)

returns a dictionary where grid id is the key and values are a list of properties:

  • inScope (bool)

  • isVisible (bool)

  • end zero, end One: Extent type for both ends ( 2D vs 3D) (None if not in scope)

  • curve: the curve (line) describing the grid extent in view (None if not in scope)

  • end bubble one end bubble zero: bool describing which bubble isi visible in view (None if not in scope)

Parameters:
  • active_view (Autodesk.Revit.DB.View) – The active view.

  • grids_in_model ([Autodesk.Revit.DB.Grid]) – Grids in the model.

Returns:

Result class instance.

  • result.status: True.

  • result.message will contain the names of the grids not in scope only.

  • result.result contains a named tuple: grid_properties:

    {

    bool, is the grid in scope (inside the crop region) # Datum Extent type at End 0, # Datum Extend type at End 1, curve, describing the start and end point of grid bool, #bubble visible at zero end bool, # bubble visible at 1 end bool # is the grid visible

    }

On exception

  • result.status (bool) will be True (exception is ignored)

  • result.message will contain the message grid not in scope for view

Return type:

Result

duHast.Revit.Grids.grids_propagate_visbility_and_extends.change_grid_extends_in_views(doc, grids_in_model, grid_template_data, views_to_change_grid_elements, callback)

Changes grids in a number views to match the extend, visibility, bubble visibility of grids in template view

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

  • grids_in_model ([Autodesk.Revit.DB.Grid]) – Grids in the model

  • grid_template_data (A named tuple: grid_properties bool, is the grid in scope (inside the crop region) # Datum Extent type at End 0, # Datum Extend type at End 1, curve, describing the start and end point of grid bool, # bubble visible at zero end bool, # bubble visible at 1 end bool # is the grid visible) – A dictionary describing the appearance of each grid in the template view

  • views_to_change_grid_elements (ProgressBase) – A list of views in which to update the grid graphics

  • callback – A progress call back function

duHast.Revit.Grids.grids_propagate_visbility_and_extends.propagate_grids_extends_and_visibility(doc, views_to_change_grid_elements, callback=None)

Propagates grid extends and visibility from the active view to all other views selected in UI.

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

  • viewsToChangeGridElements ([Autodesk.Revit.DB.View]) – A list of views in which to update the grid graphics

  • callback – A progress call back function

Returns:

Result class instance.

  • result.status: True.

  • result.message will contain the names of the grids amended.

  • result.result an empty list

On exception

  • result.status (bool) will be False

  • result.message will contain the exception message

duHast.Revit.Grids.grids_worksets module

Revit grids workset modifier functions.

duHast.Revit.Grids.grids_worksets.modify_grid_worksets_default(doc, worksetRules)

Workset modifier method. Moves all grids to one workset.

Rules format:

[‘Model name’, [[workset modifier method,[worksetName]]]]

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

  • worksetRules (List) – The workset rules in the specified format.

Returns:

A result object.

Return type:

Type

duHast.Revit.Grids.grids_worksets.modify_grid_worksets_by_type_name(doc, worksetRules)

Workset modifier method. Moves grids matching a type condition to a particular workset.

Default workset type rules example:

[[‘model name’, [[ModifyGridWorkSetsByTypeName, [[‘workset name’, util.ConDoesNotEqual, ‘grid type name’],[‘workset name’, util.ConDoesEqual, ‘grid type name’]]]]]]

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

  • worksetRules (List) – The workset rules in the specified format.

Returns:

A result object.

Return type:

Type

duHast.Revit.Grids.grids_worksets.modify_grid_worksets_by_parameter_value(doc, worksetRules)

Workset modifier method. Moves grids matching parameter condition to a particular workset

Default workset type rules example:

[[‘model name’, [[ModifyGridWorkSetsByParameterValue, [[‘workset name’, util.ConTwoStartWithOne, ‘Name’, ‘name starts with value’]]]]]]

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

  • worksetRules (_type_) – _description_

Returns:

returns a result object

Return type:

_type_

duHast.Revit.Grids.grids_worksets.modify_grids_worksets(doc, revitFileName, worksetRules)

Modifies worksets of grids as per workset rules format.

Default workset type rules example:

[[‘model name’, [[ModifyGridWorkSetsDefault, [[‘default workset name’] # There should only be one per model]]]]]

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

  • revitFileName (_type_) – _description_

  • worksetRules (_type_) – _description_

Returns:

returns a result object

Returns:

Result class instance.

  • result.status: View deletion status returned in result.status. False if an exception occurred, otherwise True.

  • result.message: will contain the fully qualified file path of the exported file

  • result.result: will be an empty list

On exception

  • Reload.status (bool) will be False

  • Reload.message will contain the exception message

Return type:

Result

duHast.Revit.Grids.purge_unused_grid_types module

This module contains a number of helper functions relating to purging Revit grids and grid heads.

duHast.Revit.Grids.purge_unused_grid_types.get_unused_grid_types_for_purge(doc)

this will return all ids of unused grid types in the model to be purged

Parameters:

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

Returns:

List of grid types which can be purged

Return type:

[]

duHast.Revit.Grids.purge_unused_grid_types.get_unused_grid_head_families(doc)

this will return all ids of unused family symbols (types) of grid head families

Parameters:

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

Returns:

A list of grid head family ids.

Return type:

[Autodesk.Revit.DB.ElementId]

duHast.Revit.Grids.purge_unused_grid_types.get_unused_grid_head_families_for_purge(doc)

this will return all ids of unused grid head symbols and families to be purged

Parameters:

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

Returns:

A list of family ids.

Return type:

[Autodesk.Revit.DB.ElementId]

Module contents