Homepage

Tools and librairies for Character Riggers and TDs (mostly for Autodesk Maya)

Introduction

bgdev is a custom suite of python tools and utility function, mostly created for Autodesk Maya and focusing on TD roles like Character Rigging or Animation. It started with my career back in August 2013, and has grown over time with the experience I got from various jobs in different companies.

License

The current repository is under MIT License.

Feel free to use, change, and share it as you please. You don’t have to, but mentioning my name whenever you use source code from here would be much appreciated!

API Documentation

You can find a generated sphinx documentation at https://bgdev.readthedocs.io/en/latest/

Installation

bgdev doesn’t require anything apart from a working version of Autodesk Maya. You will find a module file available in bgdev\src\apps-maya\module\modules\ which you can add to the MAYA_MODULE_PATH environment variable. It’ll allow Maya to pick up the whole repo automatically for you on startup.

You can always run multiple sys.path.append() on the various Python source folders: bgdev\src\apps-maya\python and bgdev\src\apps-python. Don’t forget to include the Python external libraries in bgdev\src\site-packages\Python27 too or some tools may not be working!

Usage

Once the module is installed, all you need to do is to run import bgdev inside Maya. (Obviously you need to call the right tool/library, but if you found this repo you probably know how python works! :-))

bgdev

bgdev.tools

bgdev.tools.mayaColorPicker

bgdev.tools.mayaColorPicker.core

Color picker for Maya. (old)

created

25/02/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.mayaColorPicker.main

Maya Color Picker

created

20/02/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

class ColorPicker(name=None, index=17)[source]

Bases: object

__init__(name=None, index=17)[source]

Initialize self. See help(type(self)) for accurate signature.

property color
property node

bgdev.tools.pluginManager

bgdev.tools.pluginManager.core

Custom plugin manager for Maya.

created

10/07/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.renamer

Convenient wrapper to the core and ui modules.

author

Benoit GIELLY <benoit.gielly@gmail.com>

show(*args, **kwargs)[source]

Wrap the show function of the core module.

bgdev.tools.renamer.core

Renamer tool for maya.

created

06/04/2016

author

Benoit GIELLY <benoit.gielly@gmail.com>

show(parent=None)[source]

Show widget.

bgdev.tools.renamer.ui

Main UI for the renamer.

created

06/04/2016

author

Benoit Gielly <benoit.gielly@gmail.com>

maya_window()[source]

Return the MayaWindow if in Maya else None.

bgdev.tools.renamer.utils

Utils function for the renamer.

author

Benoit GIELLY <benoit.gielly@gmail.com>

UNDO(func, *, undo=True)

Decorate a method to make it undoable.

check_image(icon, normalized=False, as_icon=False)[source]

Convert the given image path to full path name.

Parameters
  • icon (str) – Name of the icon to check

  • normalized (bool) – Normalize the path to slash forward (works on all OS)

  • as_icon (bool) – Return a QIcon of the found image file.

Returns

Updated icon path so it’s ready to be used.

Return type

str

method_decorator(func, undo=False)[source]

Decorate a method to make it undoable.

bgdev.tools.toolbar

bgdev.tools.toolbar.tabs
bgdev.tools.toolbar.tabs.maya
bgdev.tools.toolbar.tabs.maya.main

Maya toolbar override.

created

14/10/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

dock_widget(widget, title='DockWindow', area='right', floating=False)[source]

Dock the given widget properly for both M2016 and 2017+.

get_workspaces(**kwargs)[source]

Get Maya workspaces (WIP).

maya_window()[source]

Return the MayaWindow if in Maya else None.

show(*args, **kwargs)[source]

Show the widget within a maya workspaceControl.

to_qwidget(ctrl)[source]

Convert a Maya widget to a PySide2 QWidget.

Parameters

ctrl (str) – Name of the maya widget as a string.

Returns

QWidget instance object of the given widget.

Return type

QtWidgets.QWidget

bgdev.tools.toolbar.tabs.system
bgdev.tools.toolbar.tabs.system.main

Maya toolbar override.

created

14/10/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

show()[source]

Show the window.

bgdev.tools.toolbar.cfg

Config file to be shared in the toolbar project.

created

26/11/2020

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.toolbar.main

Main toolbar code.

created

09/11/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

get_class_name(cls)[source]

Get the class full path name.

show(*args, **kwargs)[source]

Show the window.

bgdev.tools.toolbar.ui

PySide Widgets used in the main toolbar code.

created

09/11/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.toolbar.utils

Utility method used in the toolbar.

created

12/11/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

check_image(icon, normalized=True)[source]

Convert the given image path to full path name.

Parameters
  • icon (str) – Name of the icon to check

  • normalized (bool) – Normalize the path to work on all OS

Returns

Updated icon path so it’s ready to be used.

Return type

str

check_modpath_has_init(path, parts)[source]

Check if given module parts all contains an __init__ file.

Parameters
  • path (str) – Path to python file.

  • parts (list) – Each parts of a module path. (Eg. [“sanity”, “core”]).

Returns

True if each part as an __init__ file as sibling else False.

Return type

bool

create_module_callback(source)[source]

Set the command for each buttons.

Parameters

source (str) – Source python code to execute.

Returns

A callable function

Return type

function

get_dcc()[source]

Get current DCC application.

get_dcc_package()[source]

Get the current DCC’s “check” package.

modpath_from_file(filename)[source]

Get the module import path from its filename.

Parameters

filename (str) – Path to python file.

Raises

ImportError – When module cannot be found in sys.path.

Returns

The module import path.

Return type

str

yaml_dump(data, path, ordered=False, **kwargs)[source]

Export YAML file.

Parameters
  • data (dict) – Dictionary to export as JSON

  • path (str) – YAML file path to save data

  • ordered (bool) – Dump data ordered when True.

  • kwargs (dict) – Any extra flags to pass in the json.dump() command

Returns

given file path

Return type

str

yaml_load(path, ordered=False, **kwargs)[source]

Import YAML file.

Parameters
  • path (str) – YAML file path to save data

  • ordered (bool) – Load data in an orderedDict when True.

  • kwargs (dict) – Any extra flags to pass in the json.load() command

Returns

the loaded data

Return type

dict

bgdev.tools.atom_import_export

Use ATOM to import or export animation.

created

31/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

atom_export(path, nodes)[source]

Export selected controlers into atom file.

