/*
 * planetary_gear_train.java
 */

import com.comsol.model.*;
import com.comsol.model.util.*;

/** Model exported on May 15 2026, 09:48 by COMSOL 6.4.0.421. */
public class planetary_gear_train {

  public static Model run() {
    Model model = ModelUtil.create("Model");

//    From the File menu, choose New.
//    In the New window, click Model Wizard.
//    In the Model Wizard window, click 3D.
//    In the Select Physics tree, select Structural Mechanics > Multibody Dynamics (mbd).
//    Click Add.
//    Click Study.
//    In the Select Study tree, select General Studies > Time Dependent.
//    Click Done.

    model.component().create("comp1", true);

    model.component("comp1").geom().create("geom1", 3);
    model.component("comp1").geom("geom1").geomRep("comsol");

    model.component("comp1").mesh().create("mesh1");
    model.component("comp1").mesh("mesh1").contribute("geom/detail", true);

    model.component("comp1").physics().create("mbd", "MultibodyDynamics", "geom1");

    model.study().create("std1");
    model.study("std1").create("time", "Transient");

//    In the Model Builder window, under Global Definitions, click Parameters 1.
//    In the Settings window for Parameters, locate the Parameters section.
//    Click Load from File.
//    Browse to the model's Application Library folder and double-click the file planetary_gear_train_parameters.txt.
//    To import content from file, use:
//    model.param().loadFile("FILENAME");
    model.param().set("ns", "34", "Number of teeth, sun gear");
    model.param().set("dps", "102[mm]", "Pitch diameter, sun gear");
    model.param().set("m", "dps/ns", "Module");
    model.param().set("np", "31", "Number of teeth, planet gear");
    model.param().set("dpp", "93[mm]", "Pitch diameter, planet gear");
    model.param().set("n", "5", "Number of planet gears");
    model.param().set("dpr", "(dps/2+dpp)*2", "Pitch diameter, ring gear");
    model.param().set("nr", "dpr/m", "Number of teeth, ring gear");
    model.param().set("ang", "2*pi/n[rad]", "Angle between planet gears");
    model.param().set("distp", "(dps+dpp)/2", "Distance between sun and planet gears");
    model.param().set("alpha", "25[deg]", "Pressure angle");
    model.param().set("beta", "30[deg]", "Helix angle");
    model.param().set("omega", "100[rad/s]", "Angular velocity");
    model.param().set("tf", "0.25[s]", "Final time");
    model.param().set("dt", "1.5e-3[s]", "Time interval");

//    In the Model Builder window, expand the Component 1 (comp1) > Geometry 1 node, then click Geometry 1.
//    In the Settings window for Geometry, locate the Advanced section.
//    From the Geometry representation list, select CAD kernel.

    model.component("comp1").geom("geom1").geomRep("cadps");

//    You can import the geometry of the gear train by browsing to the model's Application Libraries folder.
//    In the Geometry toolbar, click Import.

    model.component("comp1").geom("geom1").create("imp1", "Import");

//    In the Settings window for Import, locate the Source section.
//    Click Browse.
//    Browse to the model's Application Library folder and double-click the file planetary_gear_train.mphbin.

    model.component("comp1").geom("geom1").feature("imp1").set("filename", "planetary_gear_train.mphbin");

//    Click Import.

    model.component("comp1").geom("geom1").feature("imp1").importData();

//    In the Model Builder window, under Component 1 (comp1) > Geometry 1, click Form Union (fin).
//    In the Settings window for Form Union/Assembly, locate the Form Union/Assembly section.
//    From the Action list, select Form an assembly.

    model.component("comp1").geom("geom1").feature("fin").set("action", "assembly");

//    In the Geometry toolbar, click Build All.

    model.component("comp1").geom("geom1").run("fin");

//    Rearrange <l>Identity Boundary Pair</l> nodes to help automatic generation of hinge joints.
//    In the Model Builder window, expand the Component 1 (comp1) > Definitions node, then click Identity Boundary Pair 5 (ap5).
//    In the Settings window for Pair, click the Swap Source and Destination button.

    model.component("comp1").pair("ap5").swap();

//    Drag and drop above Identity Boundary Pair 1 (ap1).

    model.component("comp1").pair().move("ap5", 0);

//    In the Model Builder window, click Identity Boundary Pair 4 (ap4).
//    In the Settings window for Pair, click the Swap Source and Destination button.

    model.component("comp1").pair("ap4").swap();

//    Drag and drop below Identity Boundary Pair 5 (ap5).

    model.component("comp1").pair().move("ap4", 1);

//    In the Model Builder window, click Identity Boundary Pair 2 (ap2).
//    In the Settings window for Pair, click the Swap Source and Destination button.

    model.component("comp1").pair("ap2").swap();

//    Drag and drop below Identity Boundary Pair 4 (ap4).

    model.component("comp1").pair().move("ap2", 2);

//    In the Model Builder window, click Identity Boundary Pair 3 (ap3).
//    In the Settings window for Pair, click the Swap Source and Destination button.

    model.component("comp1").pair("ap3").swap();

//    In the Model Builder window, click Identity Boundary Pair 1 (ap1).
//    In the Settings window for Pair, click the Swap Source and Destination button.

    model.component("comp1").pair("ap1").swap();

//    Define a <l>Step</l> function to use in the expression of the input angular velocity.
//    In the Definitions toolbar, click More Functions and choose Step.

    model.component("comp1").func().create("step1", "Step");

//    In the Settings window for Step, locate the Parameters section.
//    In the Location text field, type 7.5e-3[s].

    model.component("comp1").func("step1").set("location", "7.5e-3[s]");

//    Click to expand the Smoothing section.
//    In the Size of transition zone text field, type 1.5e-2.

    model.component("comp1").func("step1").set("smooth", "1.5e-2");

//    Now create selections of the geometry. You will use them later when setting up the physics and mesh.
//    In the Geometry toolbar, click Selections and choose Explicit Selection.

    model.component("comp1").geom("geom1").create("sel1", "ExplicitSelection");

//    In the Model Builder window, expand the Component 1 (comp1) > Materials node, then click Component 1 (comp1) > Geometry 1 > Explicit Selection 1 (sel1).
//    In the Settings window for Explicit Selection, type Ring Gear in the Label text field.

    model.component("comp1").geom("geom1").feature("sel1").label("Ring Gear");

//    Locate the Color section.
//    From the Color list, choose None or — if you are running the cross-platform desktop — - Custom.

    model.component("comp1").geom("geom1").feature("sel1").set("color", "custom");

//    Click Show color palette only or OK on the cross-platform desktop.
//    Click Add to custom colors.
//    Set the RGB values to 205, 222, and 221, respectively.
//    Click Define custom colors.

    model.component("comp1").geom("geom1").feature("sel1")
         .set("customcolor", new double[]{0.8039215803146362, 0.8705882430076599, 0.8666666746139526});

//    On the object fin, select Domains 1, 2.

    model.component("comp1").geom("geom1").feature("sel1").selection("selection").set("fin", 1, 2);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("sel1");

//    Right-click Ring Gear and choose Duplicate.

    model.component("comp1").geom("geom1").feature().duplicate("sel2", "sel1");

//    In the Settings window for Explicit Selection, type Sun Gear in the Label text field.

    model.component("comp1").geom("geom1").feature("sel2").label("Sun Gear");

//    Locate the Entities to Select section.
//    Click the Clear Selection button for Entities to select.

    model.component("comp1").geom("geom1").feature("sel2").selection("selection").clear("fin");

//    Locate the Color section.
//    Click Show color palette only or OK on the cross-platform desktop.
//    Click Add to custom colors.
//    Set the RGB values to 226, 211, and 201, respectively.
//    Click Define custom colors.

    model.component("comp1").geom("geom1").feature("sel2")
         .set("customcolor", new double[]{0.886274516582489, 0.8274509906768799, 0.7882353067398071});

//    On the object fin, select Domain 6.

    model.component("comp1").geom("geom1").feature("sel2").selection("selection").set("fin", 6);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("sel2");

//    Right-click Sun Gear and choose Duplicate.

    model.component("comp1").geom("geom1").feature().duplicate("sel3", "sel2");

//    In the Settings window for Explicit Selection, type Planet Gears in the Label text field.

    model.component("comp1").geom("geom1").feature("sel3").label("Planet Gears");

//    Locate the Entities to Select section.
//    Click the Clear Selection button for Entities to select.

    model.component("comp1").geom("geom1").feature("sel3").selection("selection").clear("fin");

//    Locate the Color section.
//    Click Show color palette only or OK on the cross-platform desktop.
//    Click Add to custom colors.
//    Set the RGB values to 126, 123, and 122, respectively.
//    Click Define custom colors.

    model.component("comp1").geom("geom1").feature("sel3")
         .set("customcolor", new double[]{0.4941176474094391, 0.48235294222831726, 0.47843137383461});

//    On the object fin, select Domains 4, 5, 7, 8, 9.

    model.component("comp1").geom("geom1").feature("sel3").selection("selection").set("fin", 4, 5, 7, 8, 9);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("sel3");

//    Right-click Planet Gears and choose Duplicate.

    model.component("comp1").geom("geom1").feature().duplicate("sel4", "sel3");

//    In the Settings window for Explicit Selection, type Carrier in the Label text field.

    model.component("comp1").geom("geom1").feature("sel4").label("Carrier");

//    Locate the Entities to Select section.
//    Click the Clear Selection button for Entities to select.

    model.component("comp1").geom("geom1").feature("sel4").selection("selection").clear("fin");

//    Locate the Color section.
//    Click Show color palette only or OK on the cross-platform desktop.
//    Click Add to custom colors.
//    Set the RGB values to 233, 233, and 155, respectively.
//    Click Define custom colors.

    model.component("comp1").geom("geom1").feature("sel4")
         .set("customcolor", new double[]{0.9137254953384399, 0.9137254953384399, 0.6078431606292725});

//    On the object fin, select Domain 3.

    model.component("comp1").geom("geom1").feature("sel4").selection("selection").set("fin", 3);

//    Click Build Selected.

    model.component("comp1").geom("geom1").run("sel4");

//    In the Model Builder window, under Component 1 (comp1) > Geometry 1, Ctrl-click to select Ring Gear (sel1), Sun Gear (sel2), Planet Gears (sel3), Carrier (sel4).
//    Right-click and choose Group.

    model.component("comp1").geom("geom1").nodeGroup().create("grp1");
    model.component("comp1").geom("geom1").nodeGroup("grp1").placeAfter("fin");
    model.component("comp1").geom("geom1").nodeGroup("grp1").add("sel1");
    model.component("comp1").geom("geom1").nodeGroup("grp1").add("sel2");
    model.component("comp1").geom("geom1").nodeGroup("grp1").add("sel3");
    model.component("comp1").geom("geom1").nodeGroup("grp1").add("sel4");

//    In the Settings window for Group, type Selections in the Label text field.

    model.component("comp1").geom("geom1").nodeGroup("grp1").label("Selections");

//    Assign material properties. Use <l>Steel AISI 4340</l> from the built-in material library.
//    In the Materials toolbar, click Add Material to open the Add Material window.
//    In the tree, select Built-in > Steel AISI 4340.
//    Right-click and choose Link in Component 1 (comp1).

    model.component("comp1").material().create("mat1", "LibraryLink");
    model.component("comp1").material("mat1").set("materialPath", "comsol_basic_material_lib.steel_aisi_4340");
    model.component("comp1").material("mat1").reload();

//    In the Materials toolbar, click Add Material to close the Add Material window.
//    In the Physics toolbar, click Domains and choose Rigid Material.

    model.component("comp1").physics("mbd").create("rd1", "RigidDomain", 3);

//    Select Domain 3.

    model.component("comp1").physics("mbd").feature("rd1").selection().set(3);

//    In the Settings window for Rigid Material, type Rigid Material: Carrier in the Label text field.

    model.component("comp1").physics("mbd").feature("rd1").label("Rigid Material: Carrier");

//    In the Physics toolbar, click Attributes and choose Fixed Constraint.

    model.component("comp1").physics("mbd").feature("rd1").create("fix1", "FixedConstraint", -1);

//    Add <l>Helical Gear</l> nodes and specify the gear properties.
//    In the Physics toolbar, click Domains and choose Helical Gear.

    model.component("comp1").physics("mbd").create("hlg1", "HelicalGear", 3);

//    In the Settings window for Helical Gear, type Helical Gear: Ring Gear in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg1").label("Helical Gear: Ring Gear");

//    Locate the Domain Selection section.
//    From the Selection list, select Ring Gear.

    model.component("comp1").physics("mbd").feature("hlg1").selection().named("geom1_sel1");

//    Locate the Gear Properties section.
//    From the Gear mesh list, select Internal.

    model.component("comp1").physics("mbd").feature("hlg1").set("GearMesh", "Internal");

//    In the \[n\] text field, type nr.

    model.component("comp1").physics("mbd").feature("hlg1").set("nt", "nr");

//    In the \[d_\textrm{p}\] text field, type dpr.

    model.component("comp1").physics("mbd").feature("hlg1").set("dp", "dpr");

//    In the \[\alpha\] text field, type alpha.

    model.component("comp1").physics("mbd").feature("hlg1").set("alpha", "alpha");

//    In the \[\beta\] text field, type -beta.

    model.component("comp1").physics("mbd").feature("hlg1").set("beta", "-beta");

//    Locate the Center of Rotation section.
//    From the list, select User defined.

    model.component("comp1").physics("mbd").feature("hlg1").set("CenterOfRotationType", "UserDefined");

//    Right-click Helical Gear: Ring Gear and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg2", "hlg1");

//    In the Settings window for Helical Gear, type Helical Gear: Sun Gear in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg2").label("Helical Gear: Sun Gear");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg2").selection().set();

//    From the Selection list, select Sun Gear.

    model.component("comp1").physics("mbd").feature("hlg2").selection().named("geom1_sel2");

//    Locate the Gear Properties section.
//    From the Gear mesh list, select External.

    model.component("comp1").physics("mbd").feature("hlg2").set("GearMesh", "External");

//    In the \[n\] text field, type ns.

    model.component("comp1").physics("mbd").feature("hlg2").set("nt", "ns");

//    In the \[d_\textrm{p}\] text field, type dps.

    model.component("comp1").physics("mbd").feature("hlg2").set("dp", "dps");

//    In the \[\beta\] text field, type beta.

    model.component("comp1").physics("mbd").feature("hlg2").set("beta", "beta");

//    Right-click Helical Gear: Sun Gear and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg3", "hlg2");

//    In the Settings window for Helical Gear, type Helical Gear: Planet Gear 1 in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg3").label("Helical Gear: Planet Gear 1");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg3").selection().set();

//    Select Domain 9.

    model.component("comp1").physics("mbd").feature("hlg3").selection().set(9);

//    Locate the Gear Properties section.
//    In the \[n\] text field, type np.

    model.component("comp1").physics("mbd").feature("hlg3").set("nt", "np");

//    In the \[d_\textrm{p}\] text field, type dpp.

    model.component("comp1").physics("mbd").feature("hlg3").set("dp", "dpp");

//    In the \[\beta\] text field, type -beta.

    model.component("comp1").physics("mbd").feature("hlg3").set("beta", "-beta");

//    Locate the Center of Rotation section.
//    Specify the \[\mathbf{X}_\textrm{c}\] vector as

    model.component("comp1").physics("mbd").feature("hlg3").set("xc", new String[]{"distp", "0", "0"});

//    Right-click Helical Gear: Planet Gear 1 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg4", "hlg3");

//    In the Settings window for Helical Gear, type Helical Gear: Planet Gear 2 in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg4").label("Helical Gear: Planet Gear 2");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg4").selection().set();

//    Select Domain 8.

    model.component("comp1").physics("mbd").feature("hlg4").selection().set(8);

//    Locate the Center of Rotation section.
//    Specify the \[\mathbf{X}_\textrm{c}\] vector as

    model.component("comp1").physics("mbd").feature("hlg4")
         .set("xc", new String[]{"distp*cos(ang)", "distp*sin(ang)", "0"});

//    Right-click Helical Gear: Planet Gear 2 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg5", "hlg4");

//    In the Settings window for Helical Gear, type Helical Gear: Planet Gear 3 in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg5").label("Helical Gear: Planet Gear 3");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg5").selection().set();

//    Select Domain 5.

    model.component("comp1").physics("mbd").feature("hlg5").selection().set(5);

//    Locate the Center of Rotation section.
//    Specify the \[\mathbf{X}_\textrm{c}\] vector as

    model.component("comp1").physics("mbd").feature("hlg5")
         .set("xc", new String[]{"distp*cos(2*ang)", "distp*sin(2*ang)", "0"});

//    Right-click Helical Gear: Planet Gear 3 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg6", "hlg5");

//    In the Settings window for Helical Gear, type Helical Gear: Planet Gear 4 in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg6").label("Helical Gear: Planet Gear 4");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg6").selection().set();

//    Select Domain 4.

    model.component("comp1").physics("mbd").feature("hlg6").selection().set(4);

//    Locate the Center of Rotation section.
//    Specify the \[\mathbf{X}_\textrm{c}\] vector as

    model.component("comp1").physics("mbd").feature("hlg6")
         .set("xc", new String[]{"distp*cos(3*ang)", "distp*sin(3*ang)", "0"});

//    Right-click Helical Gear: Planet Gear 4 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hlg7", "hlg6");

//    In the Settings window for Helical Gear, type Helical Gear: Planet Gear 5 in the Label text field.

    model.component("comp1").physics("mbd").feature("hlg7").label("Helical Gear: Planet Gear 5");

//    Locate the Domain Selection section.
//    Click Clear Selection.

    model.component("comp1").physics("mbd").feature("hlg7").selection().set();

//    Select Domain 7.

    model.component("comp1").physics("mbd").feature("hlg7").selection().set(7);

//    Locate the Center of Rotation section.
//    Specify the \[\mathbf{X}_\textrm{c}\] vector as

    model.component("comp1").physics("mbd").feature("hlg7")
         .set("xc", new String[]{"distp*cos(4*ang)", "distp*sin(4*ang)", "0"});

//    In the Model Builder window, click Helical Gear: Ring Gear.
//    In the Physics toolbar, click Attributes and choose Fixed Constraint.

    model.component("comp1").physics("mbd").feature("hlg1").create("fix1", "FixedConstraint", -1);

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd), click Helical Gear: Sun Gear.
//    In the Physics toolbar, click Attributes and choose Fixed Constraint.

