We formulate a general and exact method of partial-wave decomposition (PWD) of any nucleon-nucleon (NN) potential and any three-nucleon (3N) force. The approach allows one to efficiently use symbolic algebra software to generate the interaction-dependent part of the program code calculating the interaction. We demonstrate the feasibility of this approach for the one-boson exchange BonnB potential, a recent nucleon-nucleon chiral force and the chiral two-pion-exchange three-nucleon force. In all cases very good agreement between the new and the traditional PWD is found. The automated PWD offered by the new approach is of the utmost importance in view of future applications of numerous chiral N3LO contributions to the 3N force in three-nucleon calculations.