Parameters
  • path (str) – The atom file path.

  • nodes (list) – List of controlers to export animation from.

atom_import(path, nodes)[source]

Import animation curves from atom file.

Parameters
  • path (str) – The atom file path.

  • nodes (list) – List of controlers to import animation onto.

export_dialog()[source]

Open up a file dialog to get the atom file to export.

import_dialog()[source]

Open up a file dialog to get the atom file to import.

bgdev.tools.bindpose

Create and set bindpose on controlers.

created

17/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

create_bindpose()[source]

Create a bindpose attribute on every controls.

get_all_controls()[source]

Get all rig controlers in the scene.

restore_bindpose(selected=True)[source]

Restore the rig controls to their bindpose.

Parameters

selected (bool) – If True, reset only selected controls, otherwise reset every controls of each selected rigs.

bgdev.tools.curve

Custom tools with curves.

author

Benoit GIELLY <benoit.gielly@gmail.com>

attach_nodes_to_curve()[source]

Attach selected nodes to selected curve.

curve_from_nodes(degree=2)[source]

Create a curve and snap each CVs on each selected nodes.

Parameters

degree (int) – The curve degree.

Returns

The created curve node.

Return type

str

get_closest_point(point, node_list)[source]

Get the closest point to each nodes in the list.

Parameters
  • point (str) – Node to evaluate the distance to.

  • node_list (list) – List of nodes to search for the closest to the point.

Returns

The closest node.

Return type

str

bgdev.tools.mel2py

Convert mel to python.

created

23/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

convert_command(command, namespace='cmds', verbose=True)[source]

Convert mel command-string to python.

Parameters
  • command (str) – The mel command as a string.

  • namespace (str) – The namespace to use for the module.

  • verbose (bool) – Prints the command after conversion.

Returns

The convert mel command to python.

Return type

str

convert_file(files, force_compatibility=True)[source]

Convert mel files to python.

Parameters
  • files (list) – List of path to mel files.

  • force_compatibility (bool) – Pymel argument. Don’t really know if it has an impact or not so adding it as a kwarg just in case.

bgdev.tools.outliner_color

Tool to quickly update outliner color of selected nodes.

created

11/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.performance

Evaluation Toolkit.

created

03/06/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

class Profiler[source]

Bases: object

Create a python profiler to check for code usage.

Example

import bgdev.tools.performance
profiler = bgdev.tools.performance.Profiler()
profiler.start()
# run python code
profiler.stop()
__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

start()[source]

Enable the profiler.

stats(sort='tottime')[source]

Print the profiler stats.

Parameters

sort (str) – Sort the stats with given value.

stop(sort='time')[source]

Stop the profiler and print restult.

Parameters

sort (str) – Sort the stats with given value.

frames_per_second(iterations=3, start=1001, frames=100, viewports='viewport2', meshes_only=True, outfile=None)[source]

Evaluate the framePerSecond in the current scene.

Parameters
  • iterations (int) – Amount of time the timeline should run.

  • start (int) – Start frame.

  • frames (int) – The amount of frames to run.

  • viewports (list) – Select the viewports you want to evaluate on. Possible values are “legacy” and “viewport2”.

  • meshes_only (bool) – Hides everything but meshes in the viewport.

  • outfile (bool or str) – Save the output fps in the given txt file. If True is passed, query the current scene path and save the log next to it (Useful when benchmarking multiple scenes in a loop).

Returns

The evaluated frame per seconds as a float number.

Return type

float

bgdev.tools.pypredef

Generate pypredefs using Maya’s help query to read command flags.

created

18/05/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

cleanup_flags(docstring)[source]

Cleanup the docstring from the mel output to a nicer result.

Parameters

docstring (str) – The docstring extracted from the help command query.

Example

Reformat this docstring:

Flags:
   -n -name        String
   -p -parent      String
   -s -shared
  -ss -skipSelect

So it looks like this:

Flags:
    name (n): String
    parent (p): String
    shared (s): None
    skipSelect (ss): None

Also returns a list of all the flags so they can be added to the method definition (eg. “flag=None”) so IDE can autocomplete them.

Parameters

docstring (str) – The docstring containing the flags to cleanup.

Returns

The cleaned-up docstring with nicer flags, and the list of flags

Return type

tuple

generate_pypredef(module, outdir=None, doclink=True)[source]

Generate pypredefs using Maya’s help query to read command flags.

Parameters
  • module (mod) – Module from which you want to generate the pypredef.

  • outdir (str) – Directory in which you want to export the text file.

  • doclink (bool) – Adds a link to the online documentation.

Note

There are a few maya commands (e.g. “nexCtx”) that are almost 1 MILLION line length… so there’s a test to skip the command if the docstring is longer than 10k lines.

Example

from maya import cmds
generate_pypredef(cmds, outdir="~/Desktop")
get_maya_urls()[source]

Generate a table for each commands from the online documentation.

Returns

Generates a {command:url} dictionnary.

Return type

dict

indent(text, amount=4)[source]

Indent each lines of the given string.

Parameters
  • text (str) – Text to indent

  • amount (int) – Number or character padding

Returns

Indented text.

Return type

str

iskeyword()

x.__contains__(y) <==> y in x.

bgdev.tools.symmetry

Utility methods used to sort nodes and graphs.

created

20/11/2020

author

Benoit GIELLY <benoit.gielly@gmail.com>

class Symmetry[source]

Bases: object

Generates a symmetry table for selected mesh.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

property center

Get center vertices.

get_side_vertices(side)[source]

Get all components of given side.

static get_vertex_id(vertex)[source]

Get vertex index from name.

get_vertex_name(index)[source]

Get vertex name from index.

property left

Get left side vertices.

mirror(vertices)[source]

Mirror vertices.

Parameters

vertices (list) – List of vertices to mirror.

Yields

str – The next vertex full name in the given list.

mirror_selection(add=False)[source]

Mirror selected vertices.

Parameters

add (bool) – Add to existing selection when True.

populate_table()[source]

Populate the symmetry table with vertices.

Notes

Maya topology symmetry must be already activated.

property right

Get right side vertices.

update()[source]

Generate a symmetry table.

bgdev.tools.symmetry_api

Utility methods used to sort nodes and graphs.

created

20/11/2020

author

Benoit GIELLY <benoit.gielly@gmail.com>

class Symmetry[source]

Bases: object

