The optimal design regarding energy efficiency of hybrid and electric drivetrains is a problem that includes topology generation, topology optimization, component sizing, and control. One of the challenges of this design problem is that the topology defines the plant sizing and control parameters. Furthermore, the topology also determines the transmission model that is needed for the evaluation of the sizing and control problems. To enable automated component sizing and control optimization, a novel method is presented in this paper for the automated dynamic modeling of arbitrary hybrid and electric drivetrain topologies. In this paper, topologies are modeled at the level of (planetary) gears and clutches, making the method suitable for complex and unconventional drivetrain topologies. A generic transmission model is defined, for which the model parameters are automatically determined. The parameter determination is based on the analytic evaluation of the kinematic and kinetic properties of the components of the topology. All transmission modes are identified and classified, and infeasible and redundant modes are automatically excluded. As the method is analytic, the computation time to determine the model parameters is short (less than a second). The model, in this case, provides the rotational speeds and torques of all power sources as a function of the rotational speed and torque at the wheels, and the control variables. Using a case study, it is shown that the method can be used to automatically solve the control and sizing problems for complex drivetrain topologies.