Inspector for Editing Template returns null

268
3
05-03-2021 04:07 PM
SteveMilligan
New 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
3 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
New 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