Fixing mesh's ith python

Does anyone know a way to fix holes/close a mesh automatically in python? I can’t find a way to get started so anything would be appreciated.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Mesh_FillHoles.htm

I see results for c# and vb but not for python. I need a method of doing this in python

Hi @kieganlenihan, Python in Rhino (IronPython) is calling RhinoCommon methods under the hood. So you can use C# code examples in some manner. For above it would look like this in Python:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    mesh_id = rs.GetObject("Mesh", rs.filter.mesh, True, False)
    if not mesh_id: return
    
    mesh = rs.coercemesh(mesh_id, True)
    rc = mesh.FillHoles()
    if not rc: return
    
    scriptcontext.doc.Objects.Replace(mesh_id, mesh)
    scriptcontext.doc.Views.Redraw()
    
DoSomething()

You might try it first on a simple mesh sphere with some removed faces to understand how it fills holes. I do not think that you get the expected result when looking at your example image.

Holes like this are better closed in apps like MeshMixer or if you want to have something more Rhino related try TriangleMeshCompleter.

_
c.

Yes this sort of thing is what I’m looking for. Is there a way to use this tool for Mac?

Hi @kieganlenihan, TriangleMeshCompleter seems to be a Rhino PlugIn which requires some windows specific libraries. MeshMixer is available for free (win + mac).

If you only need this mesh done, you might post it and i’ll try to close it.

_
c.

Thanks, I appreciate that. I already know how to extract naked edges and turn it into a polyline. So I want to be able to close that polyline as a surface and thus close the mesh. And it needs to be done automatically, so more than this mesh is needed.

This approach might work for you:

Thanks @AndersDeleuran. I am getting an error in your script however that says “Before Solution Exception: Index Too high”. Any idea why this is?

Sorry ignore that last bit. It worked! I now have a filledHole surface, but how do I union it with the original mesh?

You can .append() the new meshes onto the input mesh during the loop. Or join the meshes downstream using the standard Grasshopper mesh join component.

Oh of course, thanks! Is there a python command that mimic’s the join mesh’s command in grasshopper? Just to keep everything in the python script?

Use Rhinocommon. It will be mesh.append(othermesh) as @AndersDeleuran wrote.

1 Like

OK DUH, that was dumb of me-sorry the brain is a bit off. OK I do have another question though. Before I fill in holes of a mesh, I want to prep the mesh in a few ways, that includes the following commands:
ExtractDuplicateMeshFaces
UnifyMeshNormals
SplitDisjointMesh

But each of these present a unique problem. For UnifyMeshNormals, the command returns the number of faces that were modified, but what I want it to return is a unified mesh. For instance, I want to write the line:
Unified = rs.UnifyMeshNormals(obj) where the variable Unified is a unified mesh, not the number of modified faces. How do I do this?

Similarly, I want to use ExtractNonManifoldEdges to delete all of the hanging faces. With SplitDisjointPieces, I want to delete all of the disjointed pieces.

What are the best ways to do this?

The unify mesh normals method does not require you to declare the mesh as =. You just write

yourMesh.UnifyMeshNormals()

As you are not making something new, you are just changing the existing.

Ok I see, thank you!

Ok so when I type mymesh.UnifyMeshNormals, I get an error saying that the mesh has no attribute called that?

Kiegan

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Mesh_UnifyNormals.htm

Just follow Rhinocommon. It is UnifyNormals. Not UnifyMeshNormals.

yourMesh.UnifyNormals()