// Vibration Branch

// - This 'shortcut' script creates a vibration branch under the Project object in
//   the DesignSpace tree, including a typical frequency results

// make sure there's an active tree object
//
if( DS.Tree )
{
    var MBBT_OK = 0;
    var MBBT_ICONWARNING = 48;
    var buttonType = MBBT_OK + MBBT_ICONWARNING;
    var caption = DS.Script.localString("ID_DesignSpaceWarning");
    var message;
    var branchObj = null;
    var freqObj;
    branchObj = DS.Tree.FirstActiveBranch;
    if( !branchObj )
    {
        message = DS.Script.localString("ID_CannotFindBranch");
        DS.Script.WBScript.Out( message, true, caption, buttonType, this );
    }

    if( branchObj )
    {
        // get the Answers object
        var answersObj = branchObj.AnswerSet;
        if( answersObj )
        {
            var activeId = DS.Tree.FirstActiveObjectID;
            var answersObjId = answersObj.ID;
            DS.Script.changeActiveObject( answersObjId );

            if( DS.GUIState.AnswerSetLayer.CanInsertFrequencyGroup() )
            {
                // make sure there's nothing selected
                //
                SM.Clear();
                // add the frequency group to the branch
                //
                freqObj = answersObj.AddFrequencyGroup();

                DS.Script.fillTree();

                WizObj.ShowWizard( "VibrationWizard.xml" );
            }
            else
            {
                //if an error occurs, alert the user that the branch was not added
                var message = DS.Script.localString("ID_InsertOutlineBranchNotValid");
                DS.Script.WBScript.Out( message, true, caption, buttonType, this );
            }

            DS.Script.changeActiveObject( activeId );
        }
    }
}
