Arcpy.mp to select layout elements?

250
6
06-13-2018 02:14 PM
CharlesBailey3
Occasional Contributor

Is there a way in Python 3.x to programmatically select a layout element, such as a scale bar? Thanks much, cob

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

they give an example of moving a scalebar in this tutorial

Create a map book with Python—ArcGIS Pro | ArcGIS Desktop 

CharlesBailey3
Occasional Contributor

Thanks Dan,  but it is actually never selected in that example, just repositioned. I can set the map frame as well, but there must be a programmatic way to select the element, so that when I open the properties page with a task step it pertains to the selected element? 

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Charles, you will need to sniff around in the arcpy section for other examples of **element things.

For example

MapsurroundElement—ArcPy | ArcGIS Desktop 

but it requires you know the element name

0 Kudos
CharlesBailey3
Occasional Contributor

Yes I know the name - I can set the map frame and do all sorts of things to the elements, but can't figure out how to select one. I also don't see how to add items to the Legend_Element but I think this is another bug issue. Thanks,  cob

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

My read is that when 'select' an element of any kind by name or index number... it is selected/active/??? and you should be able to work with it.  It may be that the mp module expects to be used to modify existing things, and your case of adding to the legend element would probably necessitate going back to the beginning with adding a layer and symbolizing it from scratch... I don't use it enough.. most of my mapping uses a template structure 

0 Kudos
CharlesBailey3
Occasional Contributor

If it is ever selected, it doesn't stay in the selected state once the script completes. I was looking for a way to set this state in the code - I would think 'select' would be something that would apply to existing objects(?) As far as the Legend goes, it's pretty flaky. If you programmatically set the map frame, it works in the properties but does not add any layers from the frame to the existing legend. But if you add just one layer to the legend manually (drag it in the TOC) when the frame is set to None, then when you set the map frame all of the layers in the frame are added. I'm just trying to persist the settings of these elements with the user's content. There may be a better way but I haven't found it (?) Thanks Dan - cob