Instead of using a ScriptJob to to update on user input, use EventCallbacks instead:
def test(*args, **kwargs):
print "Fooo"
import maya.OpenMaya as OpenMaya
idx = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", test)
#when ever you finish doing your stuff
OpenMaya.MMessage.removeCallback(idx)
A plug is a point on a dependency node where a particular attribute can be connected. In simple cases the plug and attribute are equivalent. When you have array attributes, however, the plug is more specific in that it indicates which of the array elements is to be connected.
There are two main types of plugs: networked plugs and non-networked plugs. Non-networked plugs can be considered user plugs as they are created by users and belong to users. Networked plugs can be considered dependency node plugs as they are part of the dependency graph and can only be referenced by users.
In every dependency node there is a network or "tree" of plugs indicating connections that have been made to attributes of the node. The plugs in this tree are known as networked plugs as they belong to the dependency node's network.
Using MFnDependencyNode.findPlug will fail with an exception if the plug doesn't exist.
plug = om.MPlug()
try:
plug = fn_dependency.findPlug(plug_name, False)
except:
add_plug_to_node(node, plug_name)
plug = fn_dependency.findPlug(plug_name, False)
Convert ['string1','string2', ...]
to {"string1", "string2", ...}
def convert_strings_to_mel_array(py_strs):
return str([str(x) for x in py_strs]).replace("'","\"").replace("[","{").replace("]", "}")