Designing the layout for complex electromechanical products involves the challenging task of automatically laying out cables. This challenge is particularly pronounced in the case of branch cables, which are more intricate due to their multiple connection terminals and branches. This paper presents a polynomial-time wiring algorithm based on dynamic programming to determine branching point locations in the layout design of cables, given the electrical definition of the wire harness. The method considers various engineering constraints, including obstacle avoidance, wall adherence, minimum bend radius, and gray areas. To validate our method, we implemented a branch cable auto-layout system through secondary development based on the UG platform. The experimental results indicate the effectiveness of our approach, demonstrating promising performance in terms of time and high-quality layouts. This showcases its potential for practical application in cable layout design for complex electromechanical systems.