How to access the active (selected) objects through the Blender Python API from scripts/add-ons:
- The active window (in which current action occurs):
1 |
bpy.context.area.spaces.active |
- The active scene:
1 |
bpy.context.screen.scene |
- The active (selected) mesh:
1 |
bpy.context.active_object |
- The active (selected) material node (in the NODE_EDITOR window):
1 |
bpy.context.active_object.active_material.node_tree.nodes.active |
- The active (selected) material node (in the COMPOSITING window):
1 |
bpy.context.scene.node_tree.nodes.active |
- The current text in TEXT_EDITOR window:
1 |
bpy.context.area.spaces.active.text.as_string() |
- The active (selected) UV-Map:
1 |
bpy.context.active_object.data.uv_layers.active |
- Current page in the User Preferences window:
1 |
bpy.context.user_preferences.active_section |
- Current World:
1 |
bpy.context.scene.world |
- Current world node tree (Environment):
1 |
bpy.context.scene.world.node_tree |