0

hello I want to convert this Mel script into a python script so I can build on top of it.

global proc motionTrailToCurve()
{

    $selected=`ls -dag -et snapshotShape`;
    for ($obj in $selected) {
    $pts=(getAttr($obj+".pts"));
    $size=size($pts);
    $curve=`curve -d 1 -p $pts[0] $pts[1] $pts[2] -p $pts[4] $pts[5] $pts[6] -k 0 -k 1`;
    for($i=8;$i<$size;$i+=4)
    curve -os -a -p $pts[$i] $pts[$i+1] $pts[$i+2] $curve ;
    }
}

motionTrailToCurve;

when I run py to mel I get this

import pymel.core as pm

def motionTrailToCurve():
    
    selected=pm.ls(et='snapshotShape', dag=1)
    for obj in selected:
        pts=(pm.getAttr(str(obj) + ".pts"))
        size=len(pts)
        curve=pm.curve(p=[(pts[0], pts[1], pts[2]), (pts[4], pts[5], pts[6])], k=[0, 1], d=1)
        for i in range(8,size,4):
            pm.curve(curve, a=1, p=(pts[i], pts[i + 1], pts[i + 2]), os=1)

motionTrailToCurve()

when I run it I get this error:

Invalid arguments for flag 'p'.  Expected ( distance, distance, distance ), got ( ( Point, Point, Point ), ( Point, Point, Point ) ) # 

can someone point me towards the right direction on how to get this script to work in python, I'm new to all this and is just playing around trying to automate some of my workflow

NinjaBX
  • 11
  • 2
  • Silly question but where in Maya can I create a `snapshotShape`? Trying to replicate the issue but don't know how to make the object. – Green Cell Jul 03 '20 at 03:31
  • if you want to create this step by step manually i wouldn't know how, as i've always used this script. but if you want to use the script and have the snapshotshape function working then you just need to create a object move it, set a few keys then create a motion path then run the scipt – NinjaBX Jul 03 '20 at 04:17
  • I have found a work around answer for what i want to do with this, by just calling the script in python ```mel.eval("source myMELScript;") mel.eval("myMELScript;")``` but im still interested to see if this script can be done with pymel – NinjaBX Jul 03 '20 at 04:26
  • A motion path? As in Constrain>Motion Paths>Attach to a motion path, or Visualize>Create editable motion trail? Either way neither of those create a `snapshotShape` type object, which is what the very beginning of your script is looking for. – Green Cell Jul 03 '20 at 07:05

1 Answers1

0

for those that might be interest, this was the fix to get it working


def motionTrailToCurve():
    
    selected=pm.ls(et='snapshotShape', dag=1)
    for obj in selected:
        pts=(pm.getAttr(str(obj) + ".pts"))
        size=len(pts)
        curve=pm.modeling.curve(p=[pts[0], pts[1]], k=[0, 1], d=1)
        for i in range(8,size,4):
            pm.curve(curve, a=1, p=(pts[i], pts[i + 1], pts[i + 2]), os=1)

motionTrailToCurve()
NinjaBX
  • 11
  • 2