Cleaner way of adding/deleting objects to doc.Objects

Hey everyone!

I have a question about clean way of adding/deleting objects from doc, that were selected by the user. I got a list of breps that the user is picking themselves using a command and then the code goes as follows:

        foreach (var obj in go.Objects())
        {
            var brep = obj.Brep();
            if (null == brep) return Result.Failure;
            breps.Add(brep);
        }

        foreach (Brep brep in breps)
        {
            Brep newBrep = brep.DuplicateBrep();
            double targetHeight = optionInteger1.CurrentValue;
            BoundingBox bBox = newBrep.GetBoundingBox(true);
            double currentHeight = GetHeight(newBrep);
            Point3d pointOrigin = new Point3d(bBox.Center.X, bBox.Center.Y, bBox.Min.Z);
            Transform transformationMatrix = Transform.Scale(new Plane(pointOrigin, Vector3d.ZAxis), 1, 1, targetHeight / currentHeight);
            newBrep.Transform(transformationMatrix);
            doc.Objects.AddBrep(newBrep);

        }

        doc.Views.Redraw();
        return Result.Success;

First I change it from extrusions to breps, then scale, add to doc and delete the previous objects. I am thinking, is there a more “clean” way to do so? Like one line method?

You could start by using doc.Objects.Transform
Not a one-liner, you still need to calculate the transform, but still…

https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_DocObjects_Tables_ObjectTable_Transform.htm

1 Like