Problems creating a Feature Template for a Standalone Table

735
4
05-11-2018 02:13 PM
JohnReed1
New Contributor II

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";
                unitTemplates.Add(unitb);
                unitDef.RowTemplates = unitTemplates.ToArray();
                unitLayer.SetDefinition(unitDef);
            }
            CIMEditingTemplateRelationship rel = new CIMEditingTemplateRelationship();
            rel.Name = "Unit B";
            rel.TableURI = unitLayer.URI;
            rel.RelationshipID = 7;

            resTempDef.Relationships = new CIMEditingTemplateRelationship[] { rel };
            layerTemplates.Add(resTempDef);

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

0 Kudos
4 Replies
JohnReed1
New Contributor II

Forgot to mention this is ArcGIS Pro 2.1.2

0 Kudos
by Anonymous User
Not applicable

John,

The code looks correct but the rel.RelationshipID has to be set to the class ID of the relationship class in the GDB. You cant get this value from the public api at this time. We'll try to get that in for 2.3.

0 Kudos
JohnReed1
New Contributor II

Hi Sean

What about just creating a template for a stand alone table? I can create one in ArcGIS Pro manually and see it programmatically, but when I try to create one programmatically it is not visible in the manage templates like the ones I created manually are. However, if I look at the layer again programmatically, the programmatically created template is there, it is just not visible in the UI.

0 Kudos
by Anonymous User
Not applicable

Hi John,

The UI issue is another bug that were looking into. The template is created, as you know, but isn't visible until saving and reloading the project.

0 Kudos