How to find the surface area of a complicated mesh using Python code in Blender. The mesh can be .obj .ply or .stl .
1 Answer
$\begingroup$
$\endgroup$
5
One way is to sum bmesh face.calc_area() for all faces.
import bpy
import bmesh
obj = bpy.context.active_object
bm = bmesh.new()
bm.from_mesh(obj.data)
area = sum(f.calc_area() for f in bm.faces)
print(area)
bm.free()
Will give result in objects local space would need to allow for scale. eg if the object is scaled by (2, 2, 2) would need to multiple result by 2 x 2. Or apply scale before calculation.
-
$\begingroup$ @ideasman42 I am not getting any output even though it shows no errors . $\endgroup$– kpdkpsCommented Feb 26, 2016 at 6:55
-
$\begingroup$ Need a blender mesh object selected in object mode. Run script. Output will be printed to the system (not blender python) console. You will need to import obj, ply or stl models first. $\endgroup$ Commented Feb 26, 2016 at 7:05
-
$\begingroup$ The code from 3D Print Toolbox expands on this example by also accounting for scale, modifiers and the unit settings to give accurate final measurements in either metric or imperial. $\endgroup$– samblerCommented Feb 26, 2016 at 15:22
-
$\begingroup$ Is it possible to find the AREA of a selected portion in mesh.( or the portion marked by seam/pencil) . It would be more useful than finding the area of actual mesh. @ideaman42 $\endgroup$– kpdkpsCommented Mar 2, 2016 at 4:25
-
$\begingroup$ Yes, To sum the area of selected faces use
area = sum(f.calc_area() for f in bm.faces if f.select)
Examples of using bmesh on active edit mesh. blender.stackexchange.com/a/40979/15543 blender.stackexchange.com/a/41758/15543 $\endgroup$ Commented Mar 2, 2016 at 11:59