Page elements such as a scalebar can be converted to a collection of elements (rectangles, texts, ...), using element.ConvertToGraphics().
However, this is applied directly to the element on the layout, and after being converted, the scalebar does no longer have a connection to the map.
Is there a way to get the subelements of an element without altering the element itself? Can I for instance clone the element in memory? Or clone the entire layout, and delete the copy afterwards?
Perhaps "Clone"?
var lv = LayoutView.Active;
var layout = lv?.Layout;
if (layout == null) return;
QueuedTask.Run(() =>
{
var sel_elems = lv.GetSelectedElements()
.OfType<GraphicElement>()?.ToList() ??
new List<GraphicElement>();
foreach(var elem in sel_elems)
{
var ge_clones = elem.Clone("Cloned_").ConvertToGraphics();
if (ge_clones != null)
{
foreach(var ge_clone in ge_clones)
{
//TO DO - something with the converted elements
//...