Rhino python script to Weld / Unweld Mesh

Hi there,

I’m new in scripting Rhino via Python and I’d like to ask you a question.

I have a problem with Unweld / Weld Mesh, I need to select lot of geometries in Rhino and then with Python script process them all. Scrip works (I mean, it can explode or hide geometries) but when it comes to Unweld mesh it doesn’t do nothing and I don’t know where is the problem

this is my code

import rhinoscriptsyntax as rs
import Rhino.Geometry.Mesh as rgm

meshObjects = rs.GetObjects("Pick meshes you want to process", rs.filter.mesh)

for mesh in meshObjects: 
    rs.SelectObject(mesh)
    toHide = rs.InvertSelectedObjects()
    rs.HideObjects(toHide)
    
    selMesh = rs.coercemesh(mesh)
    rgm.Unweld(selMesh, 0, True)

and after that nothing is happening, I can see that Mesh is not unwelded

What am I doing wrong ? thanks ofr any help :slight_smile:

Hi @Andrzej_Zuzański,

Does this work any better?

import Rhino
import scriptcontext as sc

def test_unweld():
    filter = Rhino.DocObjects.ObjectType.Mesh
    rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select polygon meshes to unweld", False, filter)
    if rc != Rhino.Commands.Result.Success:
        return
    if not objrefs: 
        return
    
    degrees = 10.0
    rc, degrees = Rhino.Input.RhinoGet.GetNumber("Angle tolerance", False, degrees)
    if rc != Rhino.Commands.Result.Success:
        return
        
    radians = Rhino.RhinoMath.ToRadians(degrees)
    
    for objref in objrefs:
        old_mesh = objref.Mesh()
        if old_mesh:
            new_mesh = old_mesh.DuplicateMesh()
            new_mesh.Unweld(radians, True)
            new_mesh.Compact()
            sc.doc.Objects.Replace(objref, new_mesh)
    
    sc.doc.Views.Redraw()
    
if __name__=="__main__":
    test_unweld()

– Dale

It works perfect, thank you very much Dale