Python script for connecting an emitter to a curve

Connect an emtiter to a curve

Select an emitter and a curve and run this script:


       
       
## PYTHON            
def attachEmitterToCurve():

    emitter = maya.cmds.ls(sl=True, type="pointEmitter")
    if len(emitter) != 1:
        print("You must select one emitter and one nurbs curve")
        return False
    nodes = maya.cmds.ls(sl=True, type = "transform")
    nurbsCurves = {}
    
    for x in nodes:
        kids = maya.cmds.listRelatives(x, s=True, type="nurbsCurve") or []
        if len(kids) == 0:
            continue
        nurbsCurves[x] = kids
        
    if len(nurbsCurves) != 1:
        print("You must select one emitter and one nurbs curve")
        return False
        
    geoCon = maya.cmds.createNode("geoConnector")
    
    for x in nurbsCurves:
        try:
            maya.cmds.parent(emitter[0], x)
        except:
            try:
                maya.cmds.parentConstraint(x, emitter[0], mo=False)
            except:
                print("Can't parent or constrain")

        maya.cmds.connectAttr("%s.local" % nurbsCurves[x][0], "%s.localGeometry" % geoCon)
        maya.cmds.connectAttr("%s.message" % nurbsCurves[x][0], "%s.owner" % geoCon)
        maya.cmds.connectAttr("%s.worldMatrix[0]" % nurbsCurves[x][0], "%s.worldMatrix" % geoCon)
        
    maya.cmds.connectAttr("%s.ownerCentroid" % geoCon, "%s.ownerCentroid" % emitter[0])
    maya.cmds.connectAttr("%s.ownerCentroidLocal" % geoCon, "%s.translate" % emitter[0])
    maya.cmds.connectAttr("%s.ownerPositions" % geoCon, "%s.ownerPosData" % emitter[0])
    maya.cmds.connectAttr("%s.ownerVelocities" % geoCon, "%s.ownerVelData" % emitter[0])

    return True

attachEmitterToCurve()
                
       
 

Comments

Popular Posts