This is a toolbar created to create mapunitpoly templates. Is there a reason that other values beside the defaults don't save? Also I have a problem when editing that some of the templates get deleted and can't be recovered. Is there anyway to stop this from happening?
public static void UpdateMapUnitPolysFeatureTemplates(IWorkspace theWorkspace)
{
// Get the MapUnitPolys Layer from the ToC
IFeatureLayer theLayer = commonFunctions.FindFeatureLayer(theWorkspace, "MapUnitPolys");
// If the layer was not found, don't try and update the templates!
if (theLayer == null) { return; }
// Get a reference to the template editor, remove current templates
IEditor3 templateEditor = (IEditor3)ArcMap.Editor;
templateEditor.RemoveAllTemplatesInLayer((ILayer)theLayer);
// Get the DMU entries
var sortedDmu = GetDmuSortedByHierarchy(theWorkspace);
// Loop through the DMU, add templates to an array
IArray templateArray = new ArrayClass();
foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> anEntry in sortedDmu)
{
// Get this DMU entry
DescriptionOfMapUnitsAccess.DescriptionOfMapUnit dmuEntry = anEntry.Value;
// Build the template if this is not a heading
if (dmuEntry.ParagraphStyle.Contains("Heading") == true) { continue; }
IEditTemplateFactory templateFactory = new EditTemplateFactoryClass();
IEditTemplate newTemplate = templateFactory.Create(dmuEntry.MapUnit + " - " + dmuEntry.Name, (ILayer)theLayer);
// Set the Template's default values
newTemplate.SetDefaultValue("MapUnit", dmuEntry.MapUnit, false);
newTemplate.SetDefaultValue("Label", dmuEntry.Label, false);
newTemplate.SetDefaultValue("IdentityConfidence", "certain", false);
// Add the template to the array
templateArray.Add(newTemplate);
}