0
$\begingroup$

I am trying to run shrinkwrap and then remesh modifier repeatedly but not working. It seems to me there is a infinite loop inside the code. I am new to blender and python coding. What is wrong with that code?

I am using Blender 3.6

import bpy

jaw = bpy.data.objects['jaw']

for i in range(0,20):
    bpy.ops.object.modifier_add(type='SHRINKWRAP')
    bpy.context.object.modifiers["Shrinkwrap"].target = jaw
    bpy.context.object.modifiers["Shrinkwrap"].offset = 0.5

    bpy.ops.object.modifier_add(type='REMESH')
    bpy.context.object.modifiers["Remesh"].mode = 'SMOOTH'
    bpy.context.object.modifiers["Remesh"].use_remove_disconnected = False
    bpy.context.object.modifiers["Remesh"].octree_depth = 8

    bpy.ops.object.modifier_apply(modifier='SHRINKWRAP')
    bpy.ops.object.modifier_apply(modifier='REMESH')
$\endgroup$
2
  • $\begingroup$ This is XY problem. Please specify what you are trying to accomplish, why would you want to add the modifier 20 times? $\endgroup$
    – Harry McKenzie
    Commented Sep 30, 2023 at 12:42
  • $\begingroup$ There is no infinite loop, the code is ok. Depending on the complexity of your mesh, it just may take a while to perform. Even for two simple cubes it takes some seconds. Add a print(i) statement in the loop to observe this in the system console. As @HarryMcKenzie already asked, what are you trying to achieve? $\endgroup$
    – taiyo
    Commented Sep 30, 2023 at 14:01

1 Answer 1

2
$\begingroup$

bpy.ops.object.modifier_apply(modifier="modifier_name")

takes actual modifier name, which is unique for every modifier. What you are passing is modifier type.

Add modifier to selected and another to active object

See the above link.

In your specific case, you can get away using

bpy.ops.object.modifier_apply(modifier='Shrinkwrap')
bpy.ops.object.modifier_apply(modifier='Remesh')

As new modifiers are named that way.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .