How to use Rhino.Geometry.Mesh.QuadRemesh?

Hi all,

I’m new to Rhino and I would like to run QuadRemesh from python instead of the UI.

I am struggling with running the following code:

import Rhino
from pprint import pprint
import rhinoscriptsyntax as rs

# Define parameters

parameters = {
    'AdaptiveQuadCount': True, 
    'AdaptiveSize': 50.0, 
    'DetectHardEdges': True, 
    'GuideCurveInfluence': 0, 
    'PreserveMeshArrayEdgesMode': 0, 
    'SymmetryAxis': Rhino.Geometry.QuadRemeshSymmetryAxis.None, 
    'TargetQuadCount': 2000,
}

quad_mesh_parameters = Rhino.Geometry.QuadRemeshParameters()

for param_name, value in sorted(parameters.items()):
    setattr(quad_mesh_parameters, param_name, value)
    print("{}: {}".format(param_name, getattr(quad_mesh_parameters, param_name)))
print()

# Run QuadRemesh with parameters

rs.EnableRedraw(False)
for obj in Rhino.RhinoDoc.ActiveDoc.Objects:
    if obj.IsNormal:
        
        Rhino.RhinoDoc.ActiveDoc.Objects.Select(obj.Id, True)
        print('Select Object ID', obj.Id)
        print("Selected Status", obj.IsSelected(obj))
        
        print('start remesh')
        new_mesh = obj.Geometry.QuadRemesh(quad_mesh_parameters)
        print('end remesh')
        
rs.EnableRedraw(True)

I see no change in the model after running this.

Besides, another weird prompt appears
image

@Trav can you help?

Hi Clem,

Here’s a python example you can start with at the link below.

1 Like

That worked!
Thank you so much Travis.

The below code snippet applies QuadRemesh on all objects:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext

parameters = {
    'AdaptiveQuadCount': True, 
    'AdaptiveSize': 50.0, 
    'DetectHardEdges': True, 
    'GuideCurveInfluence': 0, 
    'PreserveMeshArrayEdgesMode': 0, 
    'SymmetryAxis': Rhino.Geometry.QuadRemeshSymmetryAxis.X | Rhino.Geometry.QuadRemeshSymmetryAxis.Y | Rhino.Geometry.QuadRemeshSymmetryAxis.Z, 
    'TargetQuadCount': 2000,
}

def QuadRemesh(parameters):
    
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh
    go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve
    go.SetCommandPrompt("Select Mesh to QuadRemesh")
    go.Get()
    if(go.CommandResult() != Rhino.Commands.Result.Success):
        return go.CommandResult()

    mesh = go.Object(0).Mesh()

    qr_params = Rhino.Geometry.QuadRemeshParameters()
    
    if parameters:
        for param_name, value in sorted(parameters.items()):
            setattr(qr_params, param_name, value)
            print("{}: {}".format(param_name, getattr(qr_params, param_name)))
        print
    
    remeshed = mesh.QuadRemesh(qr_params)
    
    scriptcontext.doc.ActiveDoc.Objects.Add(remeshed)
    scriptcontext.doc.ActiveDoc.Views.Redraw

    return Rhino.Commands.Result.Success

for obj in Rhino.RhinoDoc.ActiveDoc.Objects:
    if obj.IsNormal:
        
        Rhino.RhinoDoc.ActiveDoc.Objects.Select(obj.Id, True)
        print 'Select Object ID', obj.Id
        
        QuadRemesh(parameters)
1 Like