ModifierΒΆ

The Modifier package provides the base frame work for Document modification

To perform Document modification, one must use a modification context, also called a Document Modifier. This package provides the base API to create, delete and modify nodes and plugs in the Document and keep track of undoable actions at the same time.

To start a new modification context, use the Document:modify () method:

-- Start a document modification
local mod = Document:modify ()
-- Create a child in the Document
local node = mod.createnode (Document, "Node""MyNode")
-- Create a plug in the child node
local plug = mod.createplug ("Plug", node, "MyPlug", Plug.Dynamic, types.string, "Default")
-- Finish the modification and stack all actions in the undo/redo stack
mod.finish ()

Additionnally, it is possible to query the Document for the current modification context. This is useful if you have nested function calls that perform modifications.

local function createnode (parent)
-- Get the current modification context
local mod = Document:getmodifier ()
return mod.createnode (parent, "Node""MyNode")
end

-- Start a document modification
local mod = Document:modify ()
-- Create a child in the Document
local node = createnode (Document)
-- Create a child in the child
local child = createnode (node)
mod.finish ()

Note that when querying the current modification context, some actions are not permitted, such as select, createref and deleteref.

Functions:

nil Modifier.adddependency ( Plug input , Plug output ) Adds dependency of an output plug on an input plug
nil Modifier.connect ( Plug input , Plug output ) Connects a output plug to an input plug
Node node Modifier.createnode ( Node parent , string classname , string name ) Create a node in another node
Plug plug Modifier.createplug ( string plugclass , Node node , string name , number flags , type type , value value ) Creates a plug in a modification context
Reference,{Node} reference,nodes Modifier.createref ( string name , string filename , [ Node parent ] , [ table options ] , [ boolean nohostrefs ] ) Creates a reference
boolean success Modifier.deletenode ( Node node ) Deletes a node from its parent
boolean success Modifier.deleteplug ( Plug plug ) Deletes a plug from a node
nil Modifier.deleteref ( Reference reference ) Deletes a reference
nil Modifier.disconnect ( Plug input , Plug output ) Disconnects a plug from another
nil Modifier.movenode ( Node node , Node parent ) Moves a node from a parent to another
nil Modifier.removealldependencies ( Plug input ) Removes dependency of all plugs on this plug
nil Modifier.removedependency ( Plug input , Plug output ) Removes dependency of an output plug off an input plug
nil Modifier.renamenode ( Name node , string name ) Renames a node
nil Modifier.select ( table selection , [ string mode ] ) Changes the current document selection
nil Modifier.set ( Plug plug , value value ) Sets a plug value
nil Modifier.setclass ( Node node , string classname ) Changes the class of a node
nil Modifier.settype ( Plug plug , type type ) Sets a plug type
nil Modifier.touch ( Plug input ) Invalidates a plug