The wiring of small mechanical and electrical equipment is one of the bottlenecks in rapid R&D and reliability. The path optimization is the essence of wiring. The paper proposed a new automatic wiring method based on improved A* algorithm, which adapts to three-dimensional path search. The cost for bending and processing was introduced into evaluating function, the rigidity factor was also introduced to improve search efficiency. The wiring module for virtual assembly is developed by UG API implementation. The results show that the method is effective.