phobos.utils package

Submodules

phobos.utils.blender module

Contains all utility functions that are connected to Blender functionality first.

phobos.utils.blender.cleanObjectProperties(props)

Cleans a predefined list of Blender-specific or other properties from the dictionary.

Parameters:props

Returns:

phobos.utils.blender.cleanScene()

Clean up blend file (remove all objects, meshes, materials and lights)

phobos.utils.blender.compileEnumPropertyList(iterable)
Parameters:iterable

Returns:

phobos.utils.blender.createNewTextfile(textfilename, contents)

This function creates a new blender text file with the given content.

Parameters:
  • textfilename (str) – The new blender texts name.
  • contents (str) – The new textfiles content.

Returns:

phobos.utils.blender.createPreview(objects, export_path, modelname, render_resolution=256, opengl=False)

Creates a thumbnail of the given objects.

Parameters:
  • objects (list of bpy.types.Object) – list of objects for the thumbnail
  • export_path (str) – folder to export image to
  • modelname (str) – name of model (used as file name)
  • render_resolution (int, optional) – side length of resulting image in pixels (Default value = 256)
  • opengl (bool, optional) – whether to use opengl rendering or not (Default value = False)

Returns:

phobos.utils.blender.createPrimitive(pname, ptype, psize, player=0, pmaterial=None, plocation=(0, 0, 0), protation=(0, 0, 0), phobostype=None)

Generates the primitive specified by the input parameters

