In brief
- Create a new light data block and scene object, then link them to the active collection.
- Use the bpy API to set an object’s location, select it, and make it active.
- Inspect mesh surfaces through polygon and loop data, and match UV data using the same loop indices.
- Use collections to organize direct objects and child collections.
What will you learn in this tutorial?
This short exercise covers workflows for creating scene objects and reading existing mesh data with Blender’s Python API. First, we’ll create a data block and object for a point light, then link it to the active collection in the scene, position it, and make it active. In the second section, we’ll inspect the polygons, vertices, and UV coordinates of the selected mesh. Finally, we’ll see how to access the objects directly inside a collection.
This approach is a starting point for handling repetitive editing or checking tasks in architectural modeling and visualization scenes with Python. The examples are based on the Object, Mesh, and Collection types defined in Blender’s official API documentation. They are exercises in creating and reading scene data with scripts—not a recipe for producing a model.
Requirements and version information
You’ll need Blender and its Python API (bpy). The source documents are the current API pages, but they don’t specify a particular Blender version number. As a result, the sources don’t confirm a minimum version for the examples below; check that the relevant API features are available in your Blender installation. The documentation also does not state an account requirement.
The mesh UV example requires an active mesh object in the scene and an active UV layer on that mesh. Run the code snippets in Blender’s Python environment. Before running each snippet, make sure the active object and active collection are the ones you expect.
Step by step: add a light to the scene
The first step is to create a data block that defines the light itself. Then we create an object that uses this data. This distinction helps illustrate the relationship between an object and the data it carries in Blender. The example below links the new light to the active collection in the active view layer.
import bpy
view_layer = bpy.context.view_layer
light_data = bpy.data.lights.new(
name="Calisma Nokta Isigi",
type='POINT'
)
light_object = bpy.data.objects.new(
name="Calisma Nokta Isigi",
object_data=light_data
)
view_layer.active_layer_collection.collection.objects.link(light_object)
light_object.location = (5.0, 5.0, 5.0)
light_object.select_set(True)
view_layer.objects.active = light_objectThe code creates point-light data with bpy.data.lights.new and a scene object with bpy.data.objects.new. It then links the object to the active layer collection, sets its location, selects it, and makes it the active object in the view layer. The location values are example coordinates; adjust them to suit the project’s scale and scene layout. This code does not describe a real architectural lighting setup or render settings.
Running the script again may create new items with the same names. It’s good practice to inspect the results before rerunning it in a scene and to work in a test file. The source example also creates the light data block and object separately, then links them to the active collection.
Step by step: read mesh and UV data
The next snippet checks whether the active object is a mesh and whether it has an active UV layer. It then loops through the polygons and prints each polygon’s vertex index and UV coordinates from its vertex loops. According to the mesh documentation, polygons refer to loop ranges rather than storing their surface vertices directly. The data in a UV layer is also matched to these loop indices.
import bpy
obj = bpy.context.object
if obj is None or obj.type != 'MESH':
raise RuntimeError("Etkin nesne bir mesh olmalı.")
mesh = obj.data
uv_layer = mesh.uv_layers.active
if uv_layer is None:
raise RuntimeError("Mesh üzerinde etkin UV katmanı bulunamadı.")
for polygon in mesh.polygons:
print("Poligon:", polygon.index, "Köşe sayısı:", polygon.loop_total)
for loop_index in polygon.loop_indices:
vertex_index = mesh.loops[loop_index].vertex_index
uv = uv_layer.data[loop_index].uv
print("Köşe:", vertex_index, "UV:", tuple(uv))First, make the mesh object active; otherwise, the check will raise an error. The code also stops if there’s no UV layer. This makes missing data visible instead of silently producing misleading output. The snippet doesn’t edit the UV coordinates; it only prints the existing mappings to the console. Checking whether the UVs are correct or the resulting texture looks good is beyond the scope of this script.
The Mesh API represents geometry through vertices, edges, loops, and polygons. The source documentation also explains that UV and color data are aligned with the loop arrays. So, to find the UV data for a surface vertex, follow the relevant loop index rather than relying only on the polygon index.
Step by step: list objects in a collection
Collections group scene items. The example below lists the objects directly contained in the active layer collection. The objects property returns a collection’s direct objects, while all_objects includes objects in that collection and its child collections. Choose the property that fits your needs.
import bpy
collection = bpy.context.view_layer.active_layer_collection.collection
print("Etkin koleksiyon:", collection.name)
for obj in collection.objects:
print(obj.name, obj.type)This listing doesn’t change the scene. The Collection API also includes hide options for the viewport and render, but we don’t change them here. Grouping objects in the right collections and clarifying which collection scope you need can reduce the risk of future automation scripts affecting the wrong items.
Common mistakes and next steps
The most common issue is that the active object isn’t the expected type. The UV example requires an active mesh; it won’t work with mesh data when a light or camera is selected. The second issue is that the mesh has no active UV layer. The checks in this tutorial explicitly catch both cases.
For collections, don’t confuse direct objects with all the objects in child collections. Also, in the object-creation example, the data block and scene object are created in separate steps: creating the data alone doesn’t replace linking the object to a collection. Before using the script in a production file, test it in a copy of the scene and verify the active object, view layer, and collection selections.
As a next step, you can inspect the vertices, edges, and polygons data in the mesh documentation, then compare the hierarchy using the children and all_objects properties in the collection documentation. These sources don’t provide performance benchmarks, hardware requirements, or a specific compatibility table for this tutorial, so it wouldn’t be appropriate to draw conclusions about runtime in large projects.
For architecture, interior design, and archviz workflows, this basic API usage is a useful starting point for users who want to add repeatable elements to a scene, manage active object states, and check mesh UV data. The examples don’t define materials, light intensity, render settings, or a specific software add-on. Before adapting scripts to an office’s project standards, test the scene scale, collection structure, and API compatibility with the Blender installation in use.
Sources and license
This tutorial is adapted from the Object, Mesh, and Collection pages in the Blender API documentation. All three sources are licensed under CC BY-SA 4.0; the content has been adapted into Turkish and explained with new examples.
Sources
3 sourcesSource texts are not republished; short quotes are marked, everything else is our own summary and commentary.
For architecture and visualization teams, the practical value of these examples lies in breaking down direct access to scene data into clear steps. Tasks such as creating objects, linking collections, and reading UV data offer a safe testing ground before moving on to more extensive automation. The source page indicates that Blender is free, but the CC BY-SA 4.0 license of the API documentation should not be confused with the software’s licensing terms.
Offices and students in Turkey should test the examples in a copy of a scene before using them in existing files. Since the sources don’t specify hardware requirements, a particular Blender version, or add-on compatibility, these details should be verified separately in the installation being used. Scripts alone won’t improve design decisions or render quality; they provide a starting point for organizing repetitive tasks and inspecting scene data.
Frequently asked questions
How do you add a light to a scene with the Blender Python API?
First, create light data with `bpy.data.lights.new`, then create an object with `bpy.data.objects.new`. The object can be linked to the active collection, positioned, and made the active object.
How do you read mesh UV data with Python in Blender?
Check that the active object is a mesh and that it has an active UV layer. Use the polygon loop indices to match mesh vertices with UV coordinates.
Which Blender version does this tutorial require?
The API documentation used here doesn’t specify a particular Blender version number, so a minimum version can’t be determined from the sources.



