I wrote a Python script in Blender which creates a blocky version of an object with an ocean modifier, so you need to have this object added and animated by yourself.

It should work like this:

  1. An ocean mesh is created by using the original ocean object's mesh, applying all modifiers.

  2. Another mesh is created, all of the polygons facing to the top may be moved.

    For each frame from start to end:

  3. A shape key is added to the mesh.

  4. The shape key data is being filled with rounded positions from the ocean.

  5. Keyframes are inserted to make the shape key only influence the mesh at the current frame.

Use the system console to see at which frame it is working at the moment.

But every time I run the script, Blender crashes at a different frame.
The last message (right before the windows close) is this:


Here's my script: BlockyOcean.py

  • 1
    $\begingroup$ Please write minimal example code that shows your problem. See stackoverflow.com/help/mcve for the how & why. $\endgroup$
    – dr. Sybren
    Sep 5, 2017 at 10:05
  • $\begingroup$ Maybe related to this question? blender.stackexchange.com/questions/79164/… $\endgroup$
    – lucblender
    Sep 5, 2017 at 10:25
  • 1
    $\begingroup$ Firstly welcome, and kudos for having a red hot go. Quite likely the issue is you are referencing an object after it has been removed. The outer loop for o in bpy.data.objects will loop thru all the objects in the file (often scene.objects is a better option) ... but then you are adding to that collection as you go, removing meshes ... it's a little hard to follow.... Questions like these are difficult to answer because you've put a lot of time an effort into writing the script, to which I'd do it this way instead may not be appreciated. $\endgroup$
    – batFINGER
    Sep 5, 2017 at 10:49
  • $\begingroup$ @dr.Sybren ... as long as it's minimal runable and testable .. having to edit in register and import code etc can be a PITA. IMO..(might make a good meta q ) In this case, writing a stripped down version for the question will most likely provide ("debug") a solution. $\endgroup$
    – batFINGER
    Sep 5, 2017 at 10:56
  • 3
    $\begingroup$ Please include any relevant code in the question body itself instead of linking to it, just in case the link goes down in future. $\endgroup$ Sep 5, 2017 at 11:18

1 Answer 1


Okay, I got it working! As batFINGER already suspected, it was about accessing a removed object. I had an Vector variable, which was defined only once.

co = ocean.vertices[0].co

This line is now called every time the mesh changes in my script.

I also added a few lines to update bpy.data.meshes/.objects (I don't know if actually necessary), the whole code can be simplified for sure, but hey: it works!

Non-blocky ocean Blocky ocean

  • $\begingroup$ If ocean is to be later removed can use co = ocean.vertices[0].co.copy() "use this to get a copy of a wrapped vector with no reference to the original data" $\endgroup$
    – batFINGER
    Sep 6, 2017 at 8:59

You must log in to answer this question.

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