Generates a symmetry table for selected mesh.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

property center

Get center vertices.

get_side_vertices(side)[source]

Get all components of given side.

Parameters

side (str) – Side of the table to query. Either “left”, “center” or “right”.

Returns

List of side-vertices.

Return type

list

static get_sides_from_rich(vertices)[source]

Get resulting sides of a RichSelection in symmetry.

Parameters

vertices (list) – Vertices to select for symmetry.

Returns

Two OpenMaya.MSelectionList, being the result of the

MRichSelection.getSelection and MRichSelection.getSymmetry methods.

Return type

tuple

static get_vertex_id(vertex)[source]

Get vertex index from name.

Parameters

vertex (str) – Full vertex name (eg. “mesh.vtx[15]”)

Returns

Index of the vertex as integer.

Return type

int

get_vertex_name(index)[source]

Get vertex name from index.

Parameters

index (int) – Index of the vertex.

Returns

Full vertex name (eg. “mesh.vtx[15]”)

Return type

str

property left

Get left side vertices.

mirror(vertices)[source]

Mirror vertices.

Parameters

vertices (list) – List of vertices to mirror.

Yields

str – The next vertex full name in the given list.

mirror_selection(add=False)[source]

Mirror selected vertices.

Parameters

add (bool) – Add to existing selection when True.

populate_table()[source]

Populate the symmetry table with vertices.

Notes

Maya topology symmetry must be activated.

property right

Get right side vertices.

update()[source]

Generate a symmetry table.

bgdev.tools.uniloop

Create an easy attribute setting loop.

created

14/10/2016

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.tools.vector_plane

Symmetry stuff.

created

14/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

get_mirrorvector(obj, **kwargs)[source]
mirrorToolCMD(*args, **kwargs)[source]
mirror_layout()[source]
setMirrorToolCMD(callback, fields=None)[source]
vector(*args)[source]

bgdev.ui

bgdev.ui.dock

Make any window dockable within Maya.

created

8 Jun 2018

author

Benoit Gielly <benoit.gielly@gmail.com>

dock_widget(widget, label='DockWindow', area='right', floating=False)[source]

Dock the given widget properly for both M2016 and 2017+.

get_available_controls()[source]

Return all the available Controls in list.

Returns

List of existing workspaceControls.

Return type

list

bgdev.ui.flow_layout

Custom FlowLayout.

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.ui.progress_bar

ProgressBar class to use in Maya.

Todo

Convert to PySide and move to bgdev.ui.widget

created

23/05/2018

author

Benoit Gielly <benoit.gielly@gmail.com>

class ProgressBar[source]

Bases: object

ProgressBar class.

__init__()[source]

Constructor.

end()[source]

Finish the process.

is_cancelled()[source]

Check if progress was cancelled (esc. key pressed).

start(status='Begin operation...', value=100)[source]

Start the process.

property status

Update the status of the progressBar.

Type

str

step(step=1)[source]

Increase progress step by one.

class ProgressBar2[source]

Bases: object

ProgressBar class.

__init__()[source]

Constructor.

end()[source]

Finish the process.

start(status='Begin operation...', maximum=100)[source]

Start the process.

property status

Update the status of the progressBar.

Type

str

step()[source]

Increase progress step by one.

bgdev.ui.utils

Utility fonctions for UI.

created

8/02/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

check_image(icon, normalized=True, as_icon=False)[source]

Convert the given image path to full path name.

Parameters
  • icon (str) – Name of the icon to check

  • normalized (bool) – Normalize the path to slash forward (works on all OS)

  • as_icon (bool) – Return a QIcon of the found image file.

Returns

Updated icon path so it’s ready to be used.

Return type

str

generate_qrc(path, name='resources', prefix='icons')[source]

Generate .qrc file based on given folder.

Parameters
  • path (str) – Path to icons folder.

  • name (str) – Name of the qrc file to generate. Default is “resources”.

  • prefix (str) – Name of the icon prefix. Default is “icons”.

Returns

Path to the generated [qrc].py file.

Return type

str

in_maya()[source]

Check if we are in Maya or not.

Returns

True if in maya else False

Return type

bool

main_window()[source]

Return the QMainWindow for the current application.

maya_window()[source]

Get Maya MainWindow as Qt.

Returns

Maya main window as QtObject

Return type

QtWidgets.QWidget

to_qwidget(ctrl)[source]

Convert a Maya widget to a PySide2 QWidget.

Parameters

ctrl (str) – Name of the maya widget as a string.

Returns

QWidget instance object of the given widget.

Return type

QtWidgets.QWidget

bgdev.ui.widgets

PySide custom widgets.

created

12/12/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.utils

bgdev.utils.attribute

created

13 Feb 2018

author

Benoit Gielly <benoit.gielly@gmail.com>

attributes_restore(node)[source]

Restore previously unlocked attributes to their default state.

Parameters

node (str) – Node to restore attributes

Returns

False if attribute doesn’t exists else True

Return type

bool

attributes_toggle(nodes=None, attr_list=None)[source]

Toggle attributes between default and unlocked states.

Parameters
  • nodes (list) – List of nodes to toggle. If not given, use viewport selection.

  • attr_list (list) – List of extra attributes to toggle

attributes_unlock(node, base=True, user=True, attr_list=None)[source]

Unlock attributes on given node

Parameters
  • node (str) – Node to unlock attributes

  • attr_list (list) – List of extra attributes to toggle

  • base (bool) – If True, will toggle base attributes (translate, rotate, scale, visibility).

  • user (bool) – If True, will toggle user’s attributes.

create_separator_attribute(node, name=None)[source]

Create a separator attribute on the given node.

Parameters
  • node (str) – Name of the node to add the separator attribute.

  • name (str) – Name nice (category)

bgdev.utils.bindpose

Create and set bindpose on controlers.

created

17/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

create_bindpose()[source]

Create a bindpose attribute on every controls.

restore_bindpose(selected=True)[source]

Restore the rig controls to their bindpose.

Parameters

selected (bool) – If True, reset only selected controls, otherwise reset every controls of each selected rigs.

bgdev.utils.color

Color utilites.

created

08/02/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

convert_css_color(css_color)[source]

Convert given color using the PySide2 CSS API.

Parameters

css_color (str) – Any color-string you would type in a Widget’s CSS.

Returns

The RBG-converted color.

Return type

tuple

