set map as active

176
3
12-09-2021 07:25 AM
StuartMoore
Occasional Contributor III

so i have a project with 3 maps and layout, i have some code that exports the layout which uses two of the maps, the third map is used to select some features and then export it to a DXF file, this all works fine if the DXF map is selected before you run the code, if not it errors saying the DXF export can't find one of the layers

so how can i set the DXF export map as the code is ran

i've tried a few things but nothing works 

m = aprx.listMaps('CAD_EXPORT')[0]
m.active()

m.enabled()

thanks

 

0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor

arcpy.mp doc on the Map object says:

Note: arcpy.mp does not provide access to map views within the application; it only provides access to MapFrames.

So I'm not sure this is possible from arcpy.mp - hopefully someone else will chime in soon.

Your solution may be to provide an error message to tell the user to select the correct map before running the tool. Better yet, do this in the parameter validation to keep the user from running the tool when the wrong map is active.

0 Kudos
StuartMoore
Occasional Contributor III

one work around would be to check the map before it ran and then give an error if its not the correct one but the user running the script would then need to notice it and not assume its ran and that there was nothing to export 

0 Kudos
curtvprice
MVP Esteemed Contributor

If you use parameter validation, the user would not need to notice - the tool would not run and would give them a reminder why it won't run.

0 Kudos