The invention relates to the technical field of electric and electronic, and specifically relates to a visual programming method and system for a motor controller. The visual programming method for a motor controller includes the steps: visually compiling a program off-line, writing the off-line compiled program into a memory region of a controller, and operating the program written into the memory region of the controller, wherein visually compiling the program off-line includes the steps: opening the visual programming software, loading a configuration file into the memory, performing program editing, saving the program into a dynamic array, and saving the dynamic array as the first customize file. The visual programming method and system for a motor controller can realize on-line programming, debugging and single command execution, thus being convenient for program designing and debugging for the staff, and can also realize the off-line operation function, so that the staff can write the logical program flow of the application scene into the controller and disconnects communication with a host computer after saving and through power up execution or state change of I/O to trigger and stop the program so as to be suitable for some simple or fixed logical application scenes conveniently.