bgdev.utils.connections

created

2017-03-10

author

Benoit GIELLY <benoit.gielly@gmail.com>

pairblend_three_nodes()[source]

Create pairblend between three nodes.

quick_connections()[source]

Quickly connect transforms.

bgdev.utils.constraints

Utility methods about constraints.

created

05/03/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

aim_to_children(up_vector=(0, 1, 0), aim_vector=(1, 0, 0))[source]

Find an up vector for the selection and aim toward each others.

Parameters
  • up_vector

  • aim_vector

matrix_constraint(driver, target, srt='srt')[source]

Constraint one node to another using their worldMatrix attributes.

Parameters
  • driver (str) – The driver node

  • target (str) – The node that follow the driver.

  • srt (str) – The attributes to connect.

Returns

The multMatrix and decomposeMatrix nodes.

Return type

tuple

matrix_constraint_callback(srt='trs')[source]

Call back update intermediate().

bgdev.utils.controler

Utilities for controlers.

Mostly, controler shapes creation (needs to be turned into data)

author

Benoit GIELLY <benoit.gielly@gmail.com>

create_control(ctrl, variant=0, name=None, size=1.0, normal=(0, 1, 0), color='yellow')[source]

Create a controler based on its name and variant.

Parameters
  • ctrl (str) – The type of controler you want to create. Use list_controlers() method to know which ones are available.

  • variant (int) – Which variant of the controler type you want.

  • name (str) – Rename the controler with the given name.

  • size (float) – Scale the controler using given size value.

  • normal (tuple) – Which axis should the controler aim to when created. Default axis is +Y

  • color (str) – The name of the CSS color to apply as an RGB override. Uses the PySide2 StyleSheet API to convert names to RGB color.

Returns

The controler and its shape.

Return type

tuple

get_all_controls(namespace='')[source]

Get all rig controlers in the scene.

get_ctrl_data(name, variant=0)[source]

Query the controler data from its name.

get_rig_controls()[source]

Query all controlers of the selected rig(s).

list_controlers()[source]

List all the available controls.

select_all()[source]

Select all controlers in the current scene.

select_rig_controls()[source]

Select all controlers from selected rig(s).

bgdev.utils.curve

Utility methods for curves.

created

04/02/2019

author

Benoit Gielly <benoit.gielly@gmail.com>

curve_interpolate(curve=None, segments=3)[source]

Interpolate locators along a selected nurbsCurve.

Parameters
  • curve (str) – Name of the curve node. Use selection if None.

  • segments (int) – Amount of segments you want.

Returns

The created locators.

Return type

list

bgdev.utils.decorator

Useful decorators to use for methods.

created

11/12/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

REPEAT(func, *, repeat=True, undo=False)

Decorate a method to make it repeatable and/or undoable.

Parameters
  • func (function) – The method to decorate.

  • repeat (bool) – Makes the method repeatable.

  • undo (bool) – Makes the method undoable.

Example

You can use the custom wrappers in this module to decorate your method as you’d like:

import rigging.ui.decorator

@bgdev.ui.decorator.UNDO
def undoable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.REPEAT
def repeatable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.UNDO_REPEAT
def undoable_repeatable_method(*args, **kwargs):
    return args, kwargs
Returns

The decorated method.

Return type

function

UNDO(func, *, repeat=False, undo=True)

Decorate a method to make it repeatable and/or undoable.

Parameters
  • func (function) – The method to decorate.

  • repeat (bool) – Makes the method repeatable.

  • undo (bool) – Makes the method undoable.

Example

You can use the custom wrappers in this module to decorate your method as you’d like:

import rigging.ui.decorator

@bgdev.ui.decorator.UNDO
def undoable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.REPEAT
def repeatable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.UNDO_REPEAT
def undoable_repeatable_method(*args, **kwargs):
    return args, kwargs
Returns

The decorated method.

Return type

function

UNDO_REPEAT(func, *, repeat=True, undo=True)

Decorate a method to make it repeatable and/or undoable.

Parameters
  • func (function) – The method to decorate.

  • repeat (bool) – Makes the method repeatable.

  • undo (bool) – Makes the method undoable.

Example

You can use the custom wrappers in this module to decorate your method as you’d like:

import rigging.ui.decorator

@bgdev.ui.decorator.UNDO
def undoable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.REPEAT
def repeatable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.UNDO_REPEAT
def undoable_repeatable_method(*args, **kwargs):
    return args, kwargs
Returns

The decorated method.

Return type

function

method_decorator(func, repeat=False, undo=False)[source]

Decorate a method to make it repeatable and/or undoable.

Parameters
  • func (function) – The method to decorate.

  • repeat (bool) – Makes the method repeatable.

  • undo (bool) – Makes the method undoable.

Example

You can use the custom wrappers in this module to decorate your method as you’d like:

import rigging.ui.decorator

@bgdev.ui.decorator.UNDO
def undoable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.REPEAT
def repeatable_only_method(*args, **kwargs):
    return args, kwargs

@bgdev.ui.decorator.UNDO_REPEAT
def undoable_repeatable_method(*args, **kwargs):
    return args, kwargs
Returns

The decorated method.

Return type

function

selected(func)[source]

Decorate a func to use selection if no args passed.

bgdev.utils.deformer

Utility methods for deformers.

created

28/05/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

transfer_base_weights(source, target, joint=0)[source]

Transfer weights from source to target.

Parameters
  • source (str) – Source deformer

  • target (str) – Target deformer

  • joint (int) – Index of joint in skinCluster

transfer_base_weights_api(source, target, src_joint=0, tgt_joint=0)[source]

Transfer weights from source to target using OpenMaya.

Parameters
  • source (str) – Source deformer

  • target (str) – Target deformer

  • joint (int) – Index of joint in skinCluster

update_lattice(node, lattice, add=True)[source]

Add or remove node from lattice.

Parameters
  • node (str) – The node to add into the existing lattice.

  • lattice (str) – The lattice (ffd) node.

  • add (bool) – True node to lattice if True, else remove it.

update_lattice_callback(add=True)[source]

Call back update_lattice().

bgdev.utils.display

Utility methods about viewport display.

created

13/02/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

real_focus()[source]

Zoom to the current selection’s manipulator position.

real_focus_old()[source]

Zoom to the current selection’s manipulator position.

viewport_display_types(flag=None)[source]

Toggle the viewport options.

