Forgive me if this is an easy to find answer, I’m not finding the forum or api searching useful in this case.
I’ve made an object by BooleanUnion’ing multiple rs.AddBox() results and I can still see the coplanar internal edges. From the UI I can select the _MergeAllCoplanarFaces command easily enough, but I’d like to include it in my script instead.
Maybe that’s why I’m confused as well. If you hit run the _MergeAllCoplanarFaces and select the object though, it’ll simplify the isolines–I’m assuming that’s merging the faces/surfaces?
Oh bother, I attached the wrong one. I’ll update.
I downloaded this one and it should have the issue. Here’s a SS of what I’m seeing:
The issue is that you first reference a brep from Rhino, then copy it into memory by coercing it to “become” a Rhino.Geometry.Brep. Now you merge the coplanar faces of this copied brep object, but the one in Rhino remains the same.
What you need to do is bake the merged brep to Rhino and delete the old one:
import rhinoscriptsyntax as rs
import scriptcontext as sc
obj = rs.GetObject()
brep = rs.coercebrep(obj)
success = brep.MergeCoplanarFaces(.001)
sc.doc.Objects.AddBrep(brep) # bake the brep object
sc.doc.Objects.Delete(obj, True) # delete the Rhino brep
sc.doc.Views.Redraw()
You can use sc.doc.Replace(obj_id,brep) instead of add/delete.
Sorry for the rather terse answer, I was on my phone before. Here is some more complete code which uses Replace() and also preserves the original object attributes (color, layer, object name, custom display mode, etc.)
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def TestMergeFaces():
msg="Select a surface or polysurface to merge"
obj_id=rs.GetObject(msg,8+16,preselect=True)
rhobj=rs.coercerhinoobject(obj_id,True,True)
attrs=rhobj.Attributes.Duplicate()
brep=rhobj.Geometry
success=brep.MergeCoplanarFaces(sc.doc.ModelAbsoluteTolerance)
if success:
sc.doc.Objects.Replace(obj_id,brep,attrs)
sc.doc.Views.Redraw()
TestMergeFaces()
Right now I’m trying to keep things simple as I debug issues with other things in the script. I’ll keep this around to beautify the final result though.