We describe a tool to analyze the effects of gravity induced deflections on a telescope structure with segmented primary mirror optics. An objective of the telescope structural design process is to minimize image quality degradation due to uncorrectable static deflections of the optics under gravity, while ensuring that the overall system meets several requirements including limits of maximum primary mirror actuator stroke, segment rotation and decenter, and secondary mirror actuation. These design and performance criteria are not readily calculated within a finite element program. Our Merit Function routine, implemented in MATLAB and called by ANSYS, calculates these parameters and makes them available within ANSYS for evaluation and design optimization. In this analysis, ANSYS outputs key structural-model nodal displacements to a file, which are used to determine the 6 degree of freedom motion of the telescope's optical surfaces. MATLAB then utilizes these displacements, along with a database containing coordinate system transforms and a linear optics model derived from ZEMAX, to calculate various performance criteria. The values returned to ANSYS can be used to iteratively optimize performance over a set of structural design parameters. Optical parameters calculated by this routine include the optical path difference at the pupil, RMS wavefront, encircled energy and low order Zernike terms resulting from primary mirror segment rotation and decenter. Also reported are the maximum actuator strokes required to restore tip-tilt and piston of the primary mirror segments, and the deflection of the secondary mirror under gravitational load. The merit function routine is being used by the Thirty Meter Telescope (TMT) project to optimize and assess the performance of various telescope structural designs. This paper describes the mathematical basis of the calculations, their implementation and gives preliminary results of the TMT Telescope Structure Reference Design.