Automatic custom pattern generation using the developed and optimized grading method