    model.component("comp1").physics("mbd").feature("hlg2").create("fix1", "FixedConstraint", -1);

//    Select all gear features, and right click on <l>Group</l> to create a group.

    model.nodeGroup().create("grp1", "Physics", "mbd");
    model.nodeGroup("grp1").placeAfter("rd1");
    model.nodeGroup("grp1").add("hlg1");
    model.nodeGroup("grp1").add("hlg2");
    model.nodeGroup("grp1").add("hlg3");
    model.nodeGroup("grp1").add("hlg4");
    model.nodeGroup("grp1").add("hlg5");
    model.nodeGroup("grp1").add("hlg6");
    model.nodeGroup("grp1").add("hlg7");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd), click Group 1.
//    In the Settings window for Group, type Gears in the Label text field.

    model.nodeGroup("grp1").label("Gears");

//    Use <l>Gear Pair</l> nodes, with different properties to connect the gears.
//    In the Physics toolbar, click Global and choose Gear Pair.

    model.component("comp1").physics("mbd").create("grp1", "GearPair", -1);

//    In the Settings window for Gear Pair, type Gear Pair: Ring-Planet 1 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp1").label("Gear Pair: Ring-Planet 1");

//    Locate the Gear Selection section.
//    From the Wheel list, select Helical Gear: Ring Gear.

    model.component("comp1").physics("mbd").feature("grp1").set("Wheel", "hlg1");

