💻 Coding
Blender bpy Script Writer Locked to 4.2 LTS
Write an idempotent Blender 4.2 LTS bpy script that pastes into the Text Editor, with a 3.6/4.5 incompatibility list and no fake operators.
0Reviews
Prompt
Act as a Blender Python engineer targeting Blender 4.2 LTS. Write scripts that paste into the Text Editor and run. Do not invent operators. Do not target 4.5 or 3.6 APIs unless Inputs ask for a compatibility note. Inputs: - Blender version I will run: [Must be 4.2.x LTS unless specified] - Task: [What the script should do] - Scene assumptions: [Units, existing objects, collections] - Idempotent?: [Yes/No] - Mode: [Object / Edit / Geometry Nodes / addon] - Output: [objects created, files written] - Must not: [Delete the default cube, call bpy.ops.wm.save, etc.] Generate: 1. Version lock: confirm 4.2 LTS. List 3 APIs that differ in 3.6 and in 4.5 that this script will not use. 2. Full script: import bpy, a main() guarded by if __name__, no wildcard imports. 3. Operator policy: prefer data API (bpy.data, collection.objects.link) over bpy.ops when possible. If an op is required, comment why. 4. Idempotency: if Yes, find-or-create by name, do not duplicate on second run. 5. Context notes: what area/mode must be active. If VIEW_3D is required, fail with a clear RuntimeError. 6. Manual run steps: Text Editor > New > Paste > Run Script. Expected Outliner result. 7. Reverse: names to delete. Do not write addon unregister unless Mode is addon. Constraints: - Blender 4.2 LTS only in executable code. - Do not call bpy.ops.wm.quit or save the file. - If Task needs an extension that is not bundled, stop and name it.
Instructions
Replace every [bracket] with your details before running. Works on ChatGPT, Claude, and Gemini.
Examples
Example Input
Version: 4.2.7 LTS Task: create collection Packshots, create or reuse a 0.2m UV sphere named ProbeBall, assign Principled BSDF ProbeBallMat base color (0.8,0.8,0.8,1), roughness 0.35, metallic 0, put the ball at (0,0,0.1) Assumptions: metric, default cube may stay, do not delete it Idempotent: yes Mode: Object, Text Editor script, not an addon Output: collection + object + material in this file only Must not: save, quit, delete cube, pack resources
Example Output
1. Version lock
Executable code is Blender 4.2 LTS (you said 4.2.7). Will not use:
- 3.6 Principled sockets (Specular vs Specular IOR Level).
- 3.6 addons path; 4.2 uses Extensions. This file is not an addon.
- 4.5-only GPU module moves. Not used.
2. Script
import bpy
COLL, OBJ, MAT = "Packshots", "ProbeBall", "ProbeBallMat"
def get_or_create_collection(name):
col = bpy.data.collections.get(name)
if col is None:
col = bpy.data.collections.new(name)
bpy.context.scene.collection.children.link(col)
return col
def get_or_create_material(name):
mat = bpy.data.materials.get(name)
if mat is None:
mat = bpy.data.materials.new(name)
mat.use_nodes = True
bsdf = next(n for n in mat.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
bsdf.inputs["Base Color"].default_value = (0.8, 0.8, 0.8, 1.0)
bsdf.inputs["Roughness"].default_value = 0.35
bsdf.inputs["Metallic"].default_value = 0.0
return mat
def main():
if bpy.app.version[:2] != (4, 2):
raise RuntimeError("Locked to Blender 4.2 LTS")
col = get_or_create_collection(COLL)
obj = bpy.data.objects.get(OBJ)
if obj is None:
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(0.0, 0.0, 0.1))
obj = bpy.context.active_object
obj.name = OBJ
for c in list(obj.users_collection):
c.objects.unlink(obj)
col.objects.link(obj)
obj.location = (0.0, 0.0, 0.1)
mat = get_or_create_material(MAT)
if obj.data.materials:
obj.data.materials[0] = mat
else:
obj.data.materials.append(mat)
if __name__ == "__main__":
main()
3. Operator policy
primitive_uv_sphere_add only when ProbeBall is missing. Collection and material use data API. No wm.save.
4. Idempotency
Second run finds Packshots, ProbeBall, ProbeBallMat and only resets location and BSDF values.
5. Context
First-run ops path needs a 3D View poll. Default layout Text Editor > Run Script works. If poll fails, run from VIEW_3D.
6. Manual steps
Open 4.2.7. Text Editor > New > paste > Run Script. Outliner: Packshots / ProbeBall. Default cube remains.
7. Reverse
Delete object ProbeBall, material ProbeBallMat, collection Packshots. Do not File > New.