0

I have created an object programmatically and want to add a modifier to it too, programmatically. Here is my current code

import bpy
# make mesh
vertices = [(0, 0, 0),(0, 1, 0)]
edges = [[0,1]]
faces = []
obj_name="hello"
new_mesh = bpy.data.meshes.new('new_mesh')
new_mesh.from_pydata(vertices, edges, faces)
new_mesh.update()
# make object from mesh
new_object = bpy.data.objects.new(obj_name, new_mesh)
# make collection
# add object to scene collection
new_object.modifier_add(type='SCREW')
new_collection = bpy.data.collections.new('new_collection')
bpy.context.scene.collection.children.link(new_collection)
new_collection.objects.link(new_object)

This returns an error:

AttributeError: 'Object' object has no attribute 'modifier_add'

How would I go about fixing this?

Ravi Arora
  • 11
  • 1
  • The correct function call seems to be bpy.ops.object.modifier_add(type='SCREW'), although you might have to select object and make it the active object first – WhatAMesh Feb 14 '21 at 13:48
  • I wanted to know if I could do it without that and using the bpy.data object – Ravi Arora Feb 16 '21 at 08:39

0 Answers0