Unstructured mesh h-re nement replaces an existing element with a set of smaller child elements to improve the local resolution. A template can be used to create the child elements from the original nodes of the parent element and any new nodes that are introduced at edge, face, or element centers. Homogeneous re nement results when all the edges of the element are split and the child elements are typically of the same type as the parent. A transition re nement element is required to interface the homogeneously re ned element with the surrounding unre ned elements. The number of possible transition re nement templates is very large and typically only a fraction of the possible templates are implemented. The present e ort automates the process of generating the transition element templates through the use of metaprogramming: one program will generate the templates and write out software to be compiled into the actual mesh re nement code. The current approach is described in detail and demonstrated on three di erent test cases. The rst is re nement of all elements within a bounding box as might be used to improve local solution accuracy. The second case is re nement to eliminate orphans in an overset mesh system when the overlap between the meshes is insu cient to provide quality interpolation sources. The nal test case combines re nement to eliminate orphans with re nement to improve local solution accuracy. The current procedure generates over 900 unique templates that expands to over 12,000 possible combinations of transition re nement templates.