Possible flags:
  • allObjects

  • nurbsCurves

  • polymeshes

  • joints

  • locators

  • etc…

bgdev.utils.history

Utility methods to deal with history on nodes.

created

11/12/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

delete_history(nodes=None, mode=None)[source]

Delete history on selection.

Parameters
  • nodes (list) – List of nodes. If none given, use selection.

  • mode (str) – Can be “pre-deform” or “non-deform”. If None, simply delete all history on selection.

delete_unused()[source]

Delete unused nodes in the scene.

freeze_transforms(nodes=None, transforms='trsp', history=False)[source]

Freeze transforms on given nodes.

Parameters
  • nodes (list) – List of nodes. If none given, use selection.

  • transforms (str) – Transforms to freeze. e.g. “trs”.

  • history (bool) – Also delete history if True. Default is False.

bgdev.utils.hotkey

Easily create custom hotkey.

created

11/02/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

create_hotkey(name, command, keys, edit=False, annotation='New user script', category='custom', language='python')[source]

Create a user hotkey with its namedCommand.

Parameters
  • name (str) – Name of the command to attach to a hotkey

  • command (str) – The command to run. Must be an executable string.

  • keys (str) – The hotkey to use. If you want modifiers, add them before the keyboard key and separate them with “+”. Eg. “alt+shift+A”.

  • edit (bool) – If a command already exists and you want to update it.

  • annotation (str) – Add an annotation to the command/hotkey

  • category (str) – The category in which you add the command. Default is “Custom Scripts.custom”

  • language (str) – The source language used by the command. Must be either “mel” or “python”

create_hotkeys_from_yaml(path=None)[source]

Quickly re-create custom hotkeys from a yaml file.

valid_keyset()[source]

Make sure the current hotkey set is valid.

bgdev.utils.joints

Utility methods about joints.

created

13/02/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

add_joints(number=None)[source]

Add joints inbetween.

Parameters

number (int) – amount of joints to add. If none given, a prompt will ask the user.

Raises
  • TypeError – If given type is not a number.

  • RuntimeError – If no joints are selected, or only one is but has no children.

show_joint_orient(state=True)[source]

Toggle jointOrient and preferredAngle attributes in channelBox.

Applies to all joints in the scene.

Parameters

state (bool) – True if you want to display jointOrients in channelbox.

bgdev.utils.locators

Utility methods about locators.

created

05/03/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

attach_locators_to_curve()[source]

Attach a locator on each curve CVs.

create_aim_locator(middle=False, aim_vector=(1, 0, 0), up_vector=(0, 1, 0))[source]

Create a locator that’s oriented on the selection.

If selection is 2 or 3, it will use the second as the aim axis, and the third as up. If middle is set to False, it will snap it to the first selected.

Parameters
  • middle (bool) – snap in between points 1 and 2 if True, else on point 1.

  • aim_vector (tuple) – default aim vector for the aimConstraint.

  • up_vector (tuple) – default up vector for the aimConstraint.

Returns

The locator created.

Return type

str

Raises

RuntimeError – If nothing is selected.

locator_on_selection(method='matrix')[source]

Create and snap a locator on selected nodes.

Parameters

method (str) – “matrix” uses Maya’s xform command with matrix flag enabled. “pivot” uses Maya’s xform command with rotatePivot flag enabled. “manip” queries Maya’s move manipulator position and orientation.

bgdev.utils.mesh

Utility methods for meshes.

created

05/03/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

find_phantom_vertices(fix=False)[source]

Find meshes with incorrect amount of vertices.

Parameters

fix (bool) – Apply a fix to remove phantom vertices when True.

mesh_combine_and_keep(nodes=None, visible=True)[source]

Combine meshes and keep the original.

mesh_reorder_callback()[source]

Reorder or remap vertices of selected mesh(es).

bgdev.utils.name

Utility methods that parses names.

created

27/02/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

find_conflicts(query=False)[source]

Create two selection sets to store name conflicts.

Parameters

query (bool) – Only query the nodes without creating sets.

Returns

Two separate lists for conflicting transforms and shapes.

Return type

tuple

generate_unique_name(name)[source]

Generate a unique name based on the given one.

remove_end_digits(node, rename=True)[source]

Remove digits at the end of a name.

Parameters
  • node (str) – Name of the node to “cleanup”

  • rename (bool) – If True, rename the node, else just return the cleaned up name

Returns

Name of the node stripped ouf ot end digits.

Return type

str

remove_end_digits_callback()[source]

Call back remove_end_digits().

rename_deformers(node=None)[source]

Rename all the deformers in the history of the given node.

The name string will be build according to the deformerType and the node name

Parameters

node (str) – The node you want to rename deformers attached to it

Example

>>> node = "L_arm_geo"
>>> deformerType = "skinCluster"
>>> name = L_arm_geo_skinCluster"
rename_deformers_callback()[source]

Call back rename_deformers().

bgdev.utils.pivot

This module deals with pivot import/export.

created

04/01/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

export_to_file(path, rules=None, base_grp='modelHierarchy')[source]

Export pivots matrices.

Parameters
  • path (file) – Path to JSON file

  • rules (dict) – Custom “SkinMap” or it will be autogenerated by generate_data()

  • base_grp (str) – Top group to pass into the data autogeneration function

Returns

The pivot data

Return type

dict

generate_data(base_grp='modelHierarchy')[source]

Autogenerate a dictionary based on constraint nodes in scenes.

The key/value pair is equal to nodes/joints.

Parameters

base_grp (str) – Top group to investigate all descendents from.

Returns

Dictionary that maps the node with its driver.

Return type

dict

import_from_file(path)[source]

Import pivots from json file.

Parameters

path (file) – Path to JSON file

Returns

The data dictionary used

Return type

dict

reset_pivot(mesh, matrix)[source]

Reset given mesh to given matrix.

Parameters
  • mesh (str) – Node to reset pivot

  • matrix (matrix) – Matrix table giving the exact position of the pivot

bgdev.utils.rivet

Utility methods for rivets.

created

15/01/2019

author

Benoit GIELLY <benoit.gielly@gmail.com>

follicle_rivet(vertex=None, name=None)[source]

Create a rivetted locator using follicle.

Parameters
  • vertex (str) – Specify a vertex to attach the rivet to. Use selection otherwise.

  • name (str) – Using this name for the rivet if passed, otherwise create one using the mesh name.

