2
$\begingroup$

I've been trying this a bunch of ways but no matter what I do I get a blank white plane. What I want is to programmatically create a plane with the ocean modifier applied to it. What am I missing?

bpy.ops.mesh.primitive_plane_add(radius=10, view_align=False, location=(0, 0, 0))
bpy.ops.transform.translate(value=(0,0,-1.0 * model_height / 2.0 + 0.2 * model_height))
for obj in bpy.data.objects:
    obj.select = False
plane = bpy.data.objects['Plane']
plane.select = True
bpy.context.scene.objects.active = plane
bpy.ops.object.modifier_apply(modifier='Ocean')
$\endgroup$
5
$\begingroup$

You need to add the ocean modifier before you can 'Apply' it. Try :

import bpy

model_height = 2

bpy.ops.mesh.primitive_plane_add(radius=10, view_align=False, location=(0, 0, 0))
bpy.ops.transform.translate(value=(0,0,-1.0 * model_height / 2.0 + 0.2 * model_height))

for obj in bpy.data.objects:
    obj.select = False

plane = bpy.data.objects['Plane']
plane.select = True
bpy.context.scene.objects.active = plane 

#Add the modifier
bpy.ops.object.modifier_add(type='OCEAN')

#Apply the modifier
bpy.ops.object.modifier_apply(modifier='Ocean')

Obviously, if you want to adjust the Ocean modifier you'll need to do this before 'apply'ing it (or don't apply it and leave it on the modifier stack).

$\endgroup$
  • 3
    $\begingroup$ @SamJohnson Often simpler to add modifier with om = plane.modifiers.new("SomeName", 'OCEAN') Set props om.wind_velocity = 10.0 and apply with operator bpy.ops.object.modifier_apply(modifier=om.name) Similarly pick up a newly added primitive ref directly after operator with plane = context.object (will be the active object and selected) Avoid expecting the name to be "Plane". Script above only ever applies modifier to original plane if re-run. $\endgroup$ – batFINGER Oct 9 '18 at 7:20
  • $\begingroup$ @batFINGER Very worthwhile comments (as always). Feel free to add an answer or edit - you could do this far more justice than I can. $\endgroup$ – Rich Sedman Oct 9 '18 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.