3
$\begingroup$

I have about 200 objects that all have the subdivision modifier added. I want to "apply" the modifiers (effectively "baking" the subdivisions to the meshes).

Is there a way to do this to all objects at once, or do I have to go through all 200 objects and manually apply the modifier to each one?

$\endgroup$
2
  • $\begingroup$ I’ll bet you can do it with python scripting. I’ll see about it in the docs… $\endgroup$
    – TheLabCat
    Commented Jun 7, 2021 at 22:19
  • 1
    $\begingroup$ I was able to achieve what I wanted by using ctrl+a and selecting "visual geometry to mesh". It worked in my case. $\endgroup$ Commented Jun 7, 2021 at 22:31

2 Answers 2

3
$\begingroup$

Here are are some Python scripts that could accomplish your goal, although I dislike being forced into using a programming language unless I need to do something complicated or repetitively.

In the following there may be some nuance as to how you select the objects to apply modifiers.

The simplest is to look at all objects, and apply the modifier if the object has the modifier of Subdivision:

import bpy

for obj in bpy.context.editable_objects:
    if "Subdivision" in obj.modifiers:
        print("modifier_apply: ",obj)
        bpy.context.view_layer.objects.active = obj
        bpy.ops.object.modifier_apply(modifier="Subdivision")

Or, let’s say they all have a common name like "My.Subd.*", so perhaps:

import bpy

bpy.ops.object.select_all( action='DESELECT' )
# get a list of objects with a name pattern
bpy.ops.object.select_pattern(pattern="My.Subd.*")
objs = bpy.context.selected_objects
print("objects are: ", objs)
bpy.ops.object.select_all( action='DESELECT' )
for obj in objs:
    print("modifier_apply: ",obj)
    bpy.context.view_layer.objects.active = obj  # set active object
    bpy.ops.object.modifier_apply(modifier="Subdivision")  # apply only a type of modifier

Or, perhaps you have linked all to a named Collection and can enumerate with:

objs = bpy.data.collections['Collection_subdiv'].objects
$\endgroup$
6
  • 1
    $\begingroup$ Thanks for taking the time to write the script! I was able to figure out another way to achieve what I wanted, which was selecting all objects and Ctrl+A > "Visual Geometry to Mesh". It worked for what I wanted to do. But I will test your script later. If it works I'll mark your answer as the solution. $\endgroup$ Commented Jun 7, 2021 at 23:13
  • $\begingroup$ Thanks @Alexandre Marcati -- I have interesting in learning while I help, but I also as a boy I "compete for points" haha. I think there is a but, so wait until I test and refine! $\endgroup$
    – james_t
    Commented Jun 8, 2021 at 15:06
  • $\begingroup$ Ok! Let me know when you think it's finished so I can test and mark your answer as solution! Your script would be very useful because it would allow to only apply a specific type of modifier, it would sure be a good tool to have in the toolbox. :) $\endgroup$ Commented Jun 8, 2021 at 15:10
  • 1
    $\begingroup$ @Alexandre Marcati -- I have tested and fixed a bug in how to select the object to apply the modifier. I may update it later to apply the modifier to any object with any name that has a modifier of type 'Subdivision', as another example. You might also have all of the desired objects in (or linked to) a particular collections so could use objs = bpy.data.collections['Collection_subdiv'] $\endgroup$
    – james_t
    Commented Jun 8, 2021 at 16:09
  • 1
    $\begingroup$ @Alexandre Marcati -- you caught me scripting without testing again! should instead be: objs = bpy.data.collections['Collection_subdiv'].objects. And again I think we should be able to accomplish more, intuitively, through the GUI. $\endgroup$
    – james_t
    Commented Jun 8, 2021 at 18:17
7
$\begingroup$

Ok, I was able to (kinda) figure it out. Here's a way to do it in case someone else is wondering:

select all the objects you want to apply the modifiers, press Ctrl+a, then select Visual Geometry to Mesh. This has the same effect as "applying" the modifiers, but can be done to multiple objects at once. The limitation is that it will apply all modifiers, you can't pick and choose which modifiers you want to apply.

$\endgroup$
1
  • 2
    $\begingroup$ That does work :-) the only thing I could find in the docs was a bpy.OPS call, which has to have the right object selected. $\endgroup$
    – TheLabCat
    Commented Jun 7, 2021 at 22:32

You must log in to answer this question.

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