Hi all,
I am aiming to close a mesh which due to some previous surface modifications (added approximated patch by blending two separate objects) has a number of small gaps at both ends. A closed mesh is required for the subsequent conversion into a solid SubD geometry and modifications in Grasshopper.
MatchMeshEdge - seems like a request for future work/Beta releases
Could you please advise me on how I can replicate the existing manual _MatchMeshEdge Rhino command in Grasshopper 3D (avoiding to bake the geometry and scripting a customised command via the MacroEditor )
Any GhPython and c# scripting solutions are also welcome.
The gaps are very tiny and manually I am able to close the mesh surface using the following _MatchMeshEdge parameters:
*DistanceToAdjust=0.1
*RatchetMode=On
I have access to the most up-to-date Rhino v6 and Rhino Beta versions.
I look forward to receiving your help/advice.
Thank you,
Ilja
import rhinoscriptsyntax as rs
import Grasshopper
import Rhino
rhdoc = Rhino.RhinoDoc.ActiveDoc
rhdoc.Views.RedrawEnabled = False
rh_mesh = rhdoc.Objects.AddMesh(mesh)
current = rhdoc.Objects.Find(rh_mesh).RuntimeSerialNumber
# Select the mesh at the end of the command, when it is preselected the options are not available
rhdoc.Objects.UnselectAll()
command = """_MatchMeshEdge _DistanceToAdjust 0.1 _RatchetMode=_On _SelId {} _EnterEnd""".format(str(rh_mesh))
rs.Command(command)
new_obj = rhdoc.Objects.AllObjectsSince(current)
if len(new_obj) > 0:
mesh_out = new_obj[0].Geometry.Duplicate()
else:
mesh_out = None
for m in new_obj:
rhdoc.Objects.Purge(m)
rhdoc.Objects.Purge(current)
rhdoc.Views.RedrawEnabled = True
in a GHPython component, where mesh is a GH mesh input, and mesh_out the output when successful.
Technically this is equivalent to baking, running a macro, and deleting the temporary baked geometries, but it’s all automated so I guess it’s not really an issue. You could also parametrize the DistanceToAdjust parameter by adding an input to the GHPython component and feeding that to the command through .format().
I’m hoping to reactivate this topic. I’d really love to access to MatchMeshEdge in GH. Does anybody know of any updates or is aware of a working script in Grasshopper (Rhino Version 7 SR29)?
Thank you for looking at this @pierrec . I tried to copy/paste the script into GhPython node, but failing to get any result? Could you show how this can be implemented in GhPython component? I’ve attached a simple GH definition with internalized STL model that is open.
That script you copied was meant to be run from the Rhino script editor, not from Grasshopper. Here is a version that is more compatible with Grasshopper:
import rhinoscriptsyntax as rs
import Rhino
def test_match_mesh_edges(mesh):
meshobj = rs.coercemesh(mesh)
if not meshobj:
return None
mcopy = meshobj.DuplicateMesh()
distance = 0.1
rachet = True
rc = mcopy.MatchEdges(distance, rachet)
if rc:
rs.Redraw()
return mcopy
return None
mesh_out = test_match_mesh_edges(mesh)
Thanks so much for following up to this request. I feel like I’m missing something obvious here, but the provided Python script returns null. I set the input/output names to match your script and assigned Mesh as the input hint, any idea what I might be missing? I attached a screenshot.
if the input mesh has no edges to match, the result will be null, I guess that’s what’s happening in your case. If you always want a mesh to be returned, you could replace return none by return mesh
Very nice to see this added! I used to find use with it to fix meshes generated from textures in a nurbs/mesh mix workflow working downstream to watertight parts. I don’t have use for it anymore, but nice to know if I go back then I could!