The ObjectTable.Add methods add new geometry to the document.
The ObjectTable.Replace methods replace one object with another. Conceptually, this function is the same as calling ObjectTable.Delete and then ObjectTable.Add.
If the intent is to replace existing geometry, then the best practice is to make a copy of the original object’s geometry, modify it, and then call ObjectTable.Replace.
For example:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetObject();
go.SetCommandPrompt("Select polysurface");
go.GeometryFilter = ObjectType.PolysrfFilter;
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
var objref = go.Object(0);
var brep = objref.Brep();
if (null == brep || brep.Faces.Count < 2)
return Result.Failure;
var new_brep = brep.DuplicateBrep();
new_brep.Faces.RemoveAt(0);
new_brep.Compact();
doc.Objects.Replace(objref.ObjectId, new_brep);
doc.Views.Redraw();
return Result.Success;
}
I want to extrude a new solid on a face of a solid, then merge it with the original and replace the original, and make sure the faces are not duplicated.
BrepFace.CreateExtrusion solved the problem to some extent, but also encountered other problems.
But sometimes the Extrusion result will be a Non-Manifold Brep, and I initially tried some methods to fix it, but the results are not very good.
And I found that the Extrusion function that comes with Rhino does not have this problem, that is, the Extrusion function is realized by dragging the Gumbal, and I found that this function handles many details much better than us.
So we hope to directly call the Extusion function that comes with Rhino, but this should not end with a simple CreateExtrusion.
The reason we don’t want to use Gumbal directly is that we want to provide users with a more concise and comfortable operating experience, and Rhino’s own functions are more serious.
If I use Face.CreateExtrusion, I need to deal with a lot of details, but at this time Replace is in effect
If Brep.CreateBooleanUnion is used, there are no details, but Replace is invalid at this time, and the problem at this time is the title of this topic.