Select to view content in your preferred language

Inspector for Editing Template returns null

1470
5
05-03-2021 04:07 PM
SteveMilligan
Emerging Contributor

I am having an issue with the inspector for an editing template returning null.

I have a list of features that I need create. I iterate over the list of features and get the FeatureTemplate for each. I then call the ActivateDefaultToolAsync method on the FeatureTemplate to make sure that it is initialized. After that, I check for the FeatureTemplate.Inspector being null and if not I will set the feature attributes. This works most of the time, but sometimes, the Inspector is null and I have no way to set the attributes on the feature. This will happen even though the exact same featuresTemplates have all ready been created.

What could be causing the seemingly random null inspector?

ArcPro 2.6.4

 

0 Kudos
5 Replies
NarelleChedzey
Esri Contributor

Hi Steve, 

 

For performance reasons, the Inspector object belonging to a template is only initialized when that template is made the active template  (this is achieved by activating a tool on that template),  

 

Have you noticed if it is the same template that is causing problems or does it appear to be random?

 

Can you also post a sample of the code that you're using. 

 

Thanks

Narelle

0 Kudos
SteveMilligan
Emerging Contributor

Hey Narelle,

Thanks for taking the time to respond.  It seems like it is the randomly the next time that the template ActivateDefaultToolAsync is called. I have not completely tracked it down to the second or third time for example. But usually, if I am inserting more than one instance of the same template inspector it will come back as null at least once. 


Here is my pseudo code snippet: Executed a QueuedTask.Run()

foreach(MyFeatureToInsert feature in featuresToInsert)
{
    List<EditingTemplate> editingTemplates = GetEditingTemplates(feature.layerName, feature.assetGroup, feature.assetType);

    featureTemplate = editingTemplates.FirstOrDefault(my lambda here));

    if (featureTemplate != null)
    {

    if (featureTemplate.Inspector == null)
    {
        featureTemplate.ActivateDefaultToolAsync(); 
    }

    if (featureTemplate.Inspector != null)
    {
        SetAttributeValues(feature, featureTemplate.Inspector, assetType.Code);
    }
   }
}

0 Kudos
NarelleChedzey
Esri Contributor

Steve, 

 

Try awaiting the ActivateDefaultToolAsync method.   This means that the code following that line won't execute until the ActivateDefaultToolAsync method has completed. 

 

something similar to this

await QueuedTask.Run(async () =>
{
  // get editing templates

  featureTemplate = editingTemplates.FirstOrDefault(my lambda here));
  if (featureTemplate != null)
  {
    if (featureTemplate.Inspector == null)
    {
      await featureTemplate.ActivateDefaultToolAsync(); 
    }
    if (featureTemplate.Inspector != null)
    {
      SetAttributeValues(feature, featureTemplate.Inspector, assetType.Code);
    }
  }
});

 

0 Kudos
SteveMilligan
Emerging Contributor

Hey Narelle,

 I am just getting back to looking into this.  I am trying to insert a group template. I using the following code. Again the inspector is coming back null.  Is there something I missing?  

private async Task AddPointsAsync()
{
    string layerName = "Structure Junction";

    try
    {
        Layer l = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(ly => ly.Name == layerName);

        if (l == null) 
            return;
        
        await QueuedTask.Run(async () =>
        {                
            var centerPt = MapView.Active.Extent.Center;

            List<EditingTemplate> editingTemplates = l.GetTemplates().ToList();

            if (editingTemplates == null)
                throw new ApplicationException("Could not find editing templates");

            EditingTemplate featureTemplate = null;
            EditingGroupTemplate editingGroupTemplate = null;

            string templateName = "Wire Vault 4x3 6x9ft"; // custom template - this is a Editing Template that contains a Structure Junction and Structure Boundary            

            editingGroupTemplate = editingTemplates.FirstOrDefault(x => x.Name.Equals(templateName, StringComparison.InvariantCultureIgnoreCase)) as EditingGroupTemplate;

            if (editingGroupTemplate == null)
            {
                throw new ApplicationException("Feature Template could not be found");
            }

            if (editingGroupTemplate != null && centerPt != null)
            {
                if (editingGroupTemplate.Inspector == null)
                {
                    await editingGroupTemplate.ActivateDefaultToolAsync();

                    if (editingGroupTemplate.Inspector == null)
                    {
                        throw new ApplicationException("FeatureTemplate.Inspector was null.");
                    }
                }
                try
                {
                    // Create the feature
                    // 
                    EditOperation editOperation = new EditOperation();
                    RowToken token = editOperation.CreateEx(featureTemplate, centerPt);
                    if (editOperation.Execute())
                    {
                        MessageBox.Show(token.ObjectID.ToString());
                    }
                }
                catch
                {

                }
            }
        });
    }
    catch (Exception ex)
    {
        MessageBox.Show($@"Error: {ex.ToString()}");
    }
}

 

0 Kudos
VidmasKondratas
Esri Contributor

I'm having the exact same problem described in the original post at ArcGIS Pro 2.9.5 right now. Any updates with this issue? It's very wonky behavior and seems like a bug. I call GetDefinition() the first time it return the object. Subsequent calls return null. If I call GetDefinition() in another part of the code afterward in another method it returns the object again. Activating the default tool with await async first doesn't fix the issue. This behavior only occurs with specific ArcGIS Server feature layers but I can't see any difference with these particular layers versus other layers where this is not an issue.

 

 

CIMEditingTemplate iceLineTemplateDef = template.GetDefinition();

 

 

 

0 Kudos