Nowadays, the generally used automatic spraying machines are only suitable for mass products or components. The usage for multi-type and small-batch products is much limited for its time and labor consuming off-line programming. So this paper present a 3D scanning based 4-axies driving automatic spraying machine to overcome the bottle-neck of programming. By the laser installed under the horizontal slid table of the machine a linear structured light is projected on the surface of the work piece. Besides, two cameras are also symmetrically installed on the side of the laser to acquire the image. The real-time images of the camera are acquired into the computer by the image acquisition board. And then a program will process the images and output the featured point of the work pieces. According to these points, a specially designed algorithm based on the spraying principle will find out the trajectory of the spraying gun. Finally, through the PCI based motion control board, the controlling pulses are sending to the controller of the stepper motor. Then the spraying gun can move along the trajectory to painting the work piece.