Need help with editor script to copy animation data into individual curves

I'm trying to code an editor script to take an animation I build in the Animation Editor, and copy its individual curves into the AnimationCurve public variables of a script attached to a GameObject. (I'm doing this as I want access to the curve data itself, but it's easier to build the animations in the editor.) I'm new to editor scripts. I've had a look at this answer, to get me started. So far I've modified it to the following:

using UnityEditor;
using UnityEngine;
using System.Collections;

public class CopyCurves
const string duplicatePostfix = "_copy";

[MenuItem("Assets/Copy Animations To Curves")]
static void CopyCurvesToIndividualCurves()
    // Get selected AnimationClip
    AnimationClip imported = Selection.activeObject as AnimationClip;
    if (imported == null)
        Debug.Log("Selected object is not an AnimationClip");

    // Copy curves from imported to copy
    AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
    for (int i = 0; i < curveDatas.Length; i++)
        if (curveDatas<em>.path=="Joint_0" && curveDatas*.propertyName=="m_LocalRotation.x") {*</em>
 <em>_AnimationCurve anim = curveDatas*.curve;*_</em>
 <em>_*System.Object army = GameObject.Find("/Arm").GetComponent<ArmCurves>();*_</em>
 <em>_*Keyframe[] keyz = anim.keys;*_</em>
 <em>_*foreach (Keyframe key in keyz) {*_</em>
 <em>_*army.joint0x.AddKey(key); // THIS IS THE PROBLEM LINE*_</em>
 <em>_*Debug.Log("Copying curves is done");*_</em>
<em>_*<p>The GameObject's script ("ArmCurves") is simply this:</p>*_</em>
<em>_*using UnityEngine;*_</em>
<em>_*using System.Collections;*_</em>
<em>_*public class ArmCurves : MonoBehaviour {*_</em>
 <em>_*public AnimationCurve joint0x;*_</em>
<em>_*<p>I get the following error on comilation:*_</em>
<em>_*<strong><em>Assets/Editor/CopyCurves.cs(36,38): error CS1061: Type `object' does not contain a definition for`joint0x' and no extension method `joint0x' of type`object' could be found (are you missing a using directive or an assembly reference?)</em></strong></p>*_</em>
<em>_*<p>Firstly, can an editor script access variables belonging to a script attached to a GameObject? Secondly, am I mistaken that I can copy the curve data into the exposed AnimationCurve and see it in the curve editor after running this script? And thirdly, if 1 and 2 are okay, what am I doing wrong in the script above?</p>*_</em>

I haven't played that much with animations, but I'm quite sure the reason is that your `army` variable has been set to the type `System.Object`. It should be of the type `ArmCurves`, so cast it to that and you should get permission to access `joint0x`.

About you questions:

1) Yes, however you can't access scripts in the Editor folder from other scripts (not in the Editor folder). 2) Yes and no, you can copy it into the exposed AnimationCurve `joint0x` variable, however I don't think it will be viewable in the Animation editor. You can apply it to the animation on the game object and it should be viewable from there. Try taking a look at AnimationUtility.