Returns

The rivet locator created.

Return type

str

follicle_rivet_callback()[source]

Create rivets based on selection.

bgdev.utils.scripts

Random scripts and tools (needs to be sorted…).

author

Benoit GIELLY <benoit.gielly@gmail.com>

align_fingers(nodes=None, aim_vector=(1, 0, 0), up_vector=(0, 1, 0), gui=False)[source]

Align selected locators based on first and last plane (use for fingers).

find_bad_meshes()[source]

Find meshes with incorrect amount of vertices.

get_vectors_dialog()[source]

Query aim and up vectors using a LayoutPromptDialog.

logging_time()[source]

Print the logging time.

mirror_position(selected=False)[source]

Mirror selected along world Z+.

quick_distance()[source]

Get distance between two nodes.

set_default_clip_plane()[source]

Create a quick GUI to change de camera clipPlane values option vars.

set_near_clip_plane()[source]

Set nearClipPlane to 1.

show_cam_clip_planes()[source]

Turn nearClip and farClip planes visible in the CB for all cameras.

show_joint_orient(value=True)[source]

Display jointOrient attributes in channel box.

simple_snap(srt=None)[source]

Snap quickly.

snap(**kwargs)[source]

Snap an obj on a target.

time_me(func)[source]

Use this decorator to time functions execution.

toggle_side_select(toggle=True)[source]

Toggle selection.

bgdev.utils.serialize

Utility methods for data serialization (JSON, YAML, PKL, etc…).

created

26/04/2018

author

Benoit Gielly <benoit.gielly@gmail.com>

json_dump(data, path, **kwargs)[source]

Export JSON file.

Parameters
  • data (dict) – Dictionary to export as JSON

  • path (str) – JSON file path to save data

  • kwargs (dict) – Any extra flags to pass in the json.dump() command

Returns

given file path

Return type

str

json_load(path, **kwargs)[source]

Import JSON file.

Parameters
  • path (str) – JSON file path to save data

  • kwargs (dict) – Any extra flags to pass in the json.load() command

Returns

The loaded data.

Return type

dict

yaml_dump(data, path, ordered=False, **kwargs)[source]

Export YAML file.

Parameters
  • data (dict) – Dictionary to export as JSON

  • path (str) – YAML file path to save data

  • ordered (bool) – Dump data ordered when True.

  • kwargs (dict) – Any extra flags to pass in the json.dump() command

Returns

given file path

Return type

str

yaml_load(path, ordered=False, **kwargs)[source]

Import YAML file.

Parameters
  • path (str) – YAML file path to save data

  • ordered (bool) – Load data in an orderedDict when True.

  • kwargs (dict) – Any extra flags to pass in the json.load() command

Returns

the loaded data

Return type

dict

bgdev.utils.shape

Utility methods for shapes.

created

05/03/2017

author

Benoit Gielly <benoit.gielly@gmail.com>

get_shapes(node, intermediate=False, exclusive=False)[source]

Get the shapes of given node.

Parameters
  • node (str) – Node to query its shapes

  • intermediate (bool) – Get intermediate shapes when True.

  • exclusive (bool) – Only return the intermediate shapes if True. Please note that the intermediate flag must be True as well.

Returns

The shapes found below given node.

Return type

list

update_intermediate(source, target)[source]

Update shapeOrig of target with source shape.

This tool also works on nubrsCurve and any deformableShapes. It will only replace one with another.

Parameters
  • source (str) – source node

  • target (str) – target node

update_intermediate_callback()[source]

Call back update intermediate().

update_plug(source_shape, target_shape)[source]

Update the plug.

Parameters
  • source_shape (str) – Name of the source shape.

  • target_shape (str) – Name of the target shape to update.

bgdev.utils.side

Module to deal with sided data.

created

02/07/2018

author

Benoit Gielly <benoit.gielly@gmail.com>

convert_side(data, sides='LR', both=False)[source]

Replace recursively all iterations of {} with side in a data structure.

Parameters
  • data (list or dict) – The data to traverse and update.

  • sides (str) – The sides to replace brackets with.

  • both (bool) – By default, if the key is “sided”, the values associated will only get the same side as the key. Otherwise, values will get both sides. Default is False.

Example

data = side.convert_side({
    "spine_01_grp": "spine_01_jnt",
    "{}_shoulder_mechanic_grp": "{}_arm_shoulder_jnt",
    "{}_knee_pistons_grp": "{}_leg_knee_jnt",
})

>>> # Result: {"L_knee_pistons_grp": "L_leg_knee_jnt",
     "L_shoulder_mechanic_grp": "L_arm_shoulder_jnt",
     "R_knee_pistons_grp": "R_leg_knee_jnt",
     "R_shoulder_mechanic_grp": "R_arm_shoulder_jnt",
     "spine_01_grp": "spine_01_jnt"} #
Returns

An updated and sided copy of the given data.

Return type

dict or list

bgdev.utils.skincluster

Utility methods for skinclusters.

created

26/02/2017

author

Benoit Gielly <benoit.gielly@gmail.com>

add_influences(node, joints)[source]

Add given joints to the skincluster.

Parameters
  • node (str) – Can be either the skincluster or the bound node.

  • joints (list) – List of joints/influences to add.

Raises

RuntimeError – If the skincluster cannot be found.

add_influences_callback()[source]

Call back add_influences().

bind_skincluster(mesh=None, bones=None)[source]

Create a new skincluster with preset options.

Parameters
  • mesh (str) – Name of the geometry to bind.

  • bones (list) – List of bones/influences.

Returns

The created skincluster.

Return type

str

bind_skincluster_callback()[source]

Call back bind_skincluster().

copy_skincluster(source, target, method='closestPoint')[source]

Copy source skincluster onto target and keep same weights.

Parameters
  • source (str) – source mesh to copy skincluster form

  • target (str) – target mesh to paste skincluster to

  • method (str) – influence association method. Default is closestPoint.

Raises

RuntimeError – If the source skincluster cannot be found.

copy_skincluster_callback(method='closestPoint')[source]

Call back copy_skincluster().

detach_skincluster(node, clean=False)[source]

Detach the skin cluster attached to given node.

Parameters
  • node (str) – Name of the node to unbind.

  • clean (bool) – If True, remove shapeOrigs and unlock transforms.

detach_skincluster_callback(clean=False)[source]

