One solution would be a combination of using
scriptJobs<http://download.autodesk.com/global/docs/maya2012/en_us/CommandsPython/scriptJob.html>and
scriptNodes<http://download.autodesk.com/global/docs/maya2012/en_us/CommandsPython/scriptNode.html>

The scriptJob would be set on each curve to fire when your custom attribute
changes. It stays attached to the curve until the geometry is deleted. The
problem is that its not saved with the scene, which is why you need a
scriptNode. You can create the scriptNode, which is saved like any other
node in your scene, and executes arbitrary code when the scene initializes.
You can use it to set up the scriptJob.

Here is a first example showing a one-off application to a single object:

node = 'curve1'
attrib = 'curve1.filepath'
scriptJob = "cmds.scriptJob(attributeChange=(\"%s\", 'print \"Attrib
changed: %s\"'), kws=True)" % (attrib,attrib)
nodeName = cmds.scriptNode(st=2, bs=scriptJob, n='%s_script' % node,
stp='python')

This would require one scriptNode per object. Each scriptNode has the
scriptJob code, that will be executed when you load the scene, setting the
scriptJob on the curve attribute.

What you might want is something a little more robust, like a single
scriptNode that executes code that will find all your special curves and
apply the scriptJobs to them. You would have somethign like this in a
module, like: curveScript.py

def findCurves():
    shapes = cmds.ls(type='nurbsCurve')
    trans = cmds.listRelatives(shapes, parent=True)
    curves = [n for n in trans if cmds.attributeQuery('filepath',
exists=True, node=n)]
    return curves

def setupCurves():
    for node in findCurves():
        attrib = '%s.filepath' % node
        cmd = 'print "Attrib changed: %s"' % attrib
        cmds.scriptJob(attributeChange=(attrib, cmd), kws=True)

And then, when you want to create the scriptNode for your given scene, you
would do:

nodeName = cmds.scriptNode(st=2, bs='import curveScript;
curveScript.setupCurves()',
                            n='curvePath_script', stp='python')

Now every curve found will have its attribute attached to a scriptJob.
Maybe other people have a completely different solution.


On Mon, Jul 2, 2012 at 12:58 AM, Panupat Chongstitwattana <
[email protected]> wrote:

> Hi. I'm not sure how to explain my question, please forgive me if it
> doesn't make any sense.
>
> For example, I have a curve and I added a string attribute. Meant for a
> path directory.
> Once I enter the value into this attribute, I want python to check files
> in that directory and do stuff.
>
> I can do this by running separate script. But is it possible to have this
> all embed into the curve itself? So when I pass it to others, all they have
> to do is copy/paste the path they desire without having to run other extra
> script.
>
> Thanks.
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
> http://groups.google.com/group/python_inside_maya/subscribe
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to