Python script that changes geometry of objects in document

Hello,
I am trying in grasshopper to select all the meshes in the Rhino document and check if they are not closed, so that I close them using Rhino.Geometry.Mesh.FillHoles(), the script below runs without errors, but the open meshes in viewport remain open.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import os
import Rhino

sc.doc = Rhino.RhinoDoc.ActiveDoc

for rObj in Rhino.RhinoDoc.ActiveDoc.Objects:
    if(rObj.ObjectType == Rhino.DocObjects.ObjectType.Mesh):
        mesh = rObj.Geometry
        if mesh.IsClosed == False:
            Rhino.Geometry.Mesh.FillHoles(mesh)
            
sc.doc = ghdoc

You fixed the virtual geometry (hopefully) but you didn’t replace the original meshes with holes with the fixed ones. You need to add a sc.doc.Objects.Replace() for each fixed mesh and its original ID. (Not in front of computer right now)

1 Like

Your code looks fine. Do you just have to bake the changes back into the Rhino document, or isn’t that necessary with Rhino.Geometry.Mesh.FillHoles?

1 Like