//    From the Pinion list, select Helical Gear: Planet Gear 1.

    model.component("comp1").physics("mbd").feature("grp1").set("Pinion", "hlg3");

//    Right-click Gear Pair: Ring-Planet 1 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp2", "grp1");

//    In the Settings window for Gear Pair, type Gear Pair: Ring-Planet 2 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp2").label("Gear Pair: Ring-Planet 2");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 2.

    model.component("comp1").physics("mbd").feature("grp2").set("Pinion", "hlg4");

//    Right-click Gear Pair: Ring-Planet 2 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp3", "grp2");

//    In the Settings window for Gear Pair, type Gear Pair: Ring-Planet 3 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp3").label("Gear Pair: Ring-Planet 3");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 3.

    model.component("comp1").physics("mbd").feature("grp3").set("Pinion", "hlg5");

//    Right-click Gear Pair: Ring-Planet 3 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp4", "grp3");

//    In the Settings window for Gear Pair, type Gear Pair: Ring-Planet 4 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp4").label("Gear Pair: Ring-Planet 4");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 4.

    model.component("comp1").physics("mbd").feature("grp4").set("Pinion", "hlg6");

//    Right-click Gear Pair: Ring-Planet 4 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp5", "grp4");

//    In the Settings window for Gear Pair, type Gear Pair: Ring-Planet 5 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp5").label("Gear Pair: Ring-Planet 5");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 5.

    model.component("comp1").physics("mbd").feature("grp5").set("Pinion", "hlg7");

//    Right-click Gear Pair: Ring-Planet 5 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp6", "grp5");

//    In the Settings window for Gear Pair, type Gear Pair: Sun-Planet 1 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp6").label("Gear Pair: Sun-Planet 1");

//    Locate the Gear Selection section.
//    From the Wheel list, select Helical Gear: Sun Gear.

    model.component("comp1").physics("mbd").feature("grp6").set("Wheel", "hlg2");

//    From the Pinion list, select Helical Gear: Planet Gear 1.

    model.component("comp1").physics("mbd").feature("grp6").set("Pinion", "hlg3");

//    Right-click Gear Pair: Sun-Planet 1 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp7", "grp6");

//    In the Settings window for Gear Pair, type Gear Pair: Sun-Planet 2 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp7").label("Gear Pair: Sun-Planet 2");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 2.

    model.component("comp1").physics("mbd").feature("grp7").set("Pinion", "hlg4");

//    Right-click Gear Pair: Sun-Planet 2 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp8", "grp7");

//    In the Settings window for Gear Pair, type Gear Pair: Sun-Planet 3 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp8").label("Gear Pair: Sun-Planet 3");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 3.

    model.component("comp1").physics("mbd").feature("grp8").set("Pinion", "hlg5");

//    Right-click Gear Pair: Sun-Planet 3 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp9", "grp8");

//    In the Settings window for Gear Pair, type Gear Pair: Sun-Planet 4 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp9").label("Gear Pair: Sun-Planet 4");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 4.

    model.component("comp1").physics("mbd").feature("grp9").set("Pinion", "hlg6");

