Moving Brep vertices works only halfway and leaves wireframe behind

I’m writing a script which involves moving the vertices of a Brep and replacing the resulting Brep in the document.

However, it seems like it only works half-way, which appears in shaded mode, but the wireframe of the object stays in place. Also, this doesn’t appear immediately upon execution of the script, but only after navigating the view.

Simplified script and result are below. Does anyone have an idea why this happens or how to complete the replacement?

from scriptcontext import doc
import rhinoscriptsyntax as rs
from Rhino.Geometry import *

def moveVerts():
    obj = rs.GetObject("Select object")
    
    objBrep = rs.coercebrep(obj)
    verts = objBrep.Vertices
    
    moveDist = rs.GetReal("Enter the move distance of vertices",0)
    
    for vert in verts:
        x, y, z = [c + moveDist for c in vert.Location]
        vert.Location = Point3f(x,y,z)
    
    doc.Objects.Replace(obj, objBrep)
    
moveVerts()
1 Like

pretty sure you need to update the preview mesh

ok I tried with doc.Views.Redraw() and that does update it immediately without navigating the view, but the main issue of the replacement working halfway is still there. Or were you referring to something else?

no, I was refering to this. I thought I had some issues some time ago with c# and had to recalculate the preview mesh. However, I didn’t find any python command related to this except doc.Views.Redraw().

Did you try and add the brep instead of replacing? do you encounter the same problem?

Did you try and add the brep instead of replacing? do you encounter the same problem?

Yep, just tried. Same issue. I don’t know if I’m supposed to update the other components of the Breps to the new vertices somehow.

In another test, if I run the script on a single surface, nothing at all seems to happen.

Moving a vertex (= a point where edges end) in a Brep only changes that vertex, not the edges attached to it nor the surfaces on which the edges are defined. What you end up with here is a Brep with very large tolerances on the vertices, that Rhino tries to render as best as it can.

If you want to manually edit a Brep, a more natural way is to deform its surfaces, then recompute the new edges locations from the trims (which are unchanged), and vertices at the end of the edges. Have a look at this page for more info onthe relationships between these components: Rhino - Brep Data Structure

For something automated where modifying vertices will transform the rest of the Brep, you can try the Brep.TransformComponents method.

2 Likes

Thanks! I got the TransformComponents method to work in simple cases. But in some cases it was resulting in extreme deformations, and I don’t know why.

I may have to explore a different strategy.

Hi @famak2,

Brep.TransformComponents is based on the same code as the Rhino solid deformation tools (i.e. using SolidPtOn and moving vertices), which sometimes give very unexpected results. You can find examples of this on Discourse, for example:

If you find other issues, please report them on this forum with a simplified copy of your 3dm files and I’ll try to fix the bug or find a workaround.

1 Like