AnsweredAssumed Answered

Problems creating a Feature Template for a Standalone Table

Question asked by john.reed.404 on May 11, 2018
Latest reply on May 31, 2018 by sean_jones-esristaff

I have searched around, but have not found any information on this topic.

I want to create a template for a stand alone table so I can add it as a related record on a new feature template.

To try to figure out how to do this I created what I wanted manually and examined the underlying objects. Then duplicated that, but with different names.

The problem I am seeing is that the template for the standalone table is created, but it does not show up on the relationships tab of the feature template or in manage templates for the stand alone table. If I reload the templates from the layer in code it is in the array of templates along with the ones I created manually that do show up. It is like it is not visible.

Here is some sample code that might better clarify what I am trying to do. I have tried setting or not setting all the various parameters with the same results. The parameters below, except for the name, are what are set on the template that works, the one created manually.

            var map = ArcGIS.Desktop.Mapping.MapView.Active.Map;

            var featLayer = map.FindLayers("Point").First();
            var unitLayer = map.FindStandaloneTables("Unit").First();
            var unitDef = unitLayer.GetDefinition() as CIMStandaloneTable;
            var unitTemplates = unitDef.RowTemplates.ToList();
            var layerDef = featLayer.GetDefinition() as CIMFeatureLayer;
            //you can't create custom templates if auto generate is true for the layer
            if (layerDef.AutoGenerateFeatureTemplates)
                layerDef.AutoGenerateFeatureTemplates = false;
            var layerTemplates = layerDef.FeatureTemplates.ToList();

            //Create a template with a related record
            CIMFeatureTemplate resTempDef = new CIMFeatureTemplate();
            resTempDef.Name = "Type A";
            resTempDef.Description = "This is the description for the template";
            resTempDef.WriteTags(new[] { "Electric" });
            resTempDef.DefaultValues = new Dictionary<string, object>();
            resTempDef.DefaultValues.Add("a", "1");
            resTempDef.DefaultValues.Add("b", "0");
            resTempDef.DefaultValues.Add("c", DateTime.Now);
            resTempDef.RequiredFields = new string[] { "a" };
            resTempDef.HiddenFields = new string[] { "c" };

            if (!TemplateExists(unitTemplates, "Unit B"))
                if (unitDef.AutoGenerateRowTemplates)
                    unitDef.AutoGenerateRowTemplates = false;
                var unitb = new CIMFeatureTemplate();
                unitb.Name = "Unit B";
                unitb.Description = String.Empty;
                unitb.WriteTags(new[] { "Table" });

                unitb.DefaultValues = new Dictionary<string, object>();
                unitb.DefaultValues.Add("B", "This is B");
                unitb.ToolProgID = "00000000-0000-0000-0000-000000000000";
                unitDef.RowTemplates = unitTemplates.ToArray();
            CIMEditingTemplateRelationship rel = new CIMEditingTemplateRelationship();
            rel.Name = "Unit B";
            rel.TableURI = unitLayer.URI;
            rel.RelationshipID = 7;

            resTempDef.Relationships = new CIMEditingTemplateRelationship[] { rel };

            layerDef.FeatureTemplates = layerTemplates.ToArray();
            //commit changes back to layer