The aim of this paper is to find a new expression for distance-based graph invariants of connected graphs having a decomposition into convex subgraphs. We apply this method to Schultz and Gutman indices of graphs. It can be generalized to other distance-based graph invariants. As an application, the Wiener index of the one-pentagonal nanocone is computed.