Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I've been scouring the Blender Python API docs for 2.69x for a replacement to the 2.4x API's Mesh.getFromObject method.

I can't find any way to get a fresh copy of a mesh with modifiers applied in advance.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

The option to apply modifiers is common for exporters included with Blender, so you can check how they do it.

Typically you can use the Object.to_mesh function, which returns a new mesh. You can manipulate it without distructively editing the user's data.

import bpy

# --- setup variables ---
context = bpy.context
scene = context.scene

# assume we have an object with geometry, nurbs, metaball, curves... _not_ a lamp
obj = context.object

# --- get a mesh from the object ---
apply_modifiers = True
settings = 'PREVIEW'
mesh = obj.to_mesh(scene, apply_modifiers, settings)

# ... do something with the mesh ...

It's important to remove the mesh, unless you have explicitly assigned it to an object. Otherwise it will be stored in Blender until the file is saved and loaded again.

# optionally remove it
bpy.data.meshes.remove(mesh)
share|improve this answer
    
Usually the research goes easily, finding an equivalent process in Blender 2.5+, from Blender 2.4. But sometimes these methods are moved to different classes, and that adds much time, and sometimes really impairs my progress by relying upon the community (not that it's a bad thing, after doing my homework). Thank you for your help! –  Tom Pace Feb 20 at 6:31
    
I did not need to calculate the tessfaces, so I set the extra parameter calc_tessface=False and my tests pass. Awesome. –  Tom Pace Feb 20 at 6:45
    
@Tom Pace, only if you want to use legacy access to face data (tris/quads, no ngons) - blender.org/documentation/blender_python_api_2_69_release/… –  ideasman42 Feb 20 at 8:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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