Call back detach_skincluster().

get_influences(node, weighted=False)[source]

Get influences of given skincluster.

Parameters
  • node (str) – Can be either the skincluster or the bound node.

  • weighted (bool) – If True, returns only weighted influences.

Returns

List of influences.

Return type

list

Raises

RuntimeError – If the skincluster cannot be found.

get_skincluster(node)[source]

Return the skincluster of given node.

If the passed node already is a skincluster, just return it.

Parameters

node (str) – Can be either the skincluster or the bound node.

Raises

RuntimeError – If the skincluster cannot be found.

Returns

The skincluster bound to the node.

Return type

str

remove_influences(node, joints=None, unused=False, disconnect=False)[source]

Remove given joints from the skincluster.

Parameters
  • node (str) – Can be either the skincluster or the bound node.

  • joints (list) – List of joints/influences to add.

  • unused (bool) – Removed all unused influences found. This flag ignores joints when used.

Raises

RuntimeError – If the skincluster cannot be found.

remove_influences_callback(unused=False)[source]

Call back remove_influences().

reset_skincluster(node)[source]

Reset the skin cluster in place.

Parameters

node (str) – SkinCluster node or the geometry bound to it.

reset_skincluster_callback()[source]

Call back reset_skincluster().

select_influences_callback()[source]

Call back select_influences().

bgdev.utils.sort

Utility methods used to sort nodes and graphs.

created

05/03/2017

author

Benoit GIELLY <benoit.gielly@gmail.com>

sort_children(parent=None)[source]

Sort children of the given parent alphabetically.

Parameters

parent (str) – Name of the parent to use as a starting point.

sort_descendants()[source]

Sort all descandant children alphabetically.

sort_selection()[source]

Sort all children node alphabetically.

bgdev.utils.transform

Utility methods for transforms.

created

16/02/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

reset_group(node, suffix='_grp')[source]

Create a transform node to reset the value of the selected object.

Parameters
  • node (str) – name of node to reset

  • suffix (str) – suffix to use for the reset group name

Returns

reset group

Return type

str

reset_groups(suffix='_grp')[source]

Run reset_group() on a selection of multiple nodes.

Parameters

suffix (str) – suffix to use for the reset group name

Returns

all reset group created

Return type

list

bgdev.utils.vector

Utility methods to help dealing with vectors.

created

10/10/2016

author

Benoit GIELLY <benoit.gielly@gmail.com>

aim_in_plane(positions, aim_vector=(1, 0, 0), up_vector=(0, 1, 0))[source]

Align selected locators based on plane made of the first and last.

from_euler(rotation, translate=(0, 0, 0), radians=False)[source]

Convert euler rotation into 3-axis matrix.

Parameters
  • rotation (tuple) – Rotation values to add to the matrix table.

  • translate (tuple) – Translation values to add to the matrix table.

  • radians (bool) – If True, converts degrees to radians.

Returns

Matrix of given euler rotates, with translate if given.

Return type

list

get_closest_point(source, targets, furthest=False)[source]

Find the closest node to the source of each targets.

Parameters
  • source (str) – source node to use as starting point for distance calculation.

  • targets (list) – each nodes to process.

  • furthest (bool) – If True, gets the furthest node instead.

Returns

the target node that’s the closest to the source.

Return type

str

get_distance_between(node1, node2, distance_between=False, bounding_box=False, rotate_pivot=False)[source]

Get the distance between two objects.

Parameters
  • node1 (str) – Node that determines start position

  • node2 (str) – Node that determines end position

  • distance_between (bool) – If True, creates a distance_between node, query its value and delete it.

  • bounding_box (bool) – If True, creates a distance_between node,

  • rotate_pivot (bool) – If True, creates a distance_between node,

Returns

distance between two given nodes.

Return type

float

get_manipulator_xforms(as_matrix=False)[source]

Query the manipulator position and orientation.

Parameters

as_matrix (bool) – if True, returns a as_matrix built from manip xforms.

Returns

list of “XYZ” position and rotation values

or matrix array if as_matrix is True.

Return type

list

get_matrix_from_nodes(nodes, middle=True, aim_vector=(1, 0, 0), up_vector=(0, 1, 0))[source]

Return a matrix based on given nodes.

If passed nodes are 1 or more than 3, it simply return the manipulator position as a matrix. Otherwise, it’ll use the second node as the aim axis and the third as up.

Parameters
  • nodes (list) – list of nodes to get matrix

  • middle (bool) – snap in between nodes 1 and 2 if True, else on first.

  • aim_vector (tuple) – default aim vector for the aimConstraint.

  • up_vector (tuple) – default up vector for the aimConstraint.

Returns

matrix array.

Return type

list

get_matrix_from_transforms(position, normal, tangent)[source]

Construct an MMatrix from position, normal and tangent.

Parameters
  • position (list) – XYZ position.

  • normal (list) – The normal vector used to compute rotation.

  • tangent (list) – The tangent vector used to compute rotation.

Returns

The MMatrix array.

Return type

MMatrix

get_vectors(nodes, mode='xform')[source]

Generate world position vectors of each given nodes.

Parameters
  • nodes (list) – list of nodes to return position as vector.

  • mode (str) – choose between default “xform” or “pivot” to get world position.

Yields

maya.api.OpenMaya.MVector – MVector of the node’s world position

bgdev.utils.weightmap

Utility method to deal with weightmaps.

created

13/12/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

check_libraries()[source]

Check if ngSkinTools package is available.

Returns

A mapping dict with the required ngSkinTool modules.

Return type

dict

Raises
  • ImportError – If the package can’t be imported.

  • RuntimeError – If the package can’t be imported.

export_layer_data(node, data, path)[source]

Export ngLayerData into JSON file.

Parameters
  • node (str) – Name of the mesh. Used as filename.

  • data (dict) – The ngLayer dictionary to export.

  • path (str) – The parent folder where the file will be saved into.

export_multiple_skinweights(nodes, path='weights')[source]

Export multiple skinweights into a single file.

Parameters
  • nodes (str) – List of nodes to export their skinweights.

  • path (str) – File path to export weights.

export_skinweights(node, path='weights', export=True)[source]

Export the weights of the given skincluster node.

Parameters
  • node (str) – Name of the skinned node to export its weights.

  • path (str) – File path to export the weights.

  • export (bool) – Export weights into a file. Defaults to True. Use False when you only want the weights data.

