If I create a group at the layout level and then create elements in that group then all OK.
When creating a named group within a group - elements are not correctly placed in the named group - they are placed directly on the layout instead. If I don't set the name then all OK.
Layout layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault()?.GetLayout();
GroupElement groupElement = LayoutElementFactory.Instance.CreateGroupElement(layout);
CIMElement cimGroupElement = groupElement.GetDefinition();
cimGroupElement.Name = "First Level Group";
groupElement.SetDefinition(cimGroupElement);
GroupElement groupElement2 = LayoutElementFactory.Instance.CreateGroupElement(groupElement);
CIMElement cimGroupElement2 = groupElement2.GetDefinition();
cimGroupElement2.Name = "Second Level Group";
groupElement2.SetDefinition(cimGroupElement2);
for (int i = 0; i < 100; i++)
{
List<Coordinate2D> lineCoordinates = new List<Coordinate2D> { new Coordinate2D { X = i, Y = 0 }, new Coordinate2D { X = i, Y = 100 } };
Polyline polylineTic = PolylineBuilder.CreatePolyline(lineCoordinates);
CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1.0, SimpleLineStyle.Solid);
GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(groupElement2, polylineTic, lineSym);
CIMElement cimElement = lineElm.GetDefinition();
cimElement.Name = "Line" + i;
lineElm.SetDefinition(cimElement);
}
Adam
Adam,
I really appreciate you reporting this! I've reproduced the bad behavior on Pro 2.4 and noticed that if the same command is used in Pro 2.5, a crash will occur. This is a regression and will be fixed immediately in 2.6 and hopefully added to a 2.5 patch.
I noticed the issue still occurs if I use SetName() vs changing the element name via the CIM.
Jeff - Layout Team
Hi Jeff,
Great to hear. I did actually manage to find a magic combination that gets it to work but it was hours of trial and error. It was to use SetName and then change another property using get/set definition.
Adam
This issue was addressed for Pro 2.7
Jeff - arcpy.mp/Layout SDK teams