Trying to split a mesh into single undwelded faces

Hi Guys,
I try to split a mesh into single faces. Is there a simple way?
I tried a lot with chatgpt and the documents provided but i failed totally…

this was my last attemp:
I wanted to explode the mesh afterwards…

import rhinoscriptsyntax as rs

import Rhino

mesh = rs.GetObject(“Netz”)

rs.meshedges

Rhino.Geometry.Mesh.Unweld(mesh,0,bool(0))

but i get this:

Rhino.Runtime.Code.Execution.ExecuteException: Object does not match target type.
—> System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Python.Runtime.MethodBinder.Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kwargs, MethodBase methods)
— End of stack trace from previous location —
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PythonException.ThrowIfIsNull(NewReference& ob)
at Python.Runtime.PyModule.Execute(PyObject script, PyDict locals)
at Python.Runtime.RhinoCodePythonEngine.RunScope(Object scope, Object code, String pythonFile, String beforeScript, String afterScript)
at Rhino.Runtime.Code.Languages.PythonNet.CPythonCode.Execute(RunContext context)
at Rhino.Runtime.Code.Code.ExecTry(RunContext context, IPlatformDocument& doc, Object& docState)
at Rhino.Runtime.Code.Code.Run(RunContext context)
— End of inner exception stack trace —
System.Reflection.TargetException: Object does not match target type.
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Python.Runtime.MethodBinder.Invoke(BorrowedReference inst, BorrowedReference args, BorrowedReference kwargs, MethodBase methods)
— End of stack trace from previous location —
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PythonException.ThrowIfIsNull(NewReference& ob)
at Python.Runtime.PyModule.Execute(PyObject script, PyDict locals)
at Python.Runtime.RhinoCodePythonEngine.RunScope(Object scope, Object code, String pythonFile, String beforeScript, String afterScript)
at Rhino.Runtime.Code.Languages.PythonNet.CPythonCode.Execute(RunContext context)
at Rhino.Runtime.Code.Code.ExecTry(RunContext context, IPlatformDocument& doc, Object& docState)
at Rhino.Runtime.Code.Code.Run(RunContext context)

You can unweld the mesh and explode it at the unwelded edges. Here’s a quick GhPython example:


240909_ExplodeMesh_00.gh (9.3 KB)

Note the Dale recently added a new more efficient method for doing the unwelding.

1 Like

Thank you. That should be the same??? Somehow.
But why dos my Mesh does not fit the target type:
image
image
image

It’s hard to say without any files. But I can see you’re calling the unwelding method wrong. You need to call it directly on the mesh you want to unweld, see the script i posted for reference and the docs:

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.mesh/unweld

1 Like

Danke!

Ich habe es anschließend mit ChatGPT 4.0 auf anhieb lösen können… Chat GPT 4 ist auf meinem Arbeitsrechner gesperrt… Juhu…

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def unweld_all_faces(mesh_id):
    # Netz aus der Rhino-Dokumentation abrufen
    mesh = rs.coercemesh(mesh_id)
    
    if not mesh:
        print("Kein Netz gefunden.")
        return
    
    # Das Netz explodieren (d.h. in einzelne Faces zerlegen)
    exploded_meshes = []
    
    for face_index in range(mesh.Faces.Count):
        # Extrahiere jede Face als einzelnes Netz
        single_face_mesh = Rhino.Geometry.Mesh()
        
        # Hole die Eckpunkte der aktuellen Face
        face = mesh.Faces[face_index]
        vertices = [mesh.Vertices[face.A], mesh.Vertices[face.B], mesh.Vertices[face.C], mesh.Vertices[face.D]]
        
        # Füge die Vertices zum neuen Netz hinzu
        for vertex in vertices:
            single_face_mesh.Vertices.Add(vertex)
        
        # Füge die Face zum neuen Netz hinzu (unabhängig von der Anzahl der Punkte)
        if face.IsQuad:
            single_face_mesh.Faces.AddFace(0, 1, 2, 3)  # Quad Face
        else:
            single_face_mesh.Faces.AddFace(0, 1, 2)  # Triangular Face
        
        # Normals, Texturen, Farben usw. können hier auch übertragen werden, falls nötig
        single_face_mesh.Normals.ComputeNormals()
        single_face_mesh.Compact()
        
        # Füge das explodierte Netz zur Liste hinzu
        exploded_meshes.append(single_face_mesh)
    
    # Lösche das ursprüngliche Netz
    rs.DeleteObject(mesh_id)
    
    # Füge die explodierten Netze zur Rhino-Dokumentation hinzu
    for single_mesh in exploded_meshes:
        sc.doc.Objects.AddMesh(single_mesh)
    
    sc.doc.Views.Redraw()
    print(f"{len(exploded_meshes)} Faces erfolgreich unwelded und explodiert.")

def main():
    # Benutzer wählt ein Netz aus
    mesh_id = rs.GetObject("Bitte das Netz auswählen", rs.filter.mesh)
    
    if mesh_id:
        unweld_all_faces(mesh_id)
    else:
        print("Kein Netz ausgewählt.")

# Skript ausführen
main()