Select to view content in your preferred language

ArcGIS Pro 3.1 Layout GroupElements are broken

417
1
Jump to solution
06-22-2023 07:58 AM
marco_vertigis
New Contributor III

In 2.9/net48 we have some code were we create a GroupElement first and then create some further elements afterwards which have the GroupElement as their container. All this child elements got this GroupElement as their parent. In 3.1 SDK this behaviour seems to be broken or atleast it has changed.

In 3.1 SDK it seems that all ParentElements get nulled if another element is created within that group. That probably leads to many NullPointerExceptions which we got now after upgrading to 3.1. This behaviour is event watchable when assigning the child elements straight up when calling the CreateGroupElement.

 

var group1 = ElementFactory.Instance.CreateGroupElement(layout, new List<Element> (), "group1");

var test1 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap);
// test1.GetParent() > group1 
test1.SetHeight(100.0); // > works
var test2 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap);
// test1.GetParent() > null
// test2.GetParent() > group1
test1.SetHeight(100.0); // > NullPointerException
test2.SetHeight(100.0); // > works

var test3 = ElementFactory.Instance.CreateMapFrameElement(layout, frameBounds, templateMap);
var test4 = ElementFactory.Instance.CreateMapFrameElement(layout, frameBounds, templateMap);
var group2 = ElementFactory.Instance.CreateGroupElement(layout, new List<Element> { test3, test4 }, "group2");
// test3.GetParent() > null
// test4.GetParent() > null
test3.SetHeight(100.0); // > NullPointerException
test4.SetHeight(100.0); // > NullPointerException

 

 

There were alot of changes to the Element-/Layout factories. Many code snippets just went broke as soon as we updated to 3.1 and ran totally fine pre 3.x.

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hello, 

Thanks for your post.  I am able to duplicate your issues at 3.1. I have logged an issue with the Layout team for this bug to be fixed.

 

Here is a work around for this bug.  If you are able to  name your elements when creating them, you can call Layout.FindElement   (https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic29299.html)  using that name before you need to reference the element.  Doing this, you will find that the object is populated correctly and no null reference exceptions should be thrown. 

For example, here is your code with the first mapFrame element correctly showing the parent after the second map frame has been created. 

var group1 = ElementFactory.Instance.CreateGroupElement(layout, new List<Element>(), "group1");

var test1 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap, "MF1");
var parent = test1.GetParent(); //  > group1 
test1.SetHeight(100.0); // > works

var test2 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap, "MF2");
parent = test1.GetParent(); //  > null 
parent = test2.GetParent(); //  > group1

// re-get the element
test1 = layout.FindElement("MF1") as MapFrame;
parent = test1.GetParent();   // group1
test1.SetHeight(100.0); // > works

 

 

Thanks

Narelle

View solution in original post

1 Reply
NarelleChedzey
Esri Contributor

Hello, 

Thanks for your post.  I am able to duplicate your issues at 3.1. I have logged an issue with the Layout team for this bug to be fixed.

 

Here is a work around for this bug.  If you are able to  name your elements when creating them, you can call Layout.FindElement   (https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic29299.html)  using that name before you need to reference the element.  Doing this, you will find that the object is populated correctly and no null reference exceptions should be thrown. 

For example, here is your code with the first mapFrame element correctly showing the parent after the second map frame has been created. 

var group1 = ElementFactory.Instance.CreateGroupElement(layout, new List<Element>(), "group1");

var test1 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap, "MF1");
var parent = test1.GetParent(); //  > group1 
test1.SetHeight(100.0); // > works

var test2 = ElementFactory.Instance.CreateMapFrameElement(group1, frameBounds, templateMap, "MF2");
parent = test1.GetParent(); //  > null 
parent = test2.GetParent(); //  > group1

// re-get the element
test1 = layout.FindElement("MF1") as MapFrame;
parent = test1.GetParent();   // group1
test1.SetHeight(100.0); // > works

 

 

Thanks

Narelle