//    Right-click Gear Pair: Sun-Planet 4 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("grp10", "grp9");

//    In the Settings window for Gear Pair, type Gear Pair: Sun-Planet 5 in the Label text field.

    model.component("comp1").physics("mbd").feature("grp10").label("Gear Pair: Sun-Planet 5");

//    Locate the Gear Selection section.
//    From the Pinion list, select Helical Gear: Planet Gear 5.

    model.component("comp1").physics("mbd").feature("grp10").set("Pinion", "hlg7");

//    Select all gear pair features, and right click on <l>Group</l> to create a group.

    model.nodeGroup().create("grp2", "Physics", "mbd");
    model.nodeGroup("grp2").placeAfter("rd1");
    model.nodeGroup("grp2").add("grp1");
    model.nodeGroup("grp2").add("grp2");
    model.nodeGroup("grp2").add("grp3");
    model.nodeGroup("grp2").add("grp4");
    model.nodeGroup("grp2").add("grp5");
    model.nodeGroup("grp2").add("grp6");
    model.nodeGroup("grp2").add("grp7");
    model.nodeGroup("grp2").add("grp8");
    model.nodeGroup("grp2").add("grp9");
    model.nodeGroup("grp2").add("grp10");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd), click Group 2.
//    In the Settings window for Group, type Gear Pairs in the Label text field.

    model.nodeGroup("grp2").label("Gear Pairs");

//    Do as follows to generate <l>Hinge Joint</l> nodes between components.
//    In the Model Builder window, click Multibody Dynamics (mbd).
//    In the Settings window for Multibody Dynamics, click Physics Node Generation in the upper-right corner of the Automated Model Setup section.
//    From the menu, choose Create Joints.

    model.component("comp1").physics("mbd").prop("AutoModeling").runCommand("createJoints");

//    In the Model Builder window, expand the Hinge Joints node, then click Hinge Joint 1.
//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier-Planet 1 in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj1").label("Hinge Joint: Carrier-Planet 1");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd) > Hinge Joints, click Hinge Joint 2.
//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier-Planet 2 in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj2").label("Hinge Joint: Carrier-Planet 2");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd) > Hinge Joints, click Hinge Joint 3.
//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier-Planet 3 in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj3").label("Hinge Joint: Carrier-Planet 3");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd) > Hinge Joints, click Hinge Joint 4.
//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier-Planet 4 in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj4").label("Hinge Joint: Carrier-Planet 4");

//    In the Model Builder window, under Component 1 (comp1) > Multibody Dynamics (mbd) > Hinge Joints, click Hinge Joint 5.
//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier-Planet 5 in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj5").label("Hinge Joint: Carrier-Planet 5");

//    Right-click Hinge Joint: Carrier-Planet 5 and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hgj6", "hgj5");

    model.nodeGroup("grp3").add("hgj6");

//    In the Settings window for Hinge Joint, type Hinge Joint: Carrier in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj6").label("Hinge Joint: Carrier");

//    Locate the Attachment Selection section.
//    From the Source list, select Fixed.

    model.component("comp1").physics("mbd").feature("hgj6").set("Source", "fixed");

//    From the Destination list, select Rigid Material: Carrier.

    model.component("comp1").physics("mbd").feature("hgj6").set("Destination", "rd1");

//    Locate the Center of Joint section.
//    Specify the \[\mathbf{X}_{_\textrm{c}}\] vector as

    model.component("comp1").physics("mbd").feature("hgj6").set("xc", new double[]{0, 0, -0.0228});

//    Right-click Hinge Joint: Carrier and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hgj7", "hgj6");

    model.nodeGroup("grp3").add("hgj7");

//    In the Settings window for Hinge Joint, type Hinge Joint: Sun Gear in the Label text field.

    model.component("comp1").physics("mbd").feature("hgj7").label("Hinge Joint: Sun Gear");

//    Locate the Attachment Selection section.
//    From the Destination list, select Helical Gear: Sun Gear.

    model.component("comp1").physics("mbd").feature("hgj7").set("Destination", "hlg2");

//    Prescribe the motion of the gear.
//    In the Physics toolbar, click Attributes and choose Prescribed Motion.

    model.component("comp1").physics("mbd").feature("hgj7").create("pm1", "PrescribedMotion", -1);

//    In the Settings window for Prescribed Motion, locate the Prescribed Rotational Motion section.
//    From the Prescribed motion through list, select Angular velocity.

    model.component("comp1").physics("mbd").feature("hgj7").feature("pm1")
         .set("PrescribedMotionThroughRotational", "AngularVelocity");

//    In the \[\omega_{_\textrm{p}}\] text field, type omega*step1(t).

    model.component("comp1").physics("mbd").feature("hgj7").feature("pm1").set("omegap", "omega*step1(t)");

//    In the Model Builder window, right-click Hinge Joint: Sun Gear and choose Duplicate.

    model.component("comp1").physics("mbd").feature().duplicate("hgj8", "hgj7");

    model.nodeGroup("grp3").add("hgj8");

