A measurement of four branching-fraction ratios for three-body decays of $B$ mesons involving two open-charm hadrons in the final state is presented. Run 1 and Run 2 $pp$ collision data are used, recorded by the LHCb experiment at centre-of-mass energies $7$, $8$, and $13$ TeV and corresponding to an integrated luminosity of $9$ fb$^{-1}$. The measured branching-fraction ratios are [ begin{eqnarray} frac{mathcal{B} (B^+to D^{*+}D^-K^+)}{mathcal{B} (B^+to kern 0.2emoverline{kern -0.2em D}{}^0 D^0 K^+)} &=& 0.517 pm 0.015 pm 0.013 pm 0.011 , frac{mathcal{B} (B^+to D^{*-}D^+K^+)}{mathcal{B} (B^+to kern 0.2emoverline{kern -0.2em D}{}^0 D^0 K^+)} &=& 0.577 pm 0.016 pm 0.013 pm 0.013 , frac{mathcal{B} (B^0to D^{*-}D^0K^+)}{mathcal{B} (B^0to D^- D^0 K^+)} &=& 1.754 pm 0.028 pm 0.016 pm 0.035 , frac{mathcal{B} (B^+to D^{*+}D^-K^+)}{mathcal{B} (B^+to D^{*-}D^+K^+)} &=& 0.907 pm 0.033 pm 0.014 ,end{eqnarray} ] where the first of the uncertainties is statistical, the second systematic, and the third is due to the uncertainties on the $D$-meson branching fractions. These are the most accurate measurements of these ratios to date.