Applying modifier in Python, creating a new mesh.

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

damix
Posts: 21
Joined: Wed Dec 07, 2011 4:42 pm

Applying modifier in Python, creating a new mesh.

Postby damix » Tue Jul 24, 2012 4:41 pm

Hi everybody.

Let's say I have a bpy.types.Object containing a bpy.types.Mesh data field; how can I apply one of the modifiers associated with the object, in order to obtain a NEW bpy.types.Mesh, possibly contained within a NEW bpy.types.Object, thus leaving the original scene unchaged?

I'm interested in applying the EdgeSplit modifier right before exporting vertex data to my custom format; the reason why I want to do this is to have Blender automatically and transparently duplicate the vertices shared by two faces with very different orientations.

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Thu Jul 26, 2012 11:49 am

there is an operator to apply a single modifier, but i tend to use to_mesh(), which applies all modifiers and stores the result in a new mesh

Code: Select all

MeshObject.to_mesh(scene=bpy.context.scene, apply_modifiers=True, settings='PREVIEW')


you can change the show_viewport (settings='PREVIEW') or show_render (settings='RENDER') properties of modifiers before calling to_mesh to control which to apply (False = won't be applied).

this is an example how i use this:
http://code.google.com/p/blender-cod/so ... del.py#185
I'm sitting, waiting, wishing, building Blender in superstition...


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests