0
import bpy

# Set the rendering resolution
bpy.context.scene.render.resolution_x = 1920
bpy.context.scene.render.resolution_y = 1080

# Set the output file path
bpy.context.scene.render.filepath = "output.mp4"

# Create a new scene
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# Add a new icosphere to the scene
bpy.ops.mesh.primitive_ico_sphere_add()

# Select the icosphere
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = bpy.context.view_layer.objects[-1]
bpy.context.view_layer.objects.active.select_set(True)

# Enter Edit mode
bpy.ops.object.mode_set(mode='EDIT')

# Extrude and scale the icosphere to create the basic shape of the UFO
bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value": (0, 0, 0.5)})
bpy.ops.transform.resize(value=(1.5, 1.5, 1))

# Add a loop cut to create a panel on the top of the UFO
bpy.ops.mesh.loop_cut_slide(MESH_OT_loopcut={"number_cuts": 1, "smoothness": 0, "falloff": 'INVERSE_SQUARE', "edge_index": 4, "mesh_select_mode_init": (True, False, False)})

# Extrude and scale the panel to create a cockpit
bpy.ops.mesh.extrude_region_move(TRANSFORM_OT_translate={"value": (0, 0, 0.5)})
bpy.ops.transform.resize(value=(1, 0.5, 1))

# Add a new empty for the UFO to rotate around
bpy.ops.object.empty_add(type='PLAIN_AXES')

# Set the keyframes for the UFO's rotation
bpy.context.view_layer.objects.active.rotation_euler[2] = 0
bpy.context.view_layer.objects.active.keyframe_insert(data_path="rotation_euler", index=2)

bpy.context.view_layer.objects.active.rotation_euler[2] = 3.14159
bpy.context.view_layer.objects.active.keyframe_insert(data_path="rotation_euler", index=2)

# Set the frame rate and duration of the animation
bpy.context.scene.render.fps = 24
bpy.context.scene.frame_end = 48

# Render the animation
bpy.ops.render.render(animation=True)

Traceback (most recent call last):
  File "\Text", line 32, in <module>
  File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\scripts\modules\bpy\ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
AttributeError: Calling operator "bpy.ops.mesh.loop_cut_slide" error, could not be found
Error: Python script failed, check the message in the system console

I dont think my version is out of date, and I imported bpy

L0Lock
  • 15,965
  • 1
  • 20
  • 44
  • 3
    I think it is just a typo. bpy.ops.mesh.loop_cut_slide should be bpy.ops.mesh.loopcut_slide. No underscore between loop and cut. – Valalala Dec 22 '22 at 05:21
  • You can copy the error code and ask ChatGPT to fix it. But with my experience it does get a ton of errors when doing something more complex than scattering objects – Evripidis Lalissidis Dec 22 '22 at 07:17
  • for the next error "expected a view3d region & editmesh" have a look here: https://blender.stackexchange.com/questions/15118/how-do-i-override-context-for-bpy-ops-mesh-loopcut -- 3) last error, you cannot add an empty (bpy.ops.object.empty_add...) when you're still in Edit mode or you will get another invalid context error. Switch to Object mode first (bpy.ops.object.mode_set(mode='OBJECT')) -- The UFO still looks a bit strange...
  • – Blunder Dec 22 '22 at 13:28