6

I've found some code that could add a modifier but none can set parameters like Octree.

enter image description here

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Claire
  • 95
  • 1
  • 1
  • 4

2 Answers2

13

You can add a new modifier to an object with ObjectModifiers.new(). If you store the result of calling ObjectModifiers.new() in a variable (in the example below I call it modifier) you then have access to all the properties of the new modifier:

import bpy

object = bpy.data.objects['Cube']

modifier = object.modifiers.new(name="Remesh", type='REMESH')
modifier.octree_depth = 5

You can see the type of modifier by hovering the mouse over the modifier in the Add modifier menu and you can see the name of the properties by hovering over the properties on the modifier.

brockmann
  • 12,613
  • 4
  • 50
  • 93
Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
0

If you mouse over the field you should get a pop-up that show you a python expression for what the field refers to. Since my knowledge of modifiers is far from encyclopedic I can not reproduce your situation in my blender.

Nevertheless, mouse-over is a standard technique for figuring out the python path to a field (although there are some data blocks whose path is complicated enough that you just end up with a ... in the middle)

Mutant Bob
  • 9,243
  • 2
  • 29
  • 55
  • well there is no hint on these fields, hence my post, but I used autocomplete in python console – Phil May 13 '22 at 09:07