Surface Area

hi.

i work with a lot of files tere are no rhino file, but catia, solidworks, or other… so it pass by igs or step…

i’ve to calculate surfaces of part of project, and sometimes the command surfaceArea doesn’t run:‘impossible to calculate’.
so i mesh objects, and calculate the area, and it runs everytime… so when i have to do that, by script, i pass to this way, i select objects, mesh its,return the area and delete meshes…

but in Python i didn’t find rs.meshobjects, so i use the @dale’s script…
with surfaces, it’s ok, but if i select a polysurface, it mesh only one surface of the polysurface.

def MeshObjects(_ids):
    objs = [sc.doc.Objects.Find(id) for id in _ids]
    mp = Rhino.Geometry.MeshingParameters()
    mesh_ids = []
    for obj in objs:
        if isinstance(obj.Geometry, Rhino.Geometry.Brep):
            brep = obj.Geometry
        elif isinstance(obj.Geometry, Rhino.Geometry.Extrusion):
            brep = obj.Geometry.ToBrep(True)
        elif isinstance(obj.Geometry, Rhino.Geometry.Surface):
            brep = Rhino.Geometry.Brep.CreateFromSurface(obj.Geometry)
        else:
            continue
        mesh = Rhino.Geometry.Mesh.CreateFromBrep(brep,mp)[0]
        m_id = sc.doc.Objects.AddMesh(mesh)
        mesh_ids.append(m_id)

    if len(mesh_ids)==0: return
    sc.doc.Views.RedrawEnabled = True
    return mesh_ids

what is a brep in rhino?
is it possible to create a brep from a polysurface?

Hi,

a brep in Rhino is a ‘boundary representation’ object
in short a polysurface with one or more faces

to help get the correct area a rewrote the method:

not sure what the purpose of MeshObjects was, but there is an issue with

Rhino.Geometry.Mesh.CreateFromBrep(brep,mp)[0]

Rhino.Geometry.Mesh.CreateFromBrep() return an array of meshes, one for each face of a polysurface.

below a quick rewrite to directly get the mesh area for objects

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def objects_mesh_area(ids):
    objs = [sc.doc.Objects.Find(id) for id in ids]
    mp = Rhino.Geometry.MeshingParameters()
    #mesh_ids = []
    area = 0
    for obj in objs:
        if isinstance(obj.Geometry, Rhino.Geometry.Brep):
            brep = obj.Geometry
        elif isinstance(obj.Geometry, Rhino.Geometry.Extrusion):
            brep = obj.Geometry.ToBrep(True)
        elif isinstance(obj.Geometry, Rhino.Geometry.Surface):
            brep = Rhino.Geometry.Brep.CreateFromSurface(obj.Geometry)
        else:
            continue
            
            
        #collect all meshes previously only the first one was returned
        meshes = Rhino.Geometry.Mesh.CreateFromBrep(brep,mp)
        
        # make a single mesh:
        new_mesh = Rhino.Geometry.Mesh()
        # append separate meshes into one
        for mesh in meshes: new_mesh.Append(mesh)
        
        #get area from the mesh
        AMP = Rhino.Geometry.AreaMassProperties.Compute(new_mesh)
        #
        area +=  AMP.Area
        
        
    return area

    #if len(mesh_ids)==0: return
    #sc.doc.Views.RedrawEnabled = True
    #return mesh_ids
    
    

    
ids = rs.GetObjects('select objects for mesh area')

total_area = objects_mesh_area(ids)

print total_area

does this make sense?

-Willem

yes it is!!!