To provide optimal depth resolution with a coded-aperture Laue diffraction microscope, an accurate position of the coded-aperture and its scanning geometry need to be known. However, finding the geometry by trial and error is a time-consuming and often challenging process because of the large number of parameters involved. In this paper, we propose an optimization approach to automate the focusing process after data is collected. We demonstrate the robustness and efficiency of the proposed approach with experimental data taken at a synchrotron facility.