Hey thanks Ian!!! works like a charm. two critical things i was bogged down on:
1. in other frameworks I've worked in, (which has cased a bad habit), when you attach a function set to a new object, you use the object representation to access the function-set. i was trying to do that here and wondering why maya python api would not associate the function-set with my new curve object. apparently the opposite is true here, instead of using the new object to access the fnc-set, the fnc-set itself is used to operate on the new object. 2. maya api docs say that MTimeArray() and MDoubleArray() args to addKeys need to be c++ style pointers, not python references. so i was totally consumed with trying to feed the addKeys function pointers to these objects using MScriptUtil.. which was very frustrating indeed. apparently this is a case where the docs are wrong and these do not need to be c++ style pointers. yay! Ian, you made me a happy man today! just what i was looking for On Feb 17, 10:34 pm, Ian Jones <[email protected]> wrote: > This is the code I'm using (2011x64.hotfix3-win7) > > import maya.OpenMaya as om > import maya.OpenMayaAnim as oma > > #variables outside the scope of this but should be straight forward > plug = MPlug_from_elsewhere > values = list_of_values_from_elsewhere > > #initialize function set > anim_curve_function_set = oma.MFnAnimCurve() > > #detect the type of curve to create from the plug > type = anim_curve_function_set.timedAnimCurveTypeForPlug(plug) > > #create the curve > mnew_curve = anim_curve_function_set.create(type) > > #build the values for addKeys > time_array = om.MTimeArray() > values_array = om.MDoubleArray() > > for index,value in enumerate(values): > time_array.append(om.MTime(index,om.MTime.uiUnit())) > values_array.append(value) > > anim_curve_function_set.addKeys(time_array,values_array,oma.MFnAnimCurve.kTangentLinear,oma.MFnAnimCurve.kTangentLinear > ) > > Hope that helps. > > Ian > > On Thu, Feb 17, 2011 at 12:02 PM, mtherrell <[email protected]> wrote: > > so, i think the root of the problem is that: > > > the docs say that upon using the 'create' function of the MFnAnimCurve > > function set, > > that the function set becomes attached to the newly created curve so > > that you could: > > > crv.addKeys(...) > > > but i cannot get the function set attached to the python > > representation of MObject 'crv' > > even using: > > > openMayaAnim.MFnAnimCurve.setObject(crv) > > > so when i finally do go to try to add the keyframes to the curve node, > > i can't use the 'crv' MObject itself to do the operation. > > > anyone know how to make sure that the curve MObject generated with the > > 'create' function of MFnAnimCurve > > attaches the MFnAnimCurve function set?, so that one can manipulate > > the curve using MFnAnimCurve after curve creation? > > > -thanks > > -mt > > > On Feb 15, 5:01 pm, mtherrell <[email protected]> wrote: > >> Hoping i am just doing somthing wrong, > >> but: > > >> import maya.OpenMayaAnim as omAn > > >> ## instance the MFnAnimCurve() function set > >> crvFnc = omAn.MFnAnimCurve() > > >> ## make a curve > >> crv = crvFnc.create(mplug,crvtype) > > >> ## ok it has all worked so far......... > >> ## but then: > > >> ## (om.MTime().kFilm.... no variation makes a difference .. even just > >> leaving the mtime type out of it) > >> time = om.MTime(1 , om.MTime.kFilm) > > >> crv.addKey(time , 2.5 , MFnAnimCurve.kTangentStep , > >> MFnAnimCurve.kTangentStep) > > >> ### errors: > >> # Error: addKey > >> # Traceback (most recent call last): > >> # File "<maya console>", line 4, in <module> > >> # File "C:\Users\mtherrell\Documents\maya\milldev\millToolMaya.py", > >> line 91, in createAnimCurveOnLayer > >> # > >> crv.addKey(time,tvp[1],MFnAnimCurve.kTangentStep > >> ,MFnAnimCurve.kTangentStep) > >> # File "D:\buildforge\Maya_2011_Win64_Build\build\wrk\optim\runTime > >> \Python\Lib\site-packages\maya\OpenMaya.py", line 1466, in <lambda> > >> # File "D:\buildforge\Maya_2011_Win64_Build\build\wrk\optim\runTime > >> \Python\Lib\site-packages\maya\OpenMaya.py", line 34, in _swig_getattr > >> # AttributeError: addKey # > > >> the same "_swig_getattr", "AttributeError" for any of the addKey(s) or > >> addKeyframe functions of MFnAnimcurve in the python API. > >> It seems like this mysterious location of OpenMaya.py (which does not > >> actually exist on my computer) is some internal way of refering to the > >> Python/Lib/site-Packages/OpenMaya.pyc file which is the only file > >> close to that name that does exist, and must be where maya is getting > >> it python api functionality from. (i guess we are not allowed by > >> Autodesk to see the original OpenMaya.py to figure out whats wrong.) > > >> This is the error, however, that one gets when one refers to a > >> function or attribute of a function that does not exist. as though > >> within the MfnAnimCurve function set for python, they forgot to add > >> the 'addKey' and 'addKeyFrame(s)' functions. > >> But the functions are members.. see below > > >> i do not want to use mel setKeyFrame or keyframe. too slow. takes many > >> seconds to build keyframes for all the attrs i entend to animate. > >> this works fine in the normal c++ API, but i want to have this > >> functionality in a python script (for well known and well discussed > >> reasons.) > >> .. this should be possible. > > >> i want to use the python API to create an AnimCurve node with all its > >> keys and values in one fell swoop in order to make what i am doing > >> fast and in python, and in a script. > > >> any ideas where this is going wrong? > > >> to see what member functions exist: > >> one can list all the member functions of a class in python. > >> i did this to the MFnAnimCurve function set. > >> in the python script editor i did this: > > >> import maya.OpenMayaAnim > >> import inspect > > >> crvFnc = OpenMayaAnim.MFnAnimCurve() > >> funclist = inspect.getmembers(crvFnc) > > >> for func in funclist: > >> print func > > >> <<<< > > >> they deffinately did not forget to add the methods related to > >> addKey(s): > >> because they are there in the list of functions including all > >> inhereted. > > >> so either they are not working properly, i am not sending arguments to > >> them in the right way, or they are not intended by maya to work in > >> python yet they are not documented as "No Script Support" in the > >> current API docs for 2011. > > > -- > >http://groups.google.com/group/python_inside_maya > > -- http://groups.google.com/group/python_inside_maya