Returns

The weights data.

Return type

dict

export_skinweights_callback()[source]

Call back export_skinweights().

import_layer_data(node, path)[source]

Import ngLayerData from JSON file.

Parameters
  • node (str) – Name of the mesh. Used to find the JSON file.

  • path (str) – The parent folder where the file is saved.

Returns

The raw ngLayer data (somehow, this is a string!)

Return type

str

import_multiple_skinweights(path, layers=True)[source]

Import multiple skinweights into a single file.

Parameters
  • path (str) – File path to export weights.

  • layers (bool) – Keep ngSkinTools layers or not.

import_skinweights(node, path='weights', data=None, layers=True, mode='vertexID')[source]

Export the weights of the given skincluster node.

Parameters
  • node (str) – Name of the skinned node to export its weights.

  • path (str) – File path to export the weights.

  • data (dict) – Use this data directly instead of reading if from file.

  • layers (bool) – Keep ngSkinTools layers or not.

  • mode (str) – Can be “vertexID”, “UV” or “closestPoint”. Defaults to “vertexID”.

import_skinweights_callback()[source]

Call back import_skinweights().

initialize_layers(node)[source]

Remove ngSkinTools layers.

Parameters

node (str) – Name of the mesh with a skinCluster attached.

Returns

True if layers were created, false otherwise.

Return type

bool

remove_layers(node)[source]

Remove ngSkinTools layers.

Parameters

node (str) – Name of the mesh with a skinCluster attached.

bgdev.cfg

Config module to pass data accross the repository project.

Warning

NEVER RELOAD THIS MODULE. If you do you, you will lose all the data that was stored by the application instance.

created

12/12/2018

author

Benoit GIELLY <benoit.gielly@gmail.com>

bgdev.docstring

Docstring template using Google convention.

created

16/11/2018

author

Benoit Gielly <benoit.gielly@gmail.com>

This module is just a template to show how to write proper docstrings using the Google’s syntax. It will show you all the different applications and keywords you can use so sphinx can generate a nice looking documentation!

You can find a link to the Google Docstring guide here:

http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Happy docstring-ing! :D

class ExampleClass(param1, param2, param3)[source]

Bases: object

The summary line for a class docstring should fit on one line.

If the class has public attributes, they may be documented here in an Attributes section and follow the same formatting as a function’s Args section. Alternatively, attributes may be documented inline with the attribute’s declaration (see __init__ method below).

Properties created with the @property decorator should be documented in the property’s getter method.

attr1

Description of attr1.

Type

str

attr2

Description of attr2.

Type

int, optional

Parameters
  • param1 (str) – Description of param1.

  • param2 (int) – Description of param2. Multiple lines are supported.

  • param3 (list(str)) – Description of param3.

Note

Do not include the self parameter in the Args section.

__init__(param1, param2, param3)[source]

Class constructor.

You should avoid documenting classes in the __init__ method of the class. It should go within the class docstring instead.

attr3

Doc comment inline with attribute

attr4

Doc comment before attribute, with type specified

Type

list(str)

attr5

Docstring after attribute, with type specified.

Type

str

example_method(param1, param2)[source]

Class methods are similar to regular functions.

See example_function() for a better description.

Note

Do not include the self parameter in the Args section.

property getter_only_property

Properties should be documented in their getter method.

Type

str

property getter_setter_property

Get a property.

If the setter method contains notable behavior, it should be mentioned here.

Parameters
  • value (str) – Properties with both a getter and setter

  • only be documented in their getter method. (should) –

Returns

The returned value/object.

Return type

list

example_decorated_function(arg)[source]

Test the docstring to ensure the @wraps decorator worked.

Parameters

arg (str) – Description of arg1

Returns

The first argument arg1

Return type

type

example_decorator(func)[source]

Decorate a method.

Decorators need a special treatment to generate the documentation properly. You have to decorate the sub-function with the wraps method of the functools module. If you don’t, the docstring of the decorated function will be skipped.

Example

from functools import wraps

def example_decorator(func):
    "Decorator docstring"

    @wraps(func)
    def function(*args, **kwargs):
        returned_func = func(*args, **kwargs)
        return returned_func
    return function
example_function(param1, param2=None, *args, **kwargs)[source]

Show an example of a module level function.

Function parameters should be documented in the Args section. The name of each parameter is required. The type and description of each parameter is optional, but should be included if not obvious.

If *args or **kwargs are accepted, they should be listed as *args and **kwargs.

The format for a parameter is:

name (type): description
    The description may span multiple lines. Following
    lines should be indented. The "(type)" is optional.

    Multiple paragraphs are supported in parameter
    descriptions.
Parameters
  • param1 (int) – The first parameter.

  • param2 (str) – The second parameter. Defaults to None. Second line of description should be indented.

  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Returns

True if successful, False otherwise.

The return type is optional and may be specified at the beginning of the Returns section followed by a colon.

The Returns section may span multiple lines and paragraphs. Following lines should be indented to match the first line.

The Returns section supports any reStructuredText formatting, including literal blocks:

{
    'param1': param1,
    'param2': param2
}

Return type

bool

Raises
  • AttributeError – The Raises section is a list of all exceptions that are relevant to the interface.

  • ValueError – If param2 is equal to param1.

Example

Examples should be written in doctest format, and should illustrate how to use the function.

>>> print([i for i in range(4)])
[0, 1, 2, 3]

Examples

You can also use literal blocks:

print([i for i in range(4)])
>>> [0, 1, 2, 3]

Todo

  • The Todo section lists in an orange block every task that needs to be done.

  • Make sure to use an * (asterisk) to display bullet points

example_function_with_types(arg1, arg2)[source]

Show an example function with types documented in the docstring.

PEP 484 type annotations are supported. If attribute, parameter, and return types are annotated according to PEP 484, they do not need to be included in the docstring:

Parameters
  • arg1 (int) – The first parameter.

  • arg2 (str) – The second parameter.

Returns

The return value. True for success, False otherwise.

Return type

bool

example_generator(num)[source]

Create generators.

They have a Yields section instead of a Returns section.

Parameters

num (int) – The upper limit of the range to generate, from 0 to num - 1.

Yields

int – The next number in the range of 0 to num - 1.

Release Notes

1.0.0 (2020-12-10)

  • First public release of the repo

Module Index

Index