# Set active UV layer in python?

I'd like to set which UV map is selected in Properties > Object Data > UV Maps. By "selected", I'm referring to the one highlighted, not the one with the camera icon enabled.

I tried

bpy.context.object.data.uv_layers.active = bpy.context.object.data.uv_layers['AO']


But uv_layers.active remained at the previous value and there was no error message.

How can I set the active UV map from python?

• This technique also comes in handy when you are trying to prepare a mesh for texture baking, since the active UV layer seems to be important to the baking process. – Mutant Bob Aug 22 '17 at 3:10

Seems that you can set the active UV layer through the uv_textures collection rather than uv_layers:
bpy.context.object.data.uv_textures['AO'].active = True
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3279203176498413, "perplexity": 2741.8561194206363}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-05/segments/1579251690095.81/warc/CC-MAIN-20200126165718-20200126195718-00416.warc.gz"}