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 *
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)
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?
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
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.