Modifier

class guerilla.Modifier

Bases: object

Modification context

In order to keep a coherent undo/redo stack during all user interactions, some operations cannot be directly performed, but rather through a wrapper, the modification context.

Use it as a context manager (using the ‘with’ keyword) or retrieve the current modification context using static method ‘get’

Examples:

>>> from guerilla import Modifier, pynode
>>> with Modifier() as mod: 
...     mod.createnode('foo') 
<guerilla.SceneGraphNode object at ...>
>>> foo_node = pynode('foo')
>>> # retrieve current modification context
>>> m = Modifier.get()
adddependency(input, output)

Add dependency of an output plug on an input plug

Parameters:
  • input (Plug) – input plug
  • output (Plug) – output plug
connect(input, output)

Connect a plug to another

Parameters:
  • input (Plug) – input plug
  • output (Plug) – output plug
Raise:

RuntimeError if adddependency must be used (non typed plug)

createnode(name, type='SceneGraphNode', parent=None)

Create a node

Parameters:
Returns:

created node

Return type:

Node

Raise:

ValueError if type is unknown or a Reference or Document

createplug(node, name, plugType='Plug', dataType='string', flags=0, value=None)

Create a plug

Parameters:
  • node (Node) – create plug for node
  • name (str) – name of plug
  • plugType (str) – Plug by default
  • dataType (str) – type of value for new plug
  • flags (Plug.flags (int)) – Plug flag, ex: Plug.Dynamic, 0 (default)
Returns:

plug instance

Return type:

DynAttrPlug or Plug

Raise:

AttributeError raise an exception if plug already exists

Available types (dataType):

  • int, float, bool, angle,
  • string
  • color,
  • enum, filename, directory

See also

types for all available types

>>> import guerilla
>>> n = Node.create('foo'); n.createplug('bar', dataType='angle') 
<guerilla.Plug object at ...>
>>> n = Node.create('foo'); p = n.createplug('bar', dataType='color')
>>> p.set([0,255,255]); print p.get()
[0L, 255L, 255L]
>>> n = Node.create('foo') 
>>> p = n.createplug('bar', dataType=guerilla.types('enum', desc=['a', 'b']))
>>> p.set('a'); print p.get()
a
createref(name, filename, parent=None, options=None, nohostrefs=None)

Create a reference

Parameters:
  • name (str) – ref name
  • filename (str) – ref path
  • parent (Node) – parent node (default: current Document)
  • options (dict) – options to create the reference (default: None)
Returns:

reference node (ArchReference) and parent nodes (tuple of SceneGraphNode)

Return type:

tuple

>>> from guerilla import Modifier
>>> with Modifier() as mod:
...     n = mod.createnode('geom')
...     # assume objPath1 is the path of an OBJ
...     refNode, topNodes = mod.createref('foo', objPath1, n, {'prefixnodes':False,'containschildren':True})

The possible options to create the reference are:

prefixnodes: the referenced nodes are prefixed with the reference name when True

containschildren: the referenced nodes are loaded as children of the Reference, instead of loading in the Document when True

roots: the list of paths to be moved as root in the reference, with all other nodes discarded

deletenode(node)

Delete a node

Parameters:node (Node) – node to delete
Returns:True on success else False
Return type:bool
deleteplug(plug)

Delete a plug

Parameters:plug (Plug) – plug object to delete
deleteref(ref)

Delete a reference

Parameters:ref (ArchReference) – reference node
>>> from guerilla import Modifier
>>> with Modifier() as mod:
...     n = mod.createnode('geom')
...     # assume objPath1 is the path of an OBJ (or an alembic) file
...     refNode, topNodes = mod.createref('foo', objPath1, n) 
...     mod.deleteref(refNode)
>>> len(list(n.children()))
0
disconnect(input, output)

Disconnect a plug from another plug

Parameters:
  • input (Plug) – input plug to be disconnected
  • output (Plug) – output plug to be disconnected
static get()

Retrieve current modification context

Even if there is no current modification, get will return a valid context.

Returns:current modification context
Return type:Modifier
movenode(node, parent)

Move node under parent

Parameters:
  • node (Node) – node to move
  • parent (Node) – new parent node
Returns:

True on success else False

Return type:

bool

removealldependencies(input)

Remove all dependencies off an input plug

Parameters:input (Plug) – input plug
removedependency(input, output=None)

Removes dependency of an output plug off an input plug or all dependencies if output is None

Parameters:
  • input (Plug) – input plug
  • output (Plug) – output plug. If None, remove all dependencies
renamenode(node, name)

Rename a Node

Parameters:
  • node (Node) – node to rename
  • name (str) – node new name
select(selection, mode='add')

Select nodes

Parameters:
  • nodes (list of Node) – nodes to select
  • mode ((str)) – selection mode: replace, remove, add (default)
setplug(plug, value)

Set a plug value

Parameters:
  • plug (Plug) – plug object
  • value – new plug value
touch(input)

Invalidate a plug value (ie. force re-evaluation)

Parameters:input (Plug) – plug to invalidate