//    In the Settings window for Hinge Joint, type Hinge Joint: Ring Gear in the Label text field.

    return model;
  }

  public static Model run2(Model model) {

    model.component("comp1").physics("mbd").feature("hgj8").label("Hinge Joint: Ring Gear");

//    Locate the Attachment Selection section.
//    From the Destination list, select Helical Gear: Ring Gear.

    model.component("comp1").physics("mbd").feature("hgj8").set("Destination", "hlg1");

//    In the Model Builder window, click Study 1.
//    In the Settings window for Study, type Study 1: Fixed Ring Gear in the Label text field.

    model.study("std1").label("Study 1: Fixed Ring Gear");

//    In the Model Builder window, under Study 1: Fixed Ring Gear, click Step 1: Time Dependent.
//    In the Settings window for Time Dependent, locate the Study Settings section.
//    In the Output times text field, type range(0,dt,tf).

    model.study("std1").feature("time").set("tlist", "range(0,dt,tf)");

//    Locate the Physics and Variables Selection section.
//    Select the Modify model configuration for study step checkbox.

    model.study("std1").feature("time").set("useadvanceddisable", true);

//    In the tree, select Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Rigid Material: Carrier > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Gears > Helical Gear: Sun Gear > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Ring Gear.
//    Right-click and choose Disable.

    model.study("std1").feature("time")
         .set("disabledphysics", new String[]{"mbd/hgj8", "mbd/hlg2/fix1", "mbd/rd1/fix1"});

//    In the Study toolbar, click Show Default Solver.

    model.study("std1").showAutoSequences("all");

//    In the Model Builder window, expand the Solution 1 (sol1) node.
//    In the Model Builder window, under Study 1: Fixed Ring Gear > Solver Configurations > Solution 1 (sol1), click Time-Dependent Solver 1.
//    In the Settings window for Time-Dependent Solver, click to expand the Time Stepping section.
//    From the Steps taken by solver list, select Intermediate.

    model.sol("sol1").feature("t1").set("tstepsbdf", "intermediate");

//    In the Study toolbar, click Compute.

    model.study("std1").createAutoSequences("all");

    model.sol("sol1").runAll();

    model.result().create("pg1", "PlotGroup3D");
    model.result("pg1").label("Displacement (mbd)");
    model.result("pg1").set("frametype", "spatial");
    model.result("pg1").set("smooth", "internal");
    model.result("pg1").feature().create("surf1", "Surface");
    model.result("pg1").feature("surf1").label("Surface");
    model.result("pg1").feature("surf1").set("colortable", "SpectrumLight");
    model.result("pg1").feature("surf1").set("data", "parent");
    model.result("pg1").feature("surf1").feature().create("def1", "Deform");
    model.result("pg1").feature("surf1").feature("def1").label("Deformation");
    model.result("pg1").feature("surf1").feature("def1").set("scaleactive", true);
    model.result().create("pg2", "PlotGroup3D");
    model.result("pg2").label("Velocity (mbd)");
    model.result("pg2").set("frametype", "spatial");
    model.result("pg2").set("smooth", "internal");
    model.result("pg2").feature().create("vol1", "Volume");
    model.result("pg2").feature("vol1").label("Domain Numbers");
    model.result("pg2").feature("vol1").set("descractive", true);
    model.result("pg2").feature("vol1").set("expr", "mod(dom,10)");
    model.result("pg2").feature("vol1").set("descr", "Domain numbers");
    model.result("pg2").feature("vol1").set("rangecoloractive", "on");
    model.result("pg2").feature("vol1").set("rangecolormin", -0.5);
    model.result("pg2").feature("vol1").set("rangecolormax", 9.5);
    model.result("pg2").feature("vol1").set("colortable", "Cyclic");
    model.result("pg2").feature("vol1").set("colorlegend", false);
    model.result("pg2").feature("vol1").set("colortabletype", "discrete");
    model.result("pg2").feature("vol1").set("smooth", "none");
    model.result("pg2").feature("vol1").set("data", "parent");
    model.result("pg2").feature("vol1").feature().create("def1", "Deform");
    model.result("pg2").feature("vol1").feature("def1").label("Deformation");
    model.result("pg2").feature("vol1").feature("def1").set("scaleactive", true);
    model.result("pg2").feature().create("arwl1", "ArrowLine");
    model.result("pg2").feature("arwl1").label("Arrow Line");
    model.result("pg2").feature("arwl1").set("expr", new String[]{"mbd.u_tX", "mbd.u_tY", "mbd.u_tZ"});
    model.result("pg2").feature("arwl1").set("placement", "elements");
    model.result("pg2").feature("arwl1").set("data", "parent");
    model.result("pg2").feature("arwl1").feature().create("def1", "Deform");
    model.result("pg2").feature("arwl1").feature("def1").label("Deformation");
    model.result("pg2").feature("arwl1").feature("def1").set("scaleactive", true);
    model.result("pg1").run();

//    Add another <l>Time Dependent</l> study and compute the solution for the configuration with fixed sun gear.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std2");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Model Builder window, right-click Study 1: Fixed Ring Gear > Step 1: Time Dependent and choose Copy.
//    In the Model Builder window, right-click Study 2 and choose Paste Time Dependent.

    model.study("std2").feature().copy("time", "std1/time");

//    In the Settings window for Study, type Study 2: Fixed Sun Gear in the Label text field.

    model.study("std2").label("Study 2: Fixed Sun Gear");

//    In the Model Builder window, under Study 2: Fixed Sun Gear, click Step 1: Time Dependent.
//    In the Settings window for Time Dependent, locate the Physics and Variables Selection section.
//    In the tree, select Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Gears > Helical Gear: Sun Gear > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Ring Gear.
//    Right-click and choose Enable.

    model.study("std2").feature("time").set("disabledphysics", new String[]{"mbd/rd1/fix1"});

//    In the tree, select Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Gears > Helical Gear: Ring Gear > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Sun Gear.
//    Right-click and choose Disable.

    model.study("std2").feature("time")
         .set("disabledphysics", new String[]{"mbd/rd1/fix1", "mbd/hgj7", "mbd/hlg1/fix1"});

//    In the Model Builder window, click Study 2: Fixed Sun Gear.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std2").setGenPlots(false);

//    In the Study toolbar, click Compute.

    model.study("std2").createAutoSequences("all");

    model.sol("sol2").runAll();

//    Add another <l>Time Dependent</l> study and compute the solution for the case with fixed carrier.
//    In the Home toolbar, click Add Study to open the Add Study window.
//    Find the Studies subsection.
//    In the Select Study tree, select Empty Study.
//    Click Add Study in the window toolbar.

    model.study().create("std3");

//    In the Home toolbar, click Add Study to close the Add Study window.
//    In the Model Builder window, right-click Study 1: Fixed Ring Gear > Step 1: Time Dependent and choose Copy.
//    In the Model Builder window, right-click Study 3 and choose Paste Time Dependent.

    model.study("std3").feature().copy("time", "std1/time");

//    In the Settings window for Study, type Study 3: Fixed Carrier in the Label text field.

    model.study("std3").label("Study 3: Fixed Carrier");

//    In the Model Builder window, under Study 3: Fixed Carrier, click Step 1: Time Dependent.
//    In the Settings window for Time Dependent, locate the Physics and Variables Selection section.
//    In the tree, select Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Rigid Material: Carrier > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Ring Gear.
//    Right-click and choose Enable.

    model.study("std3").feature("time").set("disabledphysics", new String[]{"mbd/hlg2/fix1"});

//    In the tree, select Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Gears > Helical Gear: Ring Gear > Fixed Constraint 1, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Carrier, Component 1 (comp1) > Multibody Dynamics (mbd), Controls spatial frame > Hinge Joints > Hinge Joint: Ring Gear > Prescribed Motion 1.
//    Click Disable.

    model.study("std3").feature("time")
         .set("disabledphysics", new String[]{"mbd/hlg2/fix1", "mbd/hgj8/pm1", "mbd/hgj6", "mbd/hlg1/fix1"});

//    In the Model Builder window, click Study 3: Fixed Carrier.
//    In the Settings window for Study, locate the Study Settings section.
//    Clear the Generate default plots checkbox.

    model.study("std3").setGenPlots(false);

//    In the Study toolbar, click Compute.

    model.study("std3").createAutoSequences("all");

    model.sol("sol3").runAll();

    model.component("comp1").view("view1").set("showgrid", false);

    model.result("pg1").run();

//    In the Model Builder window, under Results, click Displacement (mbd).
//    In the Settings window for 3D Plot Group, type Displacement: Fixed Ring Gear in the Label text field.

    model.result("pg1").label("Displacement: Fixed Ring Gear");
    model.result("pg1").run();

//    In the Model Builder window, expand the Displacement: Fixed Ring Gear node.
//    Right-click Surface and choose Selection.

    model.result("pg1").feature("surf1").create("sel1", "Selection");

//    In the Settings window for Selection, locate the Selection section.
//    From the Geometric entity level list, select Domain.

    model.result("pg1").feature("surf1").feature("sel1").selection().geom("geom1", 3);

//    Select Domains 3, 4, 5, 6, 7, 8, 9.

    model.result("pg1").feature("surf1").feature("sel1").selection().set(3, 4, 5, 6, 7, 8, 9);
    model.result("pg1").run();

//    Right-click Surface and choose Duplicate.

    model.result("pg1").feature().duplicate("surf2", "surf1");
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Model Builder window, expand the Surface 2 node, then click Selection 1.
//    In the Settings window for Selection, locate the Selection section.
//    Select the Activate Selection toggle button.
//    Click Clear Selection.

    model.result("pg1").feature("surf2").feature("sel1").selection().set();

//    From the Selection list, select Ring Gear.

    model.result("pg1").feature("surf2").feature("sel1").selection().named("geom1_sel1");
    model.result("pg1").run();

//    In the Model Builder window, click Surface 2.
//    In the Settings window for Surface, locate the Coloring and Style section.
//    From the Coloring list, select Uniform.

    model.result("pg1").feature("surf2").set("coloring", "uniform");

//    From the Color list, select Gray.

    model.result("pg1").feature("surf2").set("color", "gray");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg1").feature("surf2").set("titletype", "none");

//    Right-click Surface 2 and choose Transparency.

    model.result("pg1").feature("surf2").create("tran1", "Transparency");
    model.result("pg1").run();
    model.result("pg1").run();

//    In the Displacement: Fixed Ring Gear toolbar, click Plot.

    model.result("pg1").run();

//    In the Model Builder window, right-click Displacement: Fixed Ring Gear and choose Duplicate.

    model.result().duplicate("pg3", "pg1");
    model.result("pg3").run();

//    In the Settings window for 3D Plot Group, type Displacement: Fixed Sun Gear in the Label text field.

    model.result("pg3").label("Displacement: Fixed Sun Gear");

//    Locate the Data section.
//    From the Dataset list, select Study 2: Fixed Sun Gear/Solution 2 (sol2).

    model.result("pg3").set("data", "dset2");

//    In the Displacement: Fixed Sun Gear toolbar, click Plot.

    model.result("pg3").run();
    model.result("pg1").run();

//    Right-click Displacement: Fixed Ring Gear and choose Duplicate.

    model.result().duplicate("pg4", "pg1");
    model.result("pg4").run();

//    In the Settings window for 3D Plot Group, type Displacement: Fixed Carrier in the Label text field.

    model.result("pg4").label("Displacement: Fixed Carrier");

//    Locate the Data section.
//    From the Dataset list, select Study 3: Fixed Carrier/Solution 3 (sol3).

    model.result("pg4").set("data", "dset3");

//    In the Displacement: Fixed Carrier toolbar, click Plot.

    model.result("pg4").run();
    model.result("pg1").run();

//    In the Model Builder window, under Results, Ctrl-click to select Displacement: Fixed Ring Gear, Displacement: Fixed Sun Gear, Displacement: Fixed Carrier.
//    Right-click and choose Group.

    model.nodeGroup().create("grp4", "Results");
    model.nodeGroup("grp4").set("type", "plotgroup");
    model.nodeGroup("grp4").add("plotgroup", "pg1");
    model.nodeGroup("grp4").add("plotgroup", "pg3");
    model.nodeGroup("grp4").add("plotgroup", "pg4");

//    In the Settings window for Group, type Displacement in the Label text field.

    model.nodeGroup("grp4").label("Displacement");

    model.result("pg2").run();

//    In the Model Builder window, under Results, click Velocity (mbd).
//    In the Settings window for 3D Plot Group, type Velocity: Fixed Ring Gear in the Label text field.

    model.result("pg2").label("Velocity: Fixed Ring Gear");

//    In the Results toolbar, click Configurations and choose Graph Plot Style.

    model.result().configuration().create("gsty1", "GraphStyle");
    model.result().configuration("gsty1").set("linewidth", "unspecified");

//    In the Settings window for Graph Plot Style, locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Width list, select 2.

    model.result().configuration("gsty1").set("linewidth", 2);

//    Locate the Legends section.
//    Find the Include in automatic mode subsection.
//    Clear the Headers checkbox.

    model.result().configuration("gsty1").set("autoheaders", false);

//    Clear the Point checkbox.

    model.result().configuration("gsty1").set("autopoint", false);

//    Clear the Solution checkbox.

    model.result().configuration("gsty1").set("autosolution", false);

//    Select the Description checkbox.

    model.result().configuration("gsty1").set("autodescr", true);

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg5", "PlotGroup1D");
    model.result("pg5").run();

//    In the Settings window for 1D Plot Group, type Angular Velocity: Fixed Ring Gear in the Label text field.

    model.result("pg5").label("Angular Velocity: Fixed Ring Gear");

//    Click to expand the Title section.
//    From the Title type list, select None.

    model.result("pg5").set("titletype", "none");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg5").set("ylabelactive", true);

//    In the associated text field, type Angular Velocity (rad/s).

    model.result("pg5").set("ylabel", "Angular Velocity (rad/s)");

//    Click to expand the Style Configuration section.
//    From the Configuration list, select Graph Plot Style 1.

    model.result("pg5").set("styleconfig", "gsty1");

//    Right-click Angular Velocity: Fixed Ring Gear and choose Global.

    model.result("pg5").create("glob1", "Global");
    model.result("pg5").feature("glob1").set("markerpos", "datapoints");
    model.result("pg5").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg5").feature("glob1").setIndex("expr", "mbd.hgj7.th_t", 0);
    model.result("pg5").feature("glob1").setIndex("descr", "Sun Gear", 0);
    model.result("pg5").feature("glob1").setIndex("expr", "mbd.hgj6.th_t", 1);
    model.result("pg5").feature("glob1").setIndex("descr", "Carrier", 1);
    model.result("pg5").feature("glob1").setIndex("expr", "mbd.hgj1.th_t", 2);
    model.result("pg5").feature("glob1").setIndex("descr", "Planet Gear", 2);
    model.result("pg5").run();

//    In the Model Builder window, click Angular Velocity: Fixed Ring Gear.
//    In the Angular Velocity: Fixed Ring Gear toolbar, click Plot.

    model.result("pg5").run();

//    Right-click Angular Velocity: Fixed Ring Gear and choose Duplicate.

    model.result().duplicate("pg6", "pg5");
    model.result("pg6").run();

//    In the Settings window for 1D Plot Group, type Angular Velocity: Fixed Sun Gear in the Label text field.

    model.result("pg6").label("Angular Velocity: Fixed Sun Gear");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result("pg6").set("data", "none");
    model.result("pg6").run();

//    In the Model Builder window, expand the Angular Velocity: Fixed Sun Gear node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg6").feature("glob1").setIndex("expr", "mbd.hgj8.th_t", 0);
    model.result("pg6").feature("glob1").setIndex("descr", "Ring Gear", 0);
    model.result("pg6").feature("glob1").setIndex("expr", "mbd.hgj1.th_t", 1);
    model.result("pg6").feature("glob1").setIndex("descr", "Planet Gear", 1);
    model.result("pg6").feature("glob1").setIndex("expr", "mbd.hgj6.th_t", 2);
    model.result("pg6").feature("glob1").setIndex("descr", "Carrier", 2);
    model.result("pg6").run();

//    In the Model Builder window, click Angular Velocity: Fixed Sun Gear.
//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Dataset list, select Study 2: Fixed Sun Gear/Solution 2 (sol2).

    model.result("pg6").set("data", "dset2");

//    In the Angular Velocity: Fixed Sun Gear toolbar, click Plot.

    model.result("pg6").run();
    model.result("pg5").run();

//    In the Model Builder window, right-click Angular Velocity: Fixed Ring Gear and choose Duplicate.

    model.result().duplicate("pg7", "pg5");
    model.result("pg7").run();

//    In the Settings window for 1D Plot Group, type Angular Velocity: Fixed Carrier in the Label text field.

    model.result("pg7").label("Angular Velocity: Fixed Carrier");

//    Locate the Data section.
//    From the Dataset list, select None.

    model.result("pg7").set("data", "none");
    model.result("pg7").run();

//    In the Model Builder window, expand the Angular Velocity: Fixed Carrier node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg7").feature("glob1").setIndex("expr", "mbd.hgj7.th_t", 0);
    model.result("pg7").feature("glob1").setIndex("descr", "Sun Gear", 0);
    model.result("pg7").feature("glob1").setIndex("expr", "mbd.hgj8.th_t", 1);
    model.result("pg7").feature("glob1").setIndex("descr", "Ring Gear", 1);
    model.result("pg7").feature("glob1").setIndex("expr", "mbd.hgj1.th_t", 2);
    model.result("pg7").feature("glob1").setIndex("descr", "Planet Gear", 2);
    model.result("pg7").run();

//    In the Model Builder window, click Angular Velocity: Fixed Carrier.
//    In the Settings window for 1D Plot Group, locate the Data section.
//    From the Dataset list, select Study 3: Fixed Carrier/Solution 3 (sol3).

    model.result("pg7").set("data", "dset3");

//    In the Angular Velocity: Fixed Carrier toolbar, click Plot.

    model.result("pg7").run();
    model.result("pg5").run();

//    In the Model Builder window, under Results, Ctrl-click to select Angular Velocity: Fixed Ring Gear, Angular Velocity: Fixed Sun Gear, Angular Velocity: Fixed Carrier.
//    Right-click and choose Group.

    model.nodeGroup().create("grp5", "Results");
    model.nodeGroup("grp5").set("type", "plotgroup");
    model.nodeGroup("grp5").placeAfter("plotgroup", "pg2");
    model.nodeGroup("grp5").add("plotgroup", "pg5");
    model.nodeGroup("grp5").add("plotgroup", "pg6");
    model.nodeGroup("grp5").add("plotgroup", "pg7");

//    In the Settings window for Group, type Angular Velocity in the Label text field.

    model.nodeGroup("grp5").label("Angular Velocity");

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg8", "PlotGroup1D");
    model.result("pg8").run();

//    Right-click 1D Plot Group 8 and choose Global.

    model.result("pg8").create("glob1", "Global");
    model.result("pg8").feature("glob1").set("markerpos", "datapoints");
    model.result("pg8").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg8").feature("glob1").setIndex("expr", "mbd.hgj7.th_t/mbd.hgj6.th_t", 0);
    model.result("pg8").feature("glob1").setIndex("descr", "Fixed Ring Gear", 0);

//    Right-click Global 1 and choose Duplicate.

    model.result("pg8").feature().duplicate("glob2", "glob1");
    model.result("pg8").run();

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Study 2: Fixed Sun Gear/Solution 2 (sol2).

    model.result("pg8").feature("glob2").set("data", "dset2");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg8").feature("glob2").setIndex("expr", "mbd.hgj8.th_t/mbd.hgj6.th_t", 0);
    model.result("pg8").feature("glob2").setIndex("descr", "Fixed Sun Gear", 0);

//    Right-click Global 2 and choose Duplicate.

    model.result("pg8").feature().duplicate("glob3", "glob2");
    model.result("pg8").run();

//    In the Settings window for Global, locate the Data section.
//    From the Dataset list, select Study 3: Fixed Carrier/Solution 3 (sol3).

    model.result("pg8").feature("glob3").set("data", "dset3");

//    Locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg8").feature("glob3").setIndex("expr", "mbd.hgj7.th_t/mbd.hgj8.th_t", 0);
    model.result("pg8").feature("glob3").setIndex("descr", "Fixed Carrier", 0);
    model.result("pg8").run();

//    In the Model Builder window, under Results, click 1D Plot Group 8.
//    In the Settings window for 1D Plot Group, type Transmission Ratios in the Label text field.

    model.result("pg8").label("Transmission Ratios");

//    Locate the Title section.
//    From the Title type list, select None.

    model.result("pg8").set("titletype", "none");

//    Locate the Plot Settings section.
//    Select the y-axis label checkbox.

    model.result("pg8").set("ylabelactive", true);

//    In the associated text field, type Transmission Ratio.

    model.result("pg8").set("ylabel", "Transmission Ratio");

//    Locate the Style Configuration section.
//    From the Configuration list, select Graph Plot Style 1.

    model.result("pg8").set("styleconfig", "gsty1");

//    In the Transmission Ratios toolbar, click Plot.

    model.result("pg8").run();

//    In the Results toolbar, click 1D Plot Group.

    model.result().create("pg9", "PlotGroup1D");
    model.result("pg9").run();

//    In the Settings window for 1D Plot Group, type Planet Trajectory: Fixed Ring Gear in the Label text field.

    model.result("pg9").label("Planet Trajectory: Fixed Ring Gear");

//    Locate the Title section.
//    From the Title type list, select Label.

    model.result("pg9").set("titletype", "label");

//    Locate the Style Configuration section.
//    From the Configuration list, select Graph Plot Style 1.

    model.result("pg9").set("styleconfig", "gsty1");

//    Right-click Planet Trajectory: Fixed Ring Gear and choose Global.

    model.result("pg9").create("glob1", "Global");
    model.result("pg9").feature("glob1").set("markerpos", "datapoints");
    model.result("pg9").feature("glob1").set("linewidth", "preference");

//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg9").feature("glob1").setIndex("expr", "mbd.hlg3.xcy+mbd.hlg3.v", 0);
    model.result("pg9").feature("glob1").setIndex("descr", "y-coordinate", 0);

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg9").feature("glob1").set("xdata", "expr");

//    In the Expression text field, type mbd.hlg3.xcx+mbd.hlg3.u.

    model.result("pg9").feature("glob1").set("xdataexpr", "mbd.hlg3.xcx+mbd.hlg3.u");

//    Select the Description checkbox.

    model.result("pg9").feature("glob1").set("xdatadescractive", true);

//    In the associated text field, type x-coordinate.

    model.result("pg9").feature("glob1").set("xdatadescr", "x-coordinate");

//    Click to expand the Legends section.
//    Click Override Settings in Style Configuration in the upper-right corner of the Legends section.

    model.result("pg9").feature("glob1").set("overridestyleconfiglegend", true);

//    From the Legends list, select Manual.

    model.result("pg9").feature("glob1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg9").feature("glob1").setIndex("legends", "Center point", 0);

//    Right-click Global 1 and choose Color Expression.

    model.result("pg9").feature("glob1").create("col1", "Color");
    model.result("pg9").run();

//    In the Settings window for Color Expression, locate the Expression section.
//    In the Expression text field, type t.

    model.result("pg9").feature("glob1").feature("col1").set("expr", "t");
    model.result("pg9").run();

//    In the Model Builder window, right-click Planet Trajectory: Fixed Ring Gear and choose Point Graph.

    model.result("pg9").create("ptgr1", "PointGraph");
    model.result("pg9").feature("ptgr1").set("markerpos", "datapoints");
    model.result("pg9").feature("ptgr1").set("linewidth", "preference");

//    In the Model Builder window, click Point Graph 1.
//    Select Point 2536.

    model.result("pg9").feature("ptgr1").selection().set(2536);

//    In the Settings window for Point Graph, locate the y-Axis Data section.
//    In the Expression text field, type y.

    model.result("pg9").feature("ptgr1").set("expr", "y");

//    Locate the x-Axis Data section.
//    From the Parameter list, select Expression.

    model.result("pg9").feature("ptgr1").set("xdata", "expr");

//    In the Expression text field, type x.

    model.result("pg9").feature("ptgr1").set("xdataexpr", "x");

//    Click to expand the Legends section.
//    Click Override Settings in Style Configuration in the upper-right corner of the Legends section.

    model.result("pg9").feature("ptgr1").set("overridestyleconfiglegend", true);

//    Select the Show legends checkbox.

    model.result("pg9").feature("ptgr1").set("legend", true);

//    From the Legends list, select Manual.

    model.result("pg9").feature("ptgr1").set("legendmethod", "manual");

//    In the table, enter the following settings:

    model.result("pg9").feature("ptgr1").setIndex("legends", "Left point", 0);

//    Click to expand the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dashed.

    model.result("pg9").feature("ptgr1").set("linestyle", "dashed");

//    Right-click Point Graph 1 and choose Color Expression.

    model.result("pg9").feature("ptgr1").create("col1", "Color");
    model.result("pg9").run();

//    In the Settings window for Color Expression, locate the Expression section.
//    In the Expression text field, type t.

    model.result("pg9").feature("ptgr1").feature("col1").set("expr", "t");

//    Locate the Coloring and Style section.
//    Clear the Color legend checkbox.

    model.result("pg9").feature("ptgr1").feature("col1").set("colorlegend", false);
    model.result("pg9").run();

//    In the Model Builder window, right-click Results > Planet Trajectory: Fixed Ring Gear > Point Graph 1 and choose Duplicate.

    model.result("pg9").feature().duplicate("ptgr2", "ptgr1");
    model.result("pg9").run();

//    In the Settings window for Point Graph, locate the Selection section.
//    Select the Activate Selection toggle button.
//    Click Clear Selection.

    model.result("pg9").feature("ptgr2").selection().set();

//    Select Point 2821.

    model.result("pg9").feature("ptgr2").selection().set(2821);

//    Locate the Coloring and Style section.
//    Find the Line style subsection.
//    From the Line list, select Dotted.

    model.result("pg9").feature("ptgr2").set("linestyle", "dotted");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg9").feature("ptgr2").setIndex("legends", "Right point", 0);
    model.result("pg9").run();

//    In the Model Builder window, click Planet Trajectory: Fixed Ring Gear.
//    In the Settings window for 1D Plot Group, locate the Axis section.
//    Select the Preserve aspect ratio checkbox.

    model.result("pg9").set("preserveaspect", true);

//    In the Planet Trajectory: Fixed Ring Gear toolbar, click Plot.

    model.result("pg9").run();

//    Right-click Planet Trajectory: Fixed Ring Gear and choose Duplicate.

    model.result().duplicate("pg10", "pg9");
    model.result("pg10").run();

//    In the Settings window for 1D Plot Group, type Planet Trajectory: Fixed Sun Gear in the Label text field.

    model.result("pg10").label("Planet Trajectory: Fixed Sun Gear");

//    Locate the Data section.
//    From the Dataset list, select Study 2: Fixed Sun Gear/Solution 2 (sol2).

    model.result("pg10").set("data", "dset2");
    model.result("pg10").run();

//    In the Model Builder window, expand the Planet Trajectory: Fixed Sun Gear node, then click Global 1.
//    In the Settings window for Global, locate the y-Axis Data section.
//    In the table, enter the following settings:

    model.result("pg10").feature("glob1").setIndex("expr", "mbd.grp6.xcp_pny", 0);

//    Locate the x-Axis Data section.
//    In the Expression text field, type mbd.grp6.xcp_pnx.

    model.result("pg10").feature("glob1").set("xdataexpr", "mbd.grp6.xcp_pnx");

//    Locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg10").feature("glob1").setIndex("legends", "Sun Gear", 0);
    model.result("pg10").run();

//    In the Model Builder window, expand the Global 1 node.
//    Right-click Color Expression 1 and choose Delete.

    model.result("pg10").feature("glob1").feature().remove("col1");
    model.result("pg10").run();
    model.result("pg10").run();

//    In the Model Builder window, under Results > Planet Trajectory: Fixed Sun Gear, click Point Graph 1.
//    In the Settings window for Point Graph, locate the Legends section.
//    In the table, enter the following settings:

    model.result("pg10").feature("ptgr1").setIndex("legends", "Planet Gear", 0);
    model.result("pg10").run();

//    In the Model Builder window, right-click Point Graph 2 and choose Delete.

    model.result("pg10").feature().remove("ptgr2");
    model.result("pg10").run();
    model.result("pg10").run();

//    In the Model Builder window, under Results, click Planet Trajectory: Fixed Sun Gear.
//    In the Planet Trajectory: Fixed Sun Gear toolbar, click Plot.

    model.result("pg10").run();
    model.result("pg9").run();

//    In the Model Builder window, under Results, Ctrl-click to select Planet Trajectory: Fixed Ring Gear, Planet Trajectory: Fixed Sun Gear.
//    Right-click and choose Group.

    return model;
  }

  public static Model run3(Model model) {

    model.nodeGroup().create("grp6", "Results");
    model.nodeGroup("grp6").set("type", "plotgroup");
    model.nodeGroup("grp6").placeAfter("plotgroup", "pg8");
    model.nodeGroup("grp6").add("plotgroup", "pg9");
    model.nodeGroup("grp6").add("plotgroup", "pg10");

//    In the Settings window for Group, type Planet Trajectory in the Label text field.

    model.nodeGroup("grp6").label("Planet Trajectory");

//    In the Results toolbar, click Animation and choose Player.

    model.result().export().create("anim1", "Animation");
    model.result().export("anim1").set("target", "player");
    model.result().export("anim1").set("fontsize", "9");
    model.result().export("anim1").set("colortheme", "globaltheme");
    model.result().export("anim1").set("customcolor", new double[]{1, 1, 1});
    model.result().export("anim1").set("background", "color");
    model.result().export("anim1").set("gltfincludelines", "on");
    model.result().export("anim1").set("title1d", "on");
    model.result().export("anim1").set("legend1d", "on");
    model.result().export("anim1").set("logo1d", "on");
    model.result().export("anim1").set("options1d", "on");
    model.result().export("anim1").set("title2d", "on");
    model.result().export("anim1").set("legend2d", "on");
    model.result().export("anim1").set("logo2d", "on");
    model.result().export("anim1").set("options2d", "off");
    model.result().export("anim1").set("title3d", "on");
    model.result().export("anim1").set("legend3d", "on");
    model.result().export("anim1").set("logo3d", "on");
    model.result().export("anim1").set("options3d", "off");
    model.result().export("anim1").set("axisorientation", "on");
    model.result().export("anim1").set("grid", "on");
    model.result().export("anim1").set("axes1d", "on");
    model.result().export("anim1").set("axes2d", "on");
    model.result().export("anim1").set("showgrid", "on");
    model.result().export("anim1").showFrame();

//    In the Settings window for Animation, type Displacement: Fixed Ring Gear in the Label text field.

    model.result().export("anim1").label("Displacement: Fixed Ring Gear");

//    Locate the Frames section.
//    In the Number of frames text field, type 200.

    model.result().export("anim1").set("maxframes", 200);

//    Right-click Displacement: Fixed Ring Gear and choose Duplicate.

    model.result().export().duplicate("anim2", "anim1");
    model.result().export("anim2").showFrame();

//    In the Settings window for Animation, type Displacement: Fixed Sun Gear in the Label text field.

    model.result().export("anim2").label("Displacement: Fixed Sun Gear");

//    Locate the Scene section.
//    From the Subject list, select Displacement: Fixed Sun Gear.

    model.result().export("anim2").set("plotgroup", "pg3");
    model.result().export("anim1").showFrame();

//    In the Model Builder window, right-click Displacement: Fixed Ring Gear and choose Duplicate.

    model.result().export().duplicate("anim3", "anim1");
    model.result().export("anim3").showFrame();

//    In the Settings window for Animation, type Displacement: Fixed Carrier in the Label text field.

    model.result().export("anim3").label("Displacement: Fixed Carrier");

//    Locate the Scene section.
//    From the Subject list, select Displacement: Fixed Carrier.

    model.result().export("anim3").set("plotgroup", "pg4");
    model.result("pg1").run();

    model.title("Transmission Ratios in a Planetary Gear Train");

    model
         .description("This example showcases a helical planetary gear train composed of a sun gear, ring gear, carrier, and five planet gears. Three cases are analyzed by in turn fixing the ring gear, sun gear, and carrier.\n\nFor each configuration, a transient multibody analysis is performed to determine the angular velocities of all gears under a specified input velocity. The resulting displacements and angular velocities are plotted, and the transmission ratios are compared for the three configurations.");

    return model;
  }

  public static void main(String[] args) {
    Model model = run();
    model = run2(model);
    run3(model);
  }

}
