I can use CreateGraphicElements to add lines, points and polygons to my layout and performance is great (creating 100 line graphics using CreateGraphicElements takes 0.753 seconds).
Adding 100 text graphics using the same CreateGraphicElements call and structure takes over 25 seconds - performance that is 30x slower than a non-text, geometric graphic (point, line poly). That's something special and not in a good way 😞
Is there some secret to adding a CIMTextGraphic to a layout where I could get performance similar to adding a CIMLineGraphic, CIMPointGraphic, etc?
Here's the test code that I have been working with:
Layout layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault()?.GetLayout();
GroupElement groupElement1 = LayoutElementFactory.Instance.CreateGroupElement(layout);
CIMElement cimGroupElement = groupElement1.GetDefinition();
cimGroupElement.Name = "Group Element Test - Lines";
groupElement1.SetDefinition(cimGroupElement);
//Creating a GroupElement that only consists of line graphics
var graphics = new List<CIMGraphic>();
var names = new List<string>();
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);
graphics.Add(new CIMLineGraphic() { Line = polylineTic, Symbol = new CIMSymbolReference() { Symbol = lineSym } });
names.Add($"Line{i}");
}
//Following line takes 0.75 seconds to execute
LayoutElementFactory.Instance.CreateGraphicElements(groupElement1, graphics.ToArray(), names.ToArray());
//Creating a GroupElement that only consists of text graphics
GroupElement groupElement2 = LayoutElementFactory.Instance.CreateGroupElement(layout);
CIMElement cimGroupElement2 = groupElement2.GetDefinition();
cimGroupElement2.Name = "Group Element Test - Text";
groupElement2.SetDefinition(cimGroupElement2);
graphics = new List<CIMGraphic>();
names = new List<string>();
for (int i = 0; i < 100; i++)
{
graphics.Add(new CIMTextGraphic() { Shape = new Coordinate2D { X = i, Y = i }, Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 6, "Arial Narrow", "Regular") }, Text = i.ToString() });
names.Add($"Point{i}");
}
//Following line takes > 25 seconds to execute; same usage as above, only difference is the graphics list now contains CIMTextGraphic objects instead of CIMLineGraphic objects
LayoutElementFactory.Instance.CreateGraphicElements(groupElement2, graphics.ToArray(), names.ToArray());
There is another thread that deals with the degradation of performance when adding elements in multiple nested GroupElements, but in this situation I am using CIMTextGraphic and I am not nesting.
Solved! Go to Solution.
Hello, "TheBobScript"
I tried to reproduce your code in 2.9 and 3.0 and was uncesscessful. When I run your code above, everything gets created in less than a second. There was a compile error with your sample above. I made a very slight modification to make it work. I have no idea if that is the difference. If you have different or more complete code, it may be necessary to reproduce the issue.
Here is the code modification I used to replace your lines 30-34 above.
for (int i = 0; i < 100; i++)
{
MapPoint mapPt = MapPointBuilderEx.CreateMapPoint(i, i);
graphics.Add(new CIMTextGraphic() { Shape = mapPt, Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 6, "Arial Narrow", "Regular") }, Text = i.ToString() });
names.Add($"Point{i}");
}
Jeff - Layout and arcpy.mp teams
Hello, "TheBobScript"
I tried to reproduce your code in 2.9 and 3.0 and was uncesscessful. When I run your code above, everything gets created in less than a second. There was a compile error with your sample above. I made a very slight modification to make it work. I have no idea if that is the difference. If you have different or more complete code, it may be necessary to reproduce the issue.
Here is the code modification I used to replace your lines 30-34 above.
for (int i = 0; i < 100; i++)
{
MapPoint mapPt = MapPointBuilderEx.CreateMapPoint(i, i);
graphics.Add(new CIMTextGraphic() { Shape = mapPt, Symbol = new CIMSymbolReference() { Symbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 6, "Arial Narrow", "Regular") }, Text = i.ToString() });
names.Add($"Point{i}");
}
Jeff - Layout and arcpy.mp teams
Hi Jeff. I appreciate the response and correction.
After creating my post, I have had other end users install and use my Add-in in a 2.9.X environment (I have been developing in 2.8.X). They are not reporting the same experience as you are - performance is ideal and there's no perceptible lag. I'm going to assume the world will become a better place for me when I upgrade to 2.9.
Thanks again,
Bob