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=&quot;hello&quot; 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?
102085
I am trying to set up an operator to use the BoolTool after I set a position and modifier on Selected object and a different one on the Active object. I basically need to move the selected object up in Z and add a solidify modifier at .3 thickness, and to the Active I need to add a solidify at .1 thickness and remain in original position.  I thought I understood how to get this to work, but all I get is both modifiers on the Active object. Any hint as to where to go from here?  class SolidfyDifference(bpy.types.Operator): """Solidify and Difference Mask""" bl_idname = "object.solidfy_difference" bl_label = "Add Solidy and Difference Bool" bl_options = { 'REGISTER','UNDO' }  def execute(self, context):     scene = context.scene      sel = bpy.context.selected_objects     act = bpy.context.active_object        for obj in sel:         if obj != act:             bpy.ops.object.modifier_add(type='SOLIDIFY')             bpy.context.object.modifiers["Solidify"].thickness = 0.1        return {'FINISHED'}
69425
I would like to know if there is any way to use the "Add 3d Function Surface" addon via the python interface.  I have an equation that describes a surface in the three-dimensional space that I can use to make a mesh object as described in . What I would like to know is if there is any way to do such a thing via the python interface.   As an example, I would like to be able to do something like:  def mysurface(u, v):    return numpy.array([u*v, u-v, math.pow(u, 2)])  add_mesh_from_surface_equation(func = mysurface, urange = [0, 10], vrange = [0, 10], ustep = 0.01, vstep = 0.01)   Is it possible to do something like this?
54798
Is there a simple and quick way to add a vertex to an existing edge? I mean in a similar manner (Ctrl+R) like a loop cut for the whole object?  My current workflow is, deleting the edge completely, then I select one of the vertices and extend it via E shortcut. Is there an easier method to get an extra vertex like:
31824
I have been looking for methods to create a set of objects from an Array Modifier. Normally one creates an Array, sets an Array Offset and manipulates it so that the transformation propagates to all the copies and most of the times the goal is to have a geometry as you don't care about the sub-parts own transforms but I do this time since my goal is to export these (empty in my case) transforms to a game engine. To expand a bit, I already know that I can Apply the modifier and then separate the meshes By Loose Parts but it's not what I want and the reason for that is that with that method, such loose parts will inherit all the same rotation and scale from the original object; in fact the matrix of the single copy of the array is lost when applying the array. My question is slightly different from this one:  in that I need the individual rotations and scales to be kept. What I need ideally is a workflow to go from an Array Modifier (but potentially parting ways from the Array Modifier) to create a big set (big enough to discourage manual duplication) of empty objects that keep their individual position, rotation and scale. How can I achieve that?
27921
I would like to create a mesh, then interactively add vertices (afterwards, possibly through a loop) to it through python.  Is that possible?  I can't find enough info from other answers to really get this going - either I find out how to create a mesh, or how to add a vertex, but can't seem to put them together in to a script.
2769
I need to store additional information in a .blend file, that occurs only once per file. So, attaching it to, for example, bpy.types.Scene doesn't help.  Since bpy.data is an instance of bpy.types.BlendData, I tried attaching properties to bpy.types.BlendData. This failed:  &gt;&gt;&gt; bpy.types.BlendData.testProp = bpy.props.StringProperty() &gt;&gt;&gt; bpy.data.testProp (&lt;built-in function StringProperty&gt;, {})   Here, bpy.data.testProp is not a string, but some tuple, So it looks like registering properties on bpy.types.BlendData is not supported, like it is for bpy.types.Object:  &gt;&gt;&gt; bpy.types.Object.testProp = bpy.props.StringProperty() &gt;&gt;&gt; bpy.data.objects['Camera'].testProp ''   Is it somehow possible to attach properties to bpy.types.BlendData?  Are there other ways to register global data in a .blend file?
62109
I've found some code that could add a modifier but none can set parameters like Octree.
60555
I've created a mesh I want to duplicate using python with specifications for the new duplicate's coordinates. How do I do that?
113762
I am currently in the process of writing a project in python for Blender to simulate crowds automatically. However I would need for there to be a custom UI to allow the user to choose their settings such as min to max speed, how much they want locations to randomised by etc. But from tutorials I have watched, and links I have followed all seem to have the buttons and sliders only do what is already predefined in blender and does not allow me to make it execute a function I have wrote. I managed to find a workaround for creating a custom shape by adding it to the operator menu, but is there a way for it to save the value of a slider to a variable rather than doing a predefined Blender function.  import bpy import math import mathutils  class TargetMakerPanel(bpy.types.Panel) :     bl_space_type = "VIEW_3D"     bl_region_type = "TOOLS"     bl_context = "objectmode"     bl_label = "CrowD"         def draw(self, context) :         layout = self.layout         scene = context.scene         TheCol = self.layout.column(align = True)         TheCol.operator("mesh.make_target", text = "Add Target")         layout.label(text=" Random Speed:")         row = layout.row()         row.prop(scene, "frame_start")         row.prop(scene, "frame_end")  class MakeTarget(bpy.types.Operator) :     bl_idname = "mesh.make_target"     bl_label = "Add Target"     bl_options = {"UNDO"}      def invoke(self, context, event) :         Vertices = \           [             mathutils.Vector((-0.5, -0.5,0)),             mathutils.Vector((0.5, -0.5, 0)),             mathutils.Vector((0.5, 0.5, 0)),             mathutils.Vector((-0.5, 0.5, 0)),            ]         NewMesh = bpy.data.meshes.new("Target")         NewMesh.from_pydata \             (             Vertices,             [],             [[0, 1, 2], [0, 1, 3], [1, 2, 3], [2, 0, 3]]           )         NewMesh.update()         NewObj = bpy.data.objects.new("Target", NewMesh)         context.scene.objects.link(NewObj)         return {"FINISHED"}     #end invoke   def register() :     bpy.utils.register_class(MakeTarget)     bpy.utils.register_class(TargetMakerPanel)  def unregister() :     bpy.utils.unregister_class(MakeTarget)     bpy.utils.unregister_class(TargetMakerPanel)  if __name__ == "__main__" :     register()   In my code I would ideally like it so that the row that slider that says "Start Frame" would allow me to recognise that value and assign it to a variable called MinSpeed.... Rather than it automatically changing the frame as blender had already defined it as...
23846
I am trying to create a script that will allow me to generate a list and store it in the blend file. The list starts out blank and then strings get added to the list, resulting in: [&quot;test1&quot;,&quot;test2&quot;,&quot;test3&quot;] I create a PropertyGroup Class for the enum, define a new scene property as a CollectionProperty type with access to that enum Class, before appending a new item into the enum: import bpy  class item_set(bpy.types.PropertyGroup):     myItems = []     enums = bpy.props.EnumProperty(name=&quot;My Items&quot;, items=myItems) bpy.utils.register_class(item_set)  bpy.types.Scene.myItemSet = bpy.props.CollectionProperty(type=item_set)      newItem = bpy.context.scene.myItemSet.add() newItem.myItems.append(&quot;test&quot;)    I need to be able to add items to the list, save the blend file, re-open the file, run the script again and retrieve the list from the scene. However, the  states:  One thing to keep in mind is that after saving and reloading your blend-file, your new property will have disappeared...    ...To make the values you assigned in a previous session available again, you need to redefine the property. So after reopening the blend-file you need to rerun: bpy.types.Object.myProperty = bpy.props.StringProperty()   I can do the appending into and retrieval of the property values absolutely fine upon an initial run, but as the documentation states, the property is unavailable when trying to view it's contents on a reload of the file (after having run the script, saved and re-opened the file), but I am unsure how to redefine it without clearing all it's values. If I redefined the scene property, it would presumably also need the enum Class to be available, which would currently set myItems back to [] (empty). Do I need to change the way I am initially setting the items in the class or am I on entirely the wrong track with all of this? All I need to do is store a list in the blend file, so if there is a better way please let me know. Thanks. (I would hope, eventually, to be able to store sub lists [[&quot;a&quot;,&quot;b&quot;],[&quot;c&quot;,&quot;d&quot;],[&quot;e&quot;,&quot;f&quot;]], I'm just trying to get normal lists to work first.)
29430
Is it possible to add a modifier to more than one mesh at once?  I have a lot of unique objects,  and I want to set a subdivide modifier to them, would I have to do each one individually?   I have tried selecting all the objects and then adding a modifier, but as I expected, it only added it to the active object.
112950
My goal is to reduce the faces of an object using the decimate modifier. The object I'm editing has lots of vertex groups. Blender 2.8 only lets me add the decimate modifier to a single group at once which would take quite some time. I have already put all groups in a single collection.  How can I add the decimate modifier to the entire collection?  Do I have to add the modifier group by group?
106506
I'm trying to achieve this:  I select all objects with the same type of modifier (Armature) and want to "click" Apply on all of them. I searched different scripts on here and badly put together this one:  import bpy sel = bpy.context.selected_objects  for ob in sel:     for i, mod in enumerate(ob.modifiers):         if mod.type == 'ARMATURE':             bpy.context.scene.objects.active = ob                 for x in range(0, i):                     bpy.ops.object.modifier_apply(modifier=mod.name)   It will work for some of the selected objects then Blender will say "Python Script fail". It's obvious I don't know what I'm doing, but why is it failing after working at first? Thanks  EDIT: I found something that does exactly what I was trying to do. A user from Blender Artists named VincentG created an addon called "Massive Editor" from . I selected all objects, typed Armature in the custom field and all objects that had that specific modifier applied. The script may be old, but it worked great. Thanks Vincent!  For the sake of learning though, I'd still want to know what went wrong...  UPDATE: While searching around I found this answer  and tried it out to see if it would work for me:  import bpy  sel = bpy.context.selected_objects act = bpy.context.active_object  for obj in sel:     if obj != act:         bpy.context.scene.objects.active = obj #sets the obj accessible to bpy.ops         bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Mirror")  bpy.context.scene.objects.active = act   It almost does what I would like but every time it would only apply to all selected objects except the active one.
76483
How can I assign a new material to an object in the scene via Python?
90585
The following:  bpy.data.objects['Cube'].select = True  bpy.context.scene.objects.active = bpy.data.objects['Sphere.017']   don't work in Blender 2.8, they did in 2.79 though. How should I select (multiple) objects with Python in Blender 2.8?
30324
Is it possible to make python addon as a modifier?   I just would like to make some deformation modifiers. But I know only python.
87028
Looking at the API docs I found , but It cannot be called in Edit Mode. When I try to call it, I always get:     RuntimeError: VertexGroup.add(): cannot be called while object is in edit mode.   The buttons in the vertex group list use bpy.ops.objects.vertex_group_assign(), but to work with it you have to manipulate selections, this is not nice to do from a script.    Why I try to use VertexGroup.add() in Edit Mode? My script works this way:  Human weight paint a bone, "Arm_1.L", "Arm_1.L" shares vertices with "Arm_2.L" in this case they share half the vertices (4 bone arm rig, trick to have nice deform in certain movements). When script run, all selected vertices that exist in both groups (Arm_1.L and Arm_2.L) will copy the weights of Arm_1.L into Arm_2.L but inverted. This way, I only need to weight paint "Arm_1.L" and "Arm_3.L", the script will fill the weights for "Arm_2.L".  import bpy  # ensure we are in edit mode bpy.ops.object.mode_set(mode="EDIT")  # configurable parameters src_group = "Arm_03.L" dst_group = "Arm_02.L"  obj = bpy.context.edit_object src_group_index = obj.vertex_groups[src_group].index dst_group_index = obj.vertex_groups[dst_group].index  mesh = obj.data sel_verts = [v for v in mesh.vertices if v.select] #sel_verts = mesh.vertices  # SEGFAULT in this line bpy.ops.object.mode_set(mode="OBJECT")  print("Working")  for v in sel_verts:     v1in = False     v2in = False     for g in v.groups:         if g.group == src_group_index:             v1in = True         if g.group == dst_group_index:             v2in = True     if v1in and v2in:         print("True")         obj.vertex_groups[dst_group].add([v.index], 1.0 - obj.vertex_groups[src_group].weight(v.index), 'REPLACE')  print("Finished")