Parameters:
  • pname (str) – The primitives new name.
  • ptype (str) – The new primitives type. Can be one of box, sphere, cylinder, cone, disc
  • psize (float or list) – The new primitives size. Depending on the ptype it can be either a single float or a tuple.
  • player – The layer bitmask for the new blender object. (Default value = 0)
  • pmaterial – The new primitives material. (Default value = None)
  • plocation (tuple, optional) – The new primitives location. (Default value = (0)
  • protation (tuple, optional) – The new primitives rotation. (Default value = (0)
  • phobostype (str, optional) – phobostype of object to be created (Default value = None)
  • 0
  • 0)
Returns:

bpy.types.Object - the new blender object.

phobos.utils.blender.defLayers(layerlist)

Returns a list of 20 elements encoding the visible layers according to layerlist

Parameters:layerlist

Returns:

phobos.utils.blender.getBlenderVersion()

TODO Missing documentation

phobos.utils.blender.getCombinedDimensions(objects)

Returns the dimension of the space the objects passed occupy.

Parameters:objects (list) – list of
Returns:list of floats (x, y, z) of dimensions
Raises:ValueError – If empty object list is passed.
phobos.utils.blender.getPhobosConfigPath()

Returns the user-defined config path if set or the default-path

Returns(str): (user-defined) config path

Args:

Returns:

phobos.utils.blender.getPhobosPreferences()

TODO Missing documentation

phobos.utils.blender.openScriptInEditor(scriptname)

This function opens a script/textfile in an open blender text window. Nothing happens if there is no available text window.

Parameters:scriptname (str) – The scripts name.

Returns:

phobos.utils.blender.printMatrices(obj, info=None)

This function prints the matrices of an object to the screen.

Parameters:
  • obj (bpy.types.Object) – The object to print the matrices from.
  • info (bool, optional) – If True the objects name will be included into the printed info. (Default value = None)

Returns:

phobos.utils.blender.readTextFile(textfilename)

Returns the content of a specified text file in Blender’s data.

If the file is not found, an empty string is returned.

Parameters:textfilename (str) – The blender textfiles name.
Returns:str – textfile content or empty string
phobos.utils.blender.setObjectLayersActive(obj, extendlayers=False)

Sets all layers, the specified object is on to active.

If extendlayers is set, the layers of the object are added to the already active layers instead of replacing them.

Parameters:
  • obj (bpy.types.Object) – object of which the layers shall be activated
  • extendlayers (bool, optional) – activate the object layers in addition to the already active layers (Default value = False)

Returns:

phobos.utils.blender.switchToScene(scenename)

Switch to Blender scene of the given name

Parameters:scenename

Returns:

phobos.utils.blender.toggleLayer(index, value=None)

This function toggles a specific layer or sets it to a desired value.

Parameters:
  • index (int) – The layer index you want to change.
  • value (bool, optional) – True if visible, None for toggle. (Default value = None)

Returns:

phobos.utils.blender.toggleTransformLock(obj, setting=None)

Toogle transform lock for the referred object

Parameters:
  • obj
  • setting – (Default value = None)

Returns:

phobos.utils.blender.update()

Forces Blender to update scene contents (i.e. transformations).

Sometimes when e.g. manipulating internal matrices of Blender objects such as matrix_world or matrix_local, Blender will not recalculate all related transforms, especially not the visual transform. The bpy.context.scene.update() function often named as the solution to this will lead to the matrices being updated, but not the visual transforms. This Function runs code (may be updated with new Blender verions) that forces Blender to update the visual transforms.

Args:

Returns:

phobos.utils.blender.updateTextFile(textfilename, newContent)

This function updates a blender textfile or creates a new one if it is not existent.

Parameters:
  • textfilename (str) – The blender textfiles file name.
  • newContent (str) – The textfiles new content.

Returns:

phobos.utils.editing module

Contains the utility functions for editing objects and Phobos models.

phobos.utils.editing.addAnnotation(obj, annotation, namespace=None, ignore=[])

Adds the specified annotations to the object.

If provided, the namespace will be prepended to the annotation keys and separated with a /.

Parameters:
  • obj (bpy.types.Object) – object to add the annotations to
  • annotation (dict) – annotations to add to the object
  • namespace (str, optional) – namespace which will be prepended to the annotations (Default value = None)
  • ignore (list(str, optional) – skip these keys when adding annotations (Default value = [])

Returns:

phobos.utils.editing.addAnnotationObject(obj, annotation, name=None, size=0.1, namespace=None)

Add a new annotation object with the specified annotations to the object.

The annotation object will receive ‘annotation_object’ as its default name, unless a name is provided. Naming is done using phobos.utils.naming.safelyName().

The annotation object will be scaled according to the size parameter.

If namespace is provided, the annotations will be saved with this string prepended. This is done using addAnnotation().

Parameters:
  • obj (bpy.types.Object) – object to add annotation object to
  • annotation (dict) – annotations that will be added
  • name (str, optional) – name for the new annotation object (Default value = None)
  • size (int/float, optional) – size of the new annotation object (Default value = 0.1)
  • namespace (str, optional) – namespace that will be prepended to the annotations (Default value = None)
Returns:

bpy.types.Object - the new annotation object

phobos.utils.editing.connectInterfaces(parentinterface, childinterface, transform=None)
Parameters:
  • parentinterface
  • childinterface
  • transform – (Default value = None)

Returns:

phobos.utils.editing.createInterface(ifdict, parent=None)

Create an interface object and optionally parent to existing object.

ifdict is expected as:

type: str
direction: str
model: str
name: str
parent: bpy.types.Object (optional)
scale: float (optional)
Parameters:
  • ifdict (dict) – interface data
  • parent (bpy.types.Object, optional) – designated parent object (Default value = None)
Returns:

newly created interface object

Return type:

bpy.data.Object

phobos.utils.editing.defineSubmodel(submodelname, submodeltype, version='', objects=None)

Defines a new submodule group with the specified name and type.

The group will be named like so:
‘submodeltype:submodelname/version’

Objects with the phobostype ‘interface’ (if present) are handled separately and put into a respective submodel group (which features the ‘interface’ submodeltype).

If the version is omitted, the respective part of the name is dropped, too. If no object list is provided the objects are derived from selection. The submodeltype is also added as dict entry to the group in Blender.

The selected objects are moved to the respective layer for submodels or interfaces.

Parameters:
  • submodelname – descriptive name of the submodel
  • submodeltype – type of the submodel (e.g. ‘fmu’, ‘mechanics’)
  • version – a version string (e.g. ‘1.0’, ‘dangerous’) (Default value = ‘’)
  • objects – the objects which belong to the submodel (None will derive

objects from the selection) (Default value = None)

Returns:a tuple of the submodelgroup and interfacegroup/None
phobos.utils.editing.disconnectInterfaces(parentinterface, childinterface, transform=None)
Parameters:
  • parentinterface
  • childinterface
  • transform – (Default value = None)

Returns:

Remove the selected link and reparent all links, inertia, visual and collisions to its effective Parent.

Parameters:
  • obj (bpy.types.Object) – the link to dissolve
  • delete_other – (Default value = False)

Returns:

phobos.utils.editing.getCombinedTransform(obj, effectiveparent)

Get the combined transform of the object relative to the effective parent.

This combines all transformations in the parenting hierarchy up to the specified effective parent.

Note, that the scale transformation of the effective parent is used anyway, as it scales the local matrix of the child object.

Parameters:
  • obj (bpy.types.Object) – the child object
  • effectiveparent (bpy.types.Object) – the effective parent of the child object
Returns:

bpy.types.Matrix – the combined transformations of the child object

phobos.utils.editing.getNearestCommonParent(objs)

Returns hierarchically lowest common parent of the provided objects

Parameters:objs – list of objects (bpy_types.Object)

Returns:

phobos.utils.editing.getProperties(obj, category=None)

Returns a dictionary of custom property information of the object.

If a category is provided, only the custom properties of the specified category are returned. Otherwise, the phobostype of the object will be used as category.

The dictionary contains the custom property keys with the category removed (e.g. ‘name’ for ‘link/name’).

Parameters:
  • obj (bpy.types.Object) – object to get properties of
  • category (str, optional) – property category to look for (Default value = None)
Returns:

dict – custom property information of the phobostype/category for the object

phobos.utils.editing.instantiateSubmodel(submodelname, instancename, size=1.0)

Creates an instance of the submodel specified by the submodelname.

The instance receives the definitions of the group as it is generated.

Parameters:submodelname – name of the submodel (Blender group) to create an
instance of
instancename: name the instance object will receive size: (Default value = 1.0)

Returns:

Parameters:
  • links
  • targetlink
  • movetotarget – (Default value = False)

Returns:

phobos.utils.editing.parentObjectsTo(objects, parent, clear=False)

Parents the specified objects to the parent object.

Depending on their phobostype the objects are parented either bone relative or object.

If clear is set, the parenting of the objects will be cleared (keeping the transform), before parenting.

Parameters:
  • objects (list(bpy.types.Object) – objects to set parent of
  • parent (bpy.types.Object) – parent object
  • clear (bool, optional) – if True, the parenting of the objects will be cleared (Default value = False)

Returns:

phobos.utils.editing.removeProperties(obj, props, recursive=False)

Removes a list of custom properties from the specified object.

The specified property list can contain names with wildcards at the end (e.g. sensor*).

If recursive is set, the properties will be removed recursively from all children, too.

Parameters:
  • obj (bpy.types.Object) – object to remove the properties from
  • props (list(str) – list of property names, which will be removed from the object
  • recursive (bool, optional) – if True, the properties will be removed recursively from the children, too (Default value = False)

Returns:

phobos.utils.editing.removeSubmodel(submodelname, submodeltype, version='', interfaces=True)

Removes a submodel definition from the Blender project. Returns True or False depending on whether groups have been removed or not.

Parameters:
  • submodelname – the name of the submodel
  • submodeltype – the submodeltype of the submodel
  • version – optional version of the submodel (Default value = ‘’)
  • interfaces – True if interface should also be deleted, else False. (Default value = True)
Returns:

True if groups have been removed, else False.

phobos.utils.editing.restructureKinematicTree(link, root=None)

Restructures a tree such that the link provided becomes the root of the tree.

If no root object is provided, phobos.utils.selection.getRoot() will be used.

For instance, the following tree:

    A
   / \
  B   C
 / \   \
D   E   F

would, using the call restructureKinematicsTree(C), become:

      C
     / \
    A   F
   /
  B
 / \
D   E

Currently, this function ignores all options such as unselected or hidden objects.

Parameters:
  • link (bpy.types.Object) – the link which will become the new root object
  • root (bpy.types.Object, optional) – the current root object (Default value = None)
Returns:

None

Return type:

None

phobos.utils.editing.setProperties(obj, diction, category=None)

Adds the specified dictionary as custom properties to the object.

If a category is provided, the keys of the dictionary are prepended with the category:
category/key
Parameters:
  • obj (bpy.types.Object) – object to add the information to
  • diction (dict) – information to add to the object
  • category (str, optional) – category for the dictionary entries (Default value = None)

Returns:

phobos.utils.editing.smoothen_surface(obj)

Applies various steps to make the specified object look clean and smooth.

Parameters:obj (bpy.types.Object) – object to make look clean

Returns:

phobos.utils.editing.sortObjectsToLayers(objs)

Sorts the specified objects to the layers which match their phobostype.

The layer for each phobostype is defined according to phobos.defs.layerTypes.

Parameters:objs (list(bpy.types.Object) – objects to move to their respective layer

Returns:

phobos.utils.editing.toggleInterfaces(interfaces=None, modename='toggle')
Parameters:
  • interfaces – (Default value = None)
  • modename – (Default value = ‘toggle’)

Returns:

phobos.utils.general module

Contains the basic utility functions to round numbers, convert types etc.

phobos.utils.general.calcBoundingBoxCenter(boxcorners)

Calculates the center of a bounding box.

Parameters:boxcorners (list(list(float) – coordinates of the eight cornerpoints of the box
Returns:mathutils.Vector – centerpoint of the bounding box
phobos.utils.general.calculateSum(objects, numeric_prop)

Returns sum of numeric_prop in objects.

Parameters:
  • objects (list(bpy.types.Object) – objects to sum up the property for
  • numeric_prop (str) – name of the custom property to sum
Returns:

float/int – sum of the values in the property of the objects

phobos.utils.general.copyTree(src, dst, symlinks=False, ignore=None)

Copies the folder tree from src to dst.

Symlinks and ignore can be specified according to the usage of shutil.copytree and shutil.copy2.

Parameters:
  • src (str) – path to the source folder/item
  • dst (str) – path to the destination folder/item
  • symlinks (bool, optional) – whether to copy symlinks to the destination (Default value = False)
  • ignore (callable, optional) – callable function (see shutil.copytree) (Default value = None)

Returns:

phobos.utils.general.datetimeFromIso(iso)

Accepts a date-time string in ISO format and returns a datetime object.

Parameters:iso (str) – ISO format string for a date and time
Returns:datetime.datetime – datetime object from the specified string
phobos.utils.general.distance(objects)

Returns the distance between two Blender objects.

Parameters:objects (list(bpy.types.Object) – exactly two Blender objects
Returns:tuple(float, mathutils.Vector) – distance and distance vector between the Blender objects
phobos.utils.general.is_float(text)

Tests if the specified string represents a float number.

Parameters:text (str) – text to check
Returns:bool – True if the text can be parsed to a float, False if not.
phobos.utils.general.is_int(text)

Tests if the specified string represents an integer number.

Parameters:text (str) – text to check
Returns:bool – True if the text can be parsed to an int, False if not.
phobos.utils.general.only_contains_float(stringlist)

Checks if a list of strings contains float numbers exclusively.

To determine whether the number is a float, the function is_float is used.

Parameters:stringlist (list(str) – list to check
Returns:bool – True if every string in the list can be represented as float, False if not
phobos.utils.general.only_contains_int(stringlist)

Checks if a list of strings contains int numbers exclusively.

To determine whether the number is an int, the function is_int is used.

Parameters:stringlist (list(str) – list to check
Returns:bool – True if every string in the list can be represented as int, False if not
phobos.utils.general.outerProduct(v, u)

Returns a mathutils.Matrix representing the outer product of vectors v and u.

Parameters:
  • v (mathutils.Vector) – first vector
  • u (mathutils.Vector) – second vector
Returns:

mathutils.Matrix – outer product of v and u

phobos.utils.general.parse_number(text)

Returns the specified string parsed to an int or float.

If no number can be parsed, the original string is returned.

To determine whether the number is an int or float, the functions is_int and is_float are used.

Parameters:text (string) – text to parse to a number
Returns:int/float/str – depending on successful parsing, a number or a string is returned
phobos.utils.general.parse_text(text)

Parses a text by splitting up elements separated by whitespace.

The elements are then parsed to int/float-only lists.

Parameters:text (str) – text with elements seperated by whitespace
Returns:list(str/float/int) – list with elements parsed to the same type
phobos.utils.general.roundFloatsInDict(data, decimals)

Recursively rounds all floats in the dictionary to the specified decimal digits.

If a float value is smaller than 10e-decimals it is set to zero.

Parameters:
  • data (dict) – data dictionary
  • decimals (int) – number of decimals floats should be rounded to
Returns:

dict – dictionary with rounded floats

phobos.utils.general.sortListsInDict(data, reverse=False)

Recursively loops through a dictionary and sorts all lists.

Parameters:
  • data (dict) – data dictionary
  • reverse – (Default value = False)
Returns:

dict – sorted dictionary

phobos.utils.git module

phobos.utils.git.checkoutBranch(branch, workingdir, create=False, pushorigin=False)
Parameters:
  • branch
  • workingdir
  • create – (Default value = False)
  • pushorigin – (Default value = False)

Returns:

phobos.utils.git.checkoutCommit(commit, workingdir)
Parameters:
  • commit
  • workingdir

Returns:

phobos.utils.git.cloneGit(name, url, destination)

Clones the git repository which is specified by its url into the folder with the specified name in the destination folder. If the url provides the https:// start, it might be necessary to enter gituser and password into commandline, so better use the git@git start. If the destination folder is a git already, it will not be cloned, but True will be returned. If the destination folder does not exist, it is created on the fly.

Parameters:
  • name
  • url
  • destination

Returns:

phobos.utils.git.commit(destination, message='Automated commit', ignore=[])

Commits the current status in the git folder at destination. This can ignore the first level subfolders and files specified in the optional parameter.

Parameters:
  • destination
  • message – (Default value = ‘Automated commit’)
  • ignore – (Default value = [])
Returns:

TODO

phobos.utils.git.createNewBranch(branch, workingdir, pushorigin=False)
Parameters:
  • branch
  • workingdir
  • pushorigin – (Default value = False)

Returns:

phobos.utils.git.getFetchRemotesList(self, context)
Parameters:context

Returns:

phobos.utils.git.getGitBranch()

Checks whether working directory (of .blend file) contains a git repository. Returns branch if repository is found.

Args:

Returns:

phobos.utils.git.getGitRemotes(category='', folder=None)

Returns a dictionary with git remotes of the shape {name: url, …} if valid category is provided, else {‘fetch’: {name: url, …}, ‘push’: {name: url, …}}.

Parameters:
  • category – (Default value = ‘’)
  • folder – (Default value = None)

Returns:

phobos.utils.git.getPushRemotesList(self, context, folder=None)
Parameters:
  • context
  • folder – (Default value = None)

Returns:

phobos.utils.git.initGit(destination, filename=None, initialsave=False, url=None, readmetxt='')

Creates a new Phobos git in the specified destination folder. This also creates the required folder structure. Optionally, the git can be pushed to the specified url (as origin) and an initial commit can be created.

Parameters:destination – the destination folder on the filesystem where to
initialise the git repository
filename: the filename of the blender file to save
(only useful in combination with initialsave) (Default value = None)
initialsave: True if the blendfile shall be saved for the first
commit already, False if not (Default value = False)
url: the url of the origin repository (it needs to be empty!) (Default value = None) readmetxt: a string which will be written to the Readme.md (Default value = ‘’)
Returns:True if the initialisation was successful, False if not
phobos.utils.git.isGit(folder)

Checks whether the folder contains a git directory.

Parameters:folder

Returns:

phobos.utils.git.makeGitFolders(destination)

Create the Phobos folder structure for a git at the destination.

Parameters:destination – TODO
Returns:TODO

phobos.utils.io module

phobos.utils.io.copy_model(model)

Returns a recursive deep copy of a model dictionary.

The deep copy recreates dictionaries and lists, while keeping Blender objects and everything else untouched.

This function is required, as we can not use copy.deepcopy() due to the Blender objects in our Phobos representation.

Parameters:model (dict) – model dictionary to copy
Returns:dict – deep copy of the model dictionary
phobos.utils.io.exportModel(model, exportpath='.', entitytypes=None)

Exports model to a given path in the provided formats.

Parameters:
  • model (dict) – dictionary of model to export
  • exportpath (str, optional) – path to export root (Default value = ‘.’)
  • entitytypes (list of str, optional) – export types - model will be exported to all (Default value = None)

Returns:

phobos.utils.io.exportScene(scenedict, exportpath='.', scenetypes=None, export_entity_models=False, entitytypes=None)

Exports provided scene to provided path

Parameters:
  • scenedict (dict) – dictionary of scene
  • exportpath (str, optional) – path to scene export folder (Default value = ‘.’)
  • scenetypes (list of str, optional) – export types for scene - scene will be exported to all (Default value = None)
  • export_entity_models (bool, optional) – whether to export entities additionally (Default value = False)
  • entitytypes (list of str, optional) – types to export entities in in case they are exported (Default value = None)

Returns:

phobos.utils.io.getAbsolutePath(path)

Returns an absolute path derived from the .blend file

Parameters:path

Returns:

phobos.utils.io.getDictFromYamlDefs(phobostype, defname, name)

Returns a phobos representation of the object specified by the definition parameters.

Parameters:
  • phobostype (str) – phobostype of the definition
  • defname (str) – name of the individual definition
  • name (str) – name for the new object
Returns:

dict – phobos representation from the definition

phobos.utils.io.getEntityRoots()

Returns all objects for which entity properties are specified.

Args:

Returns:roots of well-defined entities in the scene
Return type:list
phobos.utils.io.getEntityTypesForExport()

Returns list of entity types available for export

phobos.utils.io.getEntityTypesForImport()

Returns list of entity types available for import

phobos.utils.io.getExpSettings()

Returns Phobos’ export settings as displayed in the GUI

phobos.utils.io.getExportModels()

Returns a list of objects representing a model (root) in the Blender scene

phobos.utils.io.getExportPath()

Returns the root path of the export.

Phobos by default creates directories in this path for every format that is used for export, i.e. a folder “export/path/urdf” will be created for URDF files.

Args:

Returns:

phobos.utils.io.getMeshTypesForExport()

Returns list of mesh types available for export

phobos.utils.io.getMeshTypesForImport()

Returns list of mesh types available for import

phobos.utils.io.getModelListForEnumProp(self, context)

Returns list of all exportable models in the scene formatted for an EnumProperty

Parameters:context

Returns:

phobos.utils.io.getOutputMeshpath(path, meshtype=None)

Returns the folder path for mesh file export as specified in the GUI.

Phobos by default creates a directory ‘meshes’ in the export path and subsequently creates sub-directories of “export/path/meshes” for every format, e.g. resulting in “export/path/mesh/obj” for .obj file export.

Parameters:
  • path (str) – export path root (set in the GUI)
  • meshtype (str, optional) – a valid mesh type, otherwise the type set in the GUI is used (Default value = None)
Returns:

output path for meshes

Return type:

string

phobos.utils.io.getOutputMeshtype()

Returns the mesh type to be used in exported files as specified in the GUI

phobos.utils.io.getResource(specifiers)

Returns a resource object defined by an iterable of strings.

Parameters:specifiers (iterable) – strings specifying the resource
Returns:bpy.types.Object – resource object (or None if it could not be imported)
phobos.utils.io.getSceneTypesForExport()

Returns list of scene types available for export

phobos.utils.io.getSceneTypesForImport()

Returns list of scene types available for import

phobos.utils.io.importBlenderModel(filepath, namespace='', prefix=False)

Imports an existing Blender model into the current .blend scene

Parameters:
  • filepath (str) – Path of the .blend file
  • namespace – (Default value = ‘’)
  • prefix – (Default value = False)

Returns:

phobos.utils.io.importResources(restuple, filepath=None)

Accepts an iterable of iterables describing resource objects to import. For instance, reslist=((‘joint’, ‘continuous’), (‘interface’, ‘default’, ‘bidirectional’)) would import the resource objects named ‘joint_continuous’ and ‘interface_default_bidirectional’.

Parameters:
  • restuple – iterable of iterables containing import objects
  • filepath – path to file from which to load resource (Default value = None)

Returns(tuple of bpy.types.Object): imported objects

Returns:

phobos.utils.io.l2str(items, start=0, end=-1)

Generates string from (part of) a list.

Parameters:
  • items (list) – List from which the string is derived (elements need to implement str())
  • start (int, optional) – Inclusive start index for iteration (Default value = 0)
  • end (int, optional) – Exclusive end index for iteration (Default value = -1)
Returns:

str - Generated string.

phobos.utils.io.securepath(path)

Checks whether directories of a path exist and generates them if necessary.

Parameters:path (str) – The path to be secured (directories only)
Returns:String – secured path as absolute path, None on error
phobos.utils.io.xmlline(ind, tag, names, values)

Generates an xml line with specified values. To use this function you need to know the indentation level you need for this line. Make sure the names and values list have the correct order.

Parameters:
  • ind (int >= 0) – Indentation level
  • tag (String) – xml element tag
  • names (list (same order as for values) – Names of xml element’s attributes
  • values (list (same order as for names) – Values of xml element’s attributes
Returns:

String – Generated xml line.

phobos.utils.naming module

Contains the utility functions to rename objects, add/remove namespaces etc.

phobos.utils.naming.addNamespace(obj, namespace=None)

Namespaces a given blender object.

Parameters:
  • obj (bpy.types.Object) – The object to namespace.
  • namespace – (Default value = None)

Returns:

phobos.utils.naming.addNamespaceToName(name, namespace)
Parameters:
  • name
  • namespace

Returns:

phobos.utils.naming.gatherNamespaces(separator='::')

Gathers all existing namespaces.

Parameters:separator – (Default value = ‘::’)

Returns:

phobos.utils.naming.getModelName(obj)

Returns the name of the model encoded by obj, provided that obj is a valid model root.

If obj does not contain a defined ‘model/name’, the object name is returned with a ‘*’ added ad the start, ensuring that the return value will not be treated as a valid model name.

Parameters:obj (bpy.types.Object) – root object of the model
Returns:str – modelname of the object or object name with ‘*’ prepended if undefined
phobos.utils.naming.getObjectName(obj, phobostype=None)

Returns the name of an object relevant to Phobos. An optional phobostype parameter can be provided for objects with multiple uses, such as link objects (which also contain joint and motor information). If no phobostype is provided, the phobostype of the object is used. The contents of the custom property phobostype/name are returned, if present, else the object name itself is returned, stripped of namespaces.

Parameters:
  • obj (bpy.types.Object) – object for which the name is requested
  • phobostype – phobostype if relevant (e.g. ‘motor’) (Default value = None)
Returns:

str – The object’s name

phobos.utils.naming.getUniqueName(newname, names)

Generates a new name similar to the Blender internal convention.

This ensures, that the Blender internal limit to object name lengths (63 characters) is matched without omitting the number. That way, unwanted naming behaviour is avoided.

Parameters:
  • newname – desired object name
  • names – list of existing names (e.g. bpy.data.objects)
Returns:

str – new name that is unique in the Blender namespace

phobos.utils.naming.isValidModelname(name)

Returns if a name contains characters other than alphanumeric, ‘_’ and ‘-‘

Parameters:name

Returns:

phobos.utils.naming.removeNamespace(obj)

Removes the namespace from an object if present.

Parameters:obj (bpy.types.Object) – The object to remove the namespace from.

Returns:

phobos.utils.naming.replaceNameElement(prop, old, new)

For all selected elements in Blender, replace an old part of a string prop*erty with *new.

Parameters:
  • prop
  • old
  • new

Returns:

phobos.utils.naming.safelyName(obj, name, phobostype=None)
Assigns a name to an object in a safe way with regard to the internal

name handling in Blender.

If no phobostype is provided or the phobostype is the same as the object itself, the actual object is renamed, generating a name that no other object in Blender has, using Blender’s own naming scheme. This prevents Blender to assign the name and change another object’s name that previously held that name.

If the name provided cannot be assigned to the object, it is stored in a custom variable phobostype/name. Note that other */name variables in the object are not updated.

Parameters:
  • obj (bpy.types.Object) – object to rename
  • name (str) – new name for the object
  • phobostype (str, optional) – only rename if the specified phobostype is matched (Default value =

None)

Returns:new name of the Blender object
Return type:str
phobos.utils.naming.stripNamespaceFromName(name)
Parameters:name

Returns:

phobos.utils.naming.toggleNamespace(obj, namespace='')
Parameters:
  • obj
  • namespace – (Default value = ‘’)

Returns:

phobos.utils.selection module

Contains the utility functions for selecting objects in Blender based on different criteria.

phobos.utils.selection.getChildren(root, phobostypes=(), selected_only=False, include_hidden=True)

Finds all (selected or unselected / hidden or unhidden) children of a given root object and phobostypes. If phobostypes is not provided, it is ignored.

Parameters:
  • root (bpy.types.Object) – object to start search from.
  • phobostypes (list of strings, optional) – phobostypes to limit search to. (Default value = ()
  • selected_only (bool., optional) – True to find only selected children, else False. (Default value = False)
  • include_hidden (bool., optional) – True to include hidden objects, else False. (Default value = True)
Returns:

Blender objects which are children of root.

Return type:

list

phobos.utils.selection.getEffectiveParent(obj, ignore_selection=False, include_hidden=False, objectlist=[])

Returns the parent of an object, i.e. the first link ascending the object tree that is selected, starting from the obj, optionally also excluding hidden objects.

Parameters:
  • obj (bpy.types.Object) – object of which to find the parent.
  • include_hidden (bool, optional) – True to include hidden objects, else False. (Default value = False)
  • ignore_selection (bool, optional) – whether or not to use the current selection as limitation (Default value = False)
  • objectlist – list of bpy.types.Object to which possible parents are restricted (Default value = [])

Returns:

phobos.utils.selection.getImmediateChildren(obj, phobostypes=(), selected_only=False, include_hidden=False)

Returns all immediate children for a given object and phobostypes (if provided). Search can be limited to selected objects and non-hidden objects.

Parameters:
  • obj (bpy.types.Object) – object to start search from.
  • phobostypes (list of strings, optional) – phobostypes to limit search to. (Default value = ()
  • selected_only (bool., optional) – True to find only selected children, else False. (Default value = False)
  • include_hidden (bool., optional) – True to include hidden objects, else False. (Default value = False)
Returns:

list - Blender objects which are immediate children of obj.

phobos.utils.selection.getLeaves(roots, objects=[])

Returns the links representating the leaves of the spanning tree starting with an object inside the model spanning tree.

Parameters:
  • root (list of bpy.types.Object) – Root objects from where to start the search from
  • objects (list, optional) – List of objects to which the search is restricted. (Default value = [])
  • roots
Returns:

List of the leaves of the kinematic spanning tree.

Return type:

list

phobos.utils.selection.getObjectByName(name, phobostypes=())

Returns list of objects that either have a specific name or contain a custom name property with that name.

As the function returns either an empty list, a unique object or a list of objects, it is possible to test for uniqueness of the result by calling isinstance(result, list).

Parameters:
  • name (str) – The exact object name to find.
  • phobostypes – (Default value = ())
Returns:

bpy.types.Object or list - one or list of objects matching name

phobos.utils.selection.getObjectByNameAndType(name, phobostype)

Find an object with a specified phobostype and having the property “phobostype/’name’ == name”.

Parameters:
  • name (str) – The name to search for.
  • phobostype (str) – The phobostype to search for.
Returns:

bpy.types.Object - the matching object.

phobos.utils.selection.getObjectByProperty(property, value)

Returns the first object found in the .blend file data with matching property and value

Parameters:
  • property
  • value

Returns:

phobos.utils.selection.getObjectsByPattern(pattern, match_case=False)

Return a list of objects in the scene that match a name pattern. The pattern may match either the object’s actual name or the value of the ‘phobostype/name’ property.

Parameters:
  • pattern – str
  • match_case – bool (Default value = False)
Returns:

list - all matching objects.

phobos.utils.selection.getObjectsByPhobostypes(phobostypes)

Returns list of all objects in the current scene matching phobostype

Parameters:phobostypes (list) – the phobostypes to match objects with.
Returns:list - Blender objects.
phobos.utils.selection.getRecursiveChildren(obj, recursion_depth=0, phobostypes=(), selected_only=False, include_hidden=False)

Returns all children for a given object and phobostypes (if provided) within the given recursion depth. Search can be limited to selected objects and non-hidden objects.

Parameters:
  • obj (bpy.types.Object) – object to start search from.
  • recursion_depth (int, optional) – Depth of the recursion, default is all levels (Default value = 0)
  • phobostypes (list of strings, optional) – phobostypes to limit search to. (Default value = ()
  • selected_only (bool., optional) – True to find only selected children, else False. (Default value = False)
  • include_hidden (bool., optional) – True to include hidden objects, else False. (Default value = False)
Returns:

Blender objects which are children of obj within recursion depth.

Return type:

list

phobos.utils.selection.getRoot(obj=None)

Returns the root object of a model the Blender object obj or, if obj is not provided, the active object is part of, traversing up the tree. If no such object is found, returns None.

Parameters:obj (bpy.types.Object, optional) – The object to find the root for. (Default value = None)
Returns:bpy.types.Object - The root object.
phobos.utils.selection.getRoots(scene=None)

Returns a list of all of the current/specified scene’s root objects.

Parameters:scene (bpy.types.Scene, optional) – the scene of which to find the root objects (Default value = None)
Returns:list(bpy.types.Object) – root objects of the scene
phobos.utils.selection.getRootsOfSelection()

TODO Missing documentation

phobos.utils.selection.getSubmechanismRootForJoint(jointobj)
Parameters:jointobj

Returns:

phobos.utils.selection.getSubmechanismRoots(selection_only=False)
Parameters:selection_only – (Default value = False)

Returns:

phobos.utils.selection.isEntity(obj)

Returns whether or not the opject passed is an Phobos entity.

Parameters:obj (bpy.types.Object) – The object for which entity status is tested.

Returns:

phobos.utils.selection.isRoot(obj, scene=None)

Returns whether or not the object passed to obj is a Phobos model root.

Parameters:
  • obj (bpy.types.Object) – The object for which model root status is tested.
  • scene – (Default value = None)

Returns:

phobos.utils.selection.selectByName(name, match_case=False, exact=False)

Uses getObjectsByPattern to select the found objects.

Parameters:
  • name (str) – The name (pattern) to search for.
  • match_case (bool, optional) – Indicate whether to match the object names’ case to the pattern. (Default value = False)
  • exact (bool, optional) – whether to search for exact string or not (Default value = False)
Returns:

None.

phobos.utils.selection.selectObjects(objects, clear=True, active=-1)

Selects all objects provided in list, clears current selection if clear is True and sets one of the objects the active objects if a valid index is provided.

Parameters:
  • objects (iterable of bpy.types.Object) – the objects to be selected.
  • clear (bool, optional) – clear current selection? (Default value = True)
  • active (int, optional) – index of the object to set active. (Default value = -1)
Returns:

None.

phobos.utils.validation module

class phobos.utils.validation.ValidateMessage(message, level, obj=None, operator=None, information=None)

Bases: object

Resembles a message from a validation describing an issue in the model/object etc.

log()

TODO Missing documentation

phobos.utils.validation.add_message(messages, key, message)

This function adds a message to the messages dictionary.

Parameters:
  • messages (dict) – The dictionary containing the messages.
  • key (str) – The messages corresponding key (node name).
  • message (str) – The message to append to a specific key.
Returns:

None.

phobos.utils.validation.check_dict(dic, validator, messages)

This function validates a given dictionary against a validation. It writes all messages to the given messages list

Parameters:
  • dic (dict) – The dictionary you want to validate.
  • validator (dict) – The validation you want to validate against.
  • messages (dict) – The message list you want to append the error messages to.

Returns:

phobos.utils.validation.check_dict_alg(dic, validator, entry_list, messages, whole_validator, current_elem)

This function does the real validation work by working through the validation.

Parameters:
  • dic (dict) – The dictionary you want to validate.
  • validator (dict) – The validation you want to validate against.
  • entry_list(list – list): This list contains all keys you have to traverse to get the correct value in the dictionary.
  • messages (dict) – The message list you want to append the error messages to.
  • whole_validator (dict) – This is a copy of the whole validation needed when referencing to a top level key.
  • current_elem (str) – The current element the alg is checking.
  • entry_list

Returns:

phobos.utils.validation.check_leaf(leaf_value, dic, entry_list, messages, current_elem)

This function checks the dictionary against a specific validation leaf and entry_list. Writing the messages into the given list.

Parameters:
  • leaf_value (dict) – The leaf value used for validation.
  • dic (dict) – The dictionary you want to validate.
  • entry_list(list – list): The keys navigating you to the dictionary value to validate against the validation leaf.
  • messages (dict) – The list you want to append the messages to.
  • current_elem
  • entry_list

Returns:

phobos.utils.validation.generateCheckMessages(param1, param2)
Parameters:
  • param1
  • param2

Returns:

phobos.utils.validation.handle_operator(node, dic, validator, entry_list, messages, whole_validator, current_elem)

This function handles an operator and decides how to continue the validation process.

Parameters:
  • node (str) – The operator to handle.
  • dic (dict) – The dict you want to validate.
  • validator (dict) – The validation you want to validate the dic with.
  • entry_list(list – list): The list of keys to navigate to the value in the dictionary.
  • messages (dict) – The list to append the messages to.
  • whole_validator (dict) – The whole validation to reach top level keys in case of a reference operator.
  • current_elem
  • entry_list

Returns:

phobos.utils.validation.is_leaf(node_value)

This function checks whether a validation node is a leaf or not.

Parameters:node_value (dict) – The value of the node you want to check.
Returns:bool.
phobos.utils.validation.is_operator(node)

This function checks whether a validation node is an operator or not.

Parameters:node (str) – The node key you want to check.
Returns:bool.
phobos.utils.validation.traverse_dict(dic, entry_list)

This function traverses a dictionary with a given list of keys and returns the value or None if the keys are not found.

Parameters:
  • dic (dict) – The dictionary to traverse.
  • entry_list(list – list): The list of keys you want to traverse with.
  • entry_list
Returns:

dict.

phobos.utils.validation.validate(name)
Parameters:name

Returns:

phobos.utils.validation.validateGeometryType(obj, *args, adjust=False, geometry_dict=None)
Parameters:
  • obj
  • *args
  • adjust – (Default value = False)
  • geometry_dict – (Default value = None)

Returns:

phobos.utils.validation.validateInertiaData(obj, *args, adjust=False)

Validates an inertia dictionary or object.

This checks for the inertia and mass values in the dictionary (inertial/inertia and inertial/mass for an object respectively).

Also, the inertia values are checked to be positive definite (for diagonal, determinant and eigenvalues).

If adjust is set, values are adjusted/fixed for the returned dict/object. E.g. this sets a negative mass to 1e-3.

Parameters:
  • obj (dict/bpy.types.Object) – inertia dictionary or object to validate
  • *args – other arguments
  • adjust – if True, bad values will be fixed/complemented (Default value = False)
Returns:

list of ValidateMessages and the fixed dictionary/object

Return type:

tuple

phobos.utils.validation.validateJoint(link, adjust=False)

Checks for errors in the joint definitions of the specified link.

If autocomplete is set, the missing dictionary entries are complemented.
Parameters:
  • link (bpy.types.Object) – link object which forms the joint
  • autocomplete (bool) – add missing keys to the link object
  • adjust – (Default value = False)
Returns:

list(ValidateMessage) – error messages of the validation

phobos.utils.validation.validateJointType(link, adjust=False)

Validate the joint type of the specified link.

If adjust is True, the validation errors are fixed on the fly.

Parameters:
  • link (bpy.types.Object) – link representing the joint to validate
  • adjust (bool, optional) – if True, the validation errors are fixed on the fly. (Default value = False)
Returns:

list(ValidateMessage) – validation errors

Parameters:
  • link
  • objectlist – (Default value = None)

Returns:

phobos.utils.validation.validateMaterial(material, adjust=False)

Validate the specified material.

Parameters:
  • material (bpy.types.Material) – material to validate
  • adjust – (Default value = False)
Returns:

list(ValidateMessage) – validation errors for the material

phobos.utils.validation.validateObjectNames(obj)

Check for naming errors of the specified object.

This checks:
  • the phobostype/names
Parameters:obj (bpy.types.Object) – object to be checked
Returns::class:ValidateMessage list
Return type:list
phobos.utils.validation.validateObjectPose(obj, adjust=False, **kwargs)
Parameters:
  • obj
  • adjust – (Default value = False)
  • **kwargs

Returns:

phobos.utils.validation.validateVisual(obj, *args, adjust=False, geometry_dict=None)
Parameters:
  • obj
  • *args
  • adjust – (Default value = False)
  • geometry_dict – (Default value = None)

Returns:

Module contents