public ScriptVariable Call(IList <ScriptVariable> args, ScriptConsole console)
        {
            _progress.Initialize(0, "Initializing...");
            if (args == null)
            {
                throw new ArgumentNullException("args", "args cannot be null");
            }
            if (args.Count < 1)
            {
                args = new List <ScriptVariable> {
                    null
                }
            }
            ;
            if (args[0] == null)
            {
                args[0] = new ListVariable();
            }
            IList <ScriptVariable> objectNamesVar = args[0].ToList();

            if (objectNamesVar.Any(n => n.IsNull()))
            {
                throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNameCannotBeNull, "args");
            }
            List <string>           objectNames = objectNamesVar.Select(n => n.ToString()).ToList();
            MotionDataSet           dataSet     = console.MotionDataSet;
            MotionProcEnv           env2        = new MotionProcEnv(console);
            List <MotionObjectInfo> infoList    = new List <MotionObjectInfo>();

            foreach (string objectName in objectNames)
            {
                MotionObjectInfo info = dataSet.GetObjectInfoByName(objectName);
                if (info == null)
                {
                    throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNotFound + ": " + objectName, "args");
                }
                infoList.Add(info);
            }
            foreach (MotionObjectInfo info in infoList)
            {
                if (!_operation.FilterSelection(info))
                {
                    throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidTargetObjectSpecified + ": " + info.Name, "args");
                }
            }
            string errorMessage = "";

            if (!_operation.ValidateSelection(infoList, ref errorMessage))
            {
                if (errorMessage == null)
                {
                    errorMessage = "";
                }
                throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ImproperObjectSelection + ": " + errorMessage, "args");
            }

            IList <ProcParam <MotionProcEnv> > parameters = _operation.GetParameters() ?? new ProcParam <MotionProcEnv> [0];

            if (args.Count != parameters.Count + 1)
            {
                throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_NumberOfArgumentsRequired, parameters.Count + 1));
            }
            for (int i = 0; i < parameters.Count; i++)
            {
                if (!parameters[i].FromScriptVariable(env2, args[i + 1], ref errorMessage))
                {
                    throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidNthArgument + ": {1}", i + 1, errorMessage ?? ""), "args");
                }
            }
            if (!_operation.ValidateArguments(parameters, ref errorMessage))
            {
                throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidArgument + ": {0}", errorMessage ?? ""), "args");
            }
            IMotionOperationGeneral general = _operation as IMotionOperationGeneral;

            if (general != null)
            {
                _progress.Initialize(0, "Operation");
                general.Operate(infoList, parameters, dataSet, _progress);
                return(new ListVariable(infoList.Select(info => new StringVariable(info.Name))));
            }
            IMotionOperationEditObject edit = _operation as IMotionOperationEditObject;

            if (edit != null)
            {
                _progress.Initialize(dataSet.FrameLength, "Edit Object");
                foreach (MotionFrame frame in dataSet.EnumerateFrame())
                {
                    IList <MotionObject> results = edit.EditObject(infoList, parameters, new ReadOnlyMotionFrame(frame), false);
                    int count = Math.Min(results.Count, infoList.Count);
                    for (int i = 0; i < count; i++)
                    {
                        frame[infoList[i]] = results[i];
                    }
                    _progress.CurrentValue++;
                }
                dataSet.DoFrameListChanged();
                return(new ListVariable(infoList.Select(info => new StringVariable(info.Name))));
            }
            IMotionOperationOutputSequence output = _operation as IMotionOperationOutputSequence;

            if (output != null)
            {
                _progress.Initialize(0, "Output");
                IList <Sequence.SequenceData> sequences = output.OutputSequence(infoList, parameters, dataSet.EnumerateFrame().Select(frame => new ReadOnlyMotionFrame(frame)), _progress);
                foreach (Sequence.SequenceData sequence in sequences)
                {
                    console.SequenceController.AddSequence(sequence);
                }
                return(new ListVariable(sequences.Select(s => new StringVariable(s.Title))));
            }
            IMotionOperationCreateObject create = _operation as IMotionOperationCreateObject;

            if (create != null)
            {
                _progress.Initialize(dataSet.FrameLength, "Create Object");
                IList <MotionObjectInfo> newInfoList = create.GetNewObjectInfoList(infoList, parameters);
                MotionFrame firstFrame = dataSet.GetFrameByIndex(0);
                if (firstFrame != null)
                {
                    IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(firstFrame), false) ?? new MotionObject[0];
                    if (newObjects.Count != newInfoList.Count)
                    {
                        throw new InvalidOperationException(global::MotionDataHandler.Properties.Settings.Default.Msg_CreateObjectLengthMismatch);
                    }
                }
                foreach (MotionObjectInfo newInfo in newInfoList)
                {
                    dataSet.AddObject(newInfo);
                }
                foreach (MotionFrame frame in dataSet.EnumerateFrame())
                {
                    IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(frame), false) ?? new MotionObject[0];
                    int count = Math.Min(newObjects.Count, newInfoList.Count);
                    for (int i = 0; i < count; i++)
                    {
                        frame[newInfoList[i]] = newObjects[i];
                    }
                    _progress.CurrentValue++;
                }
                dataSet.DoObjectInfoSetChanged();
                dataSet.DoFrameListChanged();
                return(new ListVariable(newInfoList.Select(info => new StringVariable(info.Name))));
            }
            return(null);
        }
        /// <summary>
        /// CreateObjectの結果に基づいてプレビューを表示します.
        /// </summary>
        protected virtual void SetPreview()
        {
            if (_operation == null)
            {
                return;
            }
            // 処理の種類を判別したい
            IMotionOperationCreateObject   createOpe  = _operation as IMotionOperationCreateObject;
            IMotionOperationEditObject     editOpe    = _operation as IMotionOperationEditObject;
            IMotionOperationGeneral        generalOpe = _operation as IMotionOperationGeneral;
            IMotionOperationOutputSequence outputOpe  = _operation as IMotionOperationOutputSequence;

            // 前回のプレビュー用オブジェクトを消しておく
            motionDataViewer.ClearPreviewObjects();

            // 作成や編集でなければプレビューしない
            if (createOpe == null && editOpe == null)
            {
                panelPreview.Visible = false;
                return;
            }

            panelPreview.Visible = true;
            // 引数チェック.失敗したら表示しない
            string errorMessage = "";

            if (!_operation.ValidateArguments(_exec.Parameters, ref errorMessage))
            {
                return;
            }
            // フレーム取得.失敗したら表示しない
            MotionFrame frame = _console.MotionDataSet.GetFrameAt(TimeController.Singleton.CurrentTime);

            if (frame == null)
            {
                return;
            }
            // 作成/編集結果のオブジェクトと,プレビュー時のみに表示されるオブジェクトを分類する
            IList <MotionObject> previewObjs    = null;
            IList <MotionObject> previewSubObjs = null;

            if (createOpe != null)
            {
                previewSubObjs = createOpe.CreateObjects(_targetInfoList, _exec.Parameters, new ReadOnlyMotionFrame(frame), true);
                previewObjs    = createOpe.CreateObjects(_targetInfoList, _exec.Parameters, new ReadOnlyMotionFrame(frame), false);
            }
            else if (editOpe != null)
            {
                previewSubObjs = editOpe.EditObject(_targetInfoList, _exec.Parameters, new ReadOnlyMotionFrame(frame), true);
                previewObjs    = editOpe.EditObject(_targetInfoList, _exec.Parameters, new ReadOnlyMotionFrame(frame), false);
            }
            if (previewObjs == null)
            {
                return;
            }
            if (previewSubObjs == null)
            {
                previewSubObjs = previewObjs;
            }
            if (previewSubObjs.Count >= previewObjs.Count)
            {
                previewSubObjs = previewSubObjs.Skip(previewObjs.Count).ToList();
            }
            // プレビュー対象をビューに登録しつつ,重心を求める
            Vector3 sum   = Vector3.Empty;
            int     count = 0;

            if (previewObjs != null)
            {
                foreach (var @object in previewObjs)
                {
                    if (@object != null)
                    {
                        sum += @object.GravityPoint;
                        motionDataViewer.AddPreviewObject(@object, false);
                        count++;
                    }
                }
                foreach (var @object in previewSubObjs)
                {
                    if (@object != null)
                    {
                        sum += @object.GravityPoint;
                        motionDataViewer.AddPreviewObject(@object, true);
                        count++;
                    }
                }
                if (editOpe != null)
                {
                    foreach (MotionObjectInfo info in _targetInfoList)
                    {
                        motionDataViewer.AddPreviewRemoveObject(info);
                    }
                }
            }
            // ビューのカメラを重心の方に向ける
            if (count > 0)
            {
                sum *= 1f / count;
                motionDataViewer.ViewCamera.SetTarget(sum, false);
            }
        }