public RhinoGetTransform() : base()
 {
     m_list  = new MRhinoXformObjectList();
     m_xform = new OnXform();
     m_xform.Identity();
     m_bHaveXform = false;
     m_base       = new On3dPoint();
     m_base.Set(0, 0, 0);
 }
 public RhinoGetTransform()
     : base()
 {
     m_list = new MRhinoXformObjectList();
       m_xform = new OnXform();
       m_xform.Identity();
       m_bHaveXform = false;
       m_base = new On3dPoint();
       m_base.Set(0,0,0);
 }
Example #3
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select object to move");
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointFrom = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(pointFrom);
            gp.DrawLineFromPoint(pointFrom, true);
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointTo = gp.Point();

            On3dVector dir = new On3dVector(pointTo - pointFrom);

            if (dir.IsTiny())
            {
                return(IRhinoCommand.result.nothing);
            }

            OnXform xform = new OnXform();

            xform.Translation(dir);

            MRhinoObjRef objectRef = go.Object(0);

            context.m_doc.TransformObject(ref objectRef, xform);
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
        public override bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform)
        {
            bool       bResult = false;
            On3dVector v       = new On3dVector();
            On3dPoint  pt      = new On3dPoint(point);

            v = pt - m_base;
            if (!v.IsZero())
            {
                xform.Translation(v);
                bResult = xform.IsValid();
            }
            return(bResult);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to move");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoXformObjectList list = new MRhinoXformObjectList();

            if (list.AddObjects(go, true) < 1)
            {
                return(IRhinoCommand.result.failure);
            }

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            RhinoGetTranslation gt = new RhinoGetTranslation();

            gt.SetCommandPrompt("Point to move to");
            gt.AppendObjects(list);
            gt.SetBasePoint(gp.Point());
            gt.DrawLineFromPoint(gp.Point(), true);
            gt.GetXform();
            if (gt.CommandResult() != IRhinoCommand.result.success)
            {
                return(gt.CommandResult());
            }

            OnXform xform = new OnXform();

            if (gt.CalculateTransform(gt.View().ActiveViewport(), gt.Point(), ref xform))
            {
                // TODO: do object transformation here.
            }

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select object to move");
              go.EnableSubObjectSelect(false);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Point to move from");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint pointFrom = gp.Point();

              gp.SetCommandPrompt("Point to move to");
              gp.SetBasePoint(pointFrom);
              gp.DrawLineFromPoint(pointFrom, true);
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint pointTo = gp.Point();

              On3dVector dir = new On3dVector(pointTo - pointFrom);
              if (dir.IsTiny())
            return IRhinoCommand.result.nothing;

              OnXform xform = new OnXform();
              xform.Translation(dir);

              MRhinoObjRef objectRef = go.Object(0);
              context.m_doc.TransformObject(ref objectRef, xform);
              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
 /////////////////////////////////////////////////////////////////////////
 // STEP 4: Override this abstract function to provide your own custom
 //         transformation method. Call this function to retrieve
 //         the final transformation.
 public abstract bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform);
 public override bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform)
 {
     bool bResult = false;
       On3dVector v = new On3dVector();
       On3dPoint pt = new On3dPoint(point);
       v = pt - m_base;
       if (!v.IsZero())
       {
     xform.Translation(v);
     bResult = xform.IsValid();
       }
       return bResult;
 }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to move");
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              MRhinoXformObjectList list = new MRhinoXformObjectList();
              if (list.AddObjects(go, true) < 1)
            return IRhinoCommand.result.failure;

              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Point to move from");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              RhinoGetTranslation gt = new RhinoGetTranslation();
              gt.SetCommandPrompt("Point to move to");
              gt.AppendObjects(list);
              gt.SetBasePoint(gp.Point());
              gt.DrawLineFromPoint(gp.Point(), true);
              gt.GetXform();
              if (gt.CommandResult() != IRhinoCommand.result.success)
            return gt.CommandResult();

              OnXform xform = new OnXform();
              if (gt.CalculateTransform(gt.View().ActiveViewport(), gt.Point(), ref xform))
              {
            // TODO: do object transformation here.
              }

              return IRhinoCommand.result.success;
        }
 /////////////////////////////////////////////////////////////////////////
 // STEP 4: Override this abstract function to provide your own custom
 //         transformation method. Call this function to retrieve
 //         the final transformation.
 public abstract bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform);
Example #11
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.EnableReferenceObjectSelect(false);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect(true);
            // Phantoms, grips, lights, etc., cannot be in instance definitions.
            uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                                    );
            uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;

            go.SetGeometryFilter(geometry_filter);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Step 2, select base point
            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Block base point");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint base_point = gp.Point();

            // Step 3, get instance definition name
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Block definition name");
            gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

            string idef_name = gs.String().Trim();

            if (string.IsNullOrEmpty(idef_name))
            {
                return(IRhinoCommand.result.nothing);
            }

            // Step 4, verify objects
            int found_index             = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
            List <IRhinoObject> objects = new List <IRhinoObject>();

            bool bQuietly = context.IsInteractive() ? false : true;

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IRhinoObject obj = go.Object(i).Object();
                if (obj == null)
                {
                    continue;
                }

                // Probably don't need to do this...
                if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
                {
                    continue;
                }

                if (obj.ObjectType() == IOn.object_type.instance_reference)
                {
                    IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
                    if (iref_obj != null)
                    {
                        if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
                        {
                            if (!bQuietly)
                            {
                                RhUtil.RhinoApp().Print("Unable to create block.\n");
                            }
                            return(IRhinoCommand.result.failure);
                        }
                    }
                }
                objects.Add(obj);
            }

            // Step 5, create instance definition
            OnInstanceDefinition idef = new OnInstanceDefinition();

            idef.SetName(idef_name);

            int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);

            if (idef_index < 0)
            {
                return(IRhinoCommand.result.failure);
            }

            // Step 6, create the instance reference
            OnXform xform = new OnXform();

            xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
            IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);

            if (inst_obj != null)
            {
                inst_obj.Select(true);
            }
            else
            {
                if (!bQuietly)
                {
                    RhUtil.RhinoApp().Print("Error creating block.\n");
                }
                return(IRhinoCommand.result.failure);
            }

            // Step 7, delete existing geometry
            for (int i = 0; i < objects.Count; i++)
            {
                context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Example #12
0
        int CreateInstanceDefinition(MRhinoDoc doc, IOnInstanceDefinition idef, IOn3dPoint point, List <IRhinoObject> objects, bool bQuietly)
        {
            int found_index = doc.m_instance_definition_table.FindInstanceDefinition(idef.Name(), true);
            List <IRhinoObject> idef_objects = new List <IRhinoObject>();

            OnXform xform = new OnXform();

            xform.Translation(new On3dPoint(OnUtil.On_origin) - point);

            for (int i = 0; i < objects.Count; i++)
            {
                IRhinoObject obj = objects[i];
                if (obj == null)
                {
                    continue;
                }

                if (obj.ObjectType() == IOn.object_type.light_object ||
                    obj.ObjectType() == IOn.object_type.grip_object ||
                    obj.ObjectType() == IOn.object_type.phantom_object
                    )
                {
                    continue;
                }

                // Transform geometry and attributes, but do not add to the document
                MRhinoObject dupe = doc.TransformObject(obj, xform, false, false, false);
                if (dupe != null)
                {
                    if (doc.AddObject(dupe, false, true))
                    {
                        idef_objects.Add(dupe);
                    }
                }
            }

            if (idef_objects.Count < 1)
            {
                return(-1);
            }

            int idef_index = -1;

            if (found_index < 0)
            {
                idef_index = doc.m_instance_definition_table.AddInstanceDefinition(idef, idef_objects.ToArray(), false, bQuietly);
            }
            else if (doc.m_instance_definition_table.ModifyInstanceDefinitionGeometry(found_index, idef_objects.ToArray(), bQuietly))
            {
                idef_index = found_index;
                doc.m_instance_definition_table.ModifyInstanceDefinition(idef, idef_index, (uint)IDEF_SETTINGS.all_idef_settings, bQuietly);

                if (!bQuietly)
                {
                    IRhinoInstanceObject[] iref_object_list = null;
                    int iref_count = doc.m_instance_definition_table[found_index].GetReferences(out iref_object_list);
                    if (iref_count > 0)
                    {
                        RhUtil.RhinoApp().Print(string.Format("{0} Instances of block \"{1}\" have been updated.\n", iref_count, idef.Name()));
                    }
                }
            }

            if (idef_index < 0 && !bQuietly)
            {
                string message = (found_index < 0) ? "Error creating block.\n" : "Error modifying block.\n";
                RhUtil.RhinoApp().Print(message);
            }

            return(idef_index);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to define block");
              go.EnableReferenceObjectSelect(false);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect(true);
              // Phantoms, grips, lights, etc., cannot be in instance definitions.
              uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                              );
              uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;
              go.SetGeometryFilter(geometry_filter);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Step 2, select base point
              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Block base point");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint base_point = gp.Point();

              // Step 3, get instance definition name
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Block definition name");
              gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

              string idef_name = gs.String().Trim();
              if (string.IsNullOrEmpty(idef_name))
            return IRhinoCommand.result.nothing;

              // Step 4, verify objects
              int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
              List<IRhinoObject> objects = new List<IRhinoObject>();

              bool bQuietly = context.IsInteractive() ? false : true;

              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IRhinoObject obj = go.Object(i).Object();
            if (obj == null)
              continue;

            // Probably don't need to do this...
            if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
              continue;

            if (obj.ObjectType() == IOn.object_type.instance_reference)
            {
              IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
              if (iref_obj != null)
              {
            if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
            {
              if (!bQuietly)
                RhUtil.RhinoApp().Print("Unable to create block.\n");
              return IRhinoCommand.result.failure;
            }
              }
            }
            objects.Add(obj);
              }

              // Step 5, create instance definition
              OnInstanceDefinition idef = new OnInstanceDefinition();
              idef.SetName(idef_name);

              int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);
              if (idef_index < 0)
            return IRhinoCommand.result.failure;

              // Step 6, create the instance reference
              OnXform xform = new OnXform();
              xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
              IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);
              if (inst_obj != null)
              {
            inst_obj.Select(true);
              }
              else
              {
            if (!bQuietly)
              RhUtil.RhinoApp().Print("Error creating block.\n");
            return IRhinoCommand.result.failure;
              }

              // Step 7, delete existing geometry
              for (int i = 0; i < objects.Count; i++)
            context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
        int CreateInstanceDefinition(MRhinoDoc doc, IOnInstanceDefinition idef, IOn3dPoint point, List<IRhinoObject> objects, bool bQuietly)
        {
            int found_index = doc.m_instance_definition_table.FindInstanceDefinition(idef.Name(), true);
              List<IRhinoObject> idef_objects = new List<IRhinoObject>();

              OnXform xform = new OnXform();
              xform.Translation(new On3dPoint(OnUtil.On_origin) - point);

              for (int i = 0; i < objects.Count; i++)
              {
            IRhinoObject obj = objects[i];
            if (obj == null)
              continue;

            if (obj.ObjectType() == IOn.object_type.light_object ||
            obj.ObjectType() == IOn.object_type.grip_object ||
            obj.ObjectType() == IOn.object_type.phantom_object
              )
              continue;

            // Transform geometry and attributes, but do not add to the document
            MRhinoObject dupe = doc.TransformObject(obj, xform, false, false, false);
            if (dupe != null)
            {
              if (doc.AddObject(dupe, false, true))
            idef_objects.Add(dupe);
            }
              }

              if (idef_objects.Count < 1)
            return -1;

              int idef_index = -1;

              if (found_index < 0)
            idef_index = doc.m_instance_definition_table.AddInstanceDefinition(idef, idef_objects.ToArray(), false, bQuietly);
              else if (doc.m_instance_definition_table.ModifyInstanceDefinitionGeometry(found_index, idef_objects.ToArray(), bQuietly))
              {
            idef_index = found_index;
            doc.m_instance_definition_table.ModifyInstanceDefinition(idef, idef_index, (uint)IDEF_SETTINGS.all_idef_settings, bQuietly);

            if (!bQuietly)
            {
              IRhinoInstanceObject[] iref_object_list = null;
              int iref_count = doc.m_instance_definition_table[found_index].GetReferences(out iref_object_list);
              if (iref_count > 0)
            RhUtil.RhinoApp().Print(string.Format("{0} Instances of block \"{1}\" have been updated.\n", iref_count, idef.Name()));
            }
              }

              if (idef_index < 0 && !bQuietly)
              {
            string message = (found_index < 0) ? "Error creating block.\n" : "Error modifying block.\n";
            RhUtil.RhinoApp().Print(message);
              }

              return idef_index;
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Validate the selection
            IRhinoObject obj = go.Object(0).Object();

            if (null == obj)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the active view
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the construction plane from the active view
            OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

            // Create a construction plane aligned bounding box
            OnBoundingBox bbox = new OnBoundingBox();

            IRhinoObject[] objs = new IRhinoObject[1] {
                obj
            };
            bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);

            if (rc == false)
            {
                return(IRhinoCommand.result.failure);
            }

            // Validate bounding box
            if (0 != bbox.IsDegenerate())
            {
                RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
                return(IRhinoCommand.result.nothing);
            }

            // ON_BrepBox wants 8 points defining the box corners
            // arranged in this order:
            //
            //          v7______________v6
            //           |\             |\
            //           | \            | \
            //           |  \ _____________\ 
            //           |   v4         |   v5
            //           |   |          |   |
            //           |   |          |   |
            //          v3---|---------v2   |
            //           \   |          \   |
            //            \  |           \  |
            //             \ |            \ |
            //              \v0____________\v1
            //
            On3dPoint[] box_corners = new On3dPoint[8];
            box_corners[0] = bbox.Corner(0, 0, 0);
            box_corners[1] = bbox.Corner(1, 0, 0);
            box_corners[2] = bbox.Corner(1, 1, 0);
            box_corners[3] = bbox.Corner(0, 1, 0);
            box_corners[4] = bbox.Corner(0, 0, 1);
            box_corners[5] = bbox.Corner(1, 0, 1);
            box_corners[6] = bbox.Corner(1, 1, 1);
            box_corners[7] = bbox.Corner(0, 1, 1);

            // Transform points to the world-xy plane
            OnXform p2w = new OnXform();

            p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
            for (int i = 0; i < 8; i++)
            {
                box_corners[i].Transform(p2w);
            }

            // Make a brep box
            OnBrep brep = OnUtil.ON_BrepBox(box_corners);

            if (null != brep)
            {
                context.m_doc.AddBrepObject(brep);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select curve");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Validate the selection
              IRhinoObject obj = go.Object(0).Object();
              if (null == obj)
            return IRhinoCommand.result.failure;

              // Get the active view
              MRhinoView view = RhUtil.RhinoApp().ActiveView();
              if (null == view)
            return IRhinoCommand.result.failure;

              // Get the construction plane from the active view
              OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

              // Create a construction plane aligned bounding box
              OnBoundingBox bbox = new OnBoundingBox();
              IRhinoObject[] objs = new IRhinoObject[1] { obj };
              bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);
              if (rc == false)
            return IRhinoCommand.result.failure;

              // Validate bounding box
              if (0 != bbox.IsDegenerate())
              {
            RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
            return IRhinoCommand.result.nothing;
              }

              // ON_BrepBox wants 8 points defining the box corners
              // arranged in this order:
              //
              //          v7______________v6
              //           |\             |\
              //           | \            | \
              //           |  \ _____________\
              //           |   v4         |   v5
              //           |   |          |   |
              //           |   |          |   |
              //          v3---|---------v2   |
              //           \   |          \   |
              //            \  |           \  |
              //             \ |            \ |
              //              \v0____________\v1
              //
              On3dPoint[] box_corners = new On3dPoint[8];
              box_corners[0] = bbox.Corner(0, 0, 0);
              box_corners[1] = bbox.Corner(1, 0, 0);
              box_corners[2] = bbox.Corner(1, 1, 0);
              box_corners[3] = bbox.Corner(0, 1, 0);
              box_corners[4] = bbox.Corner(0, 0, 1);
              box_corners[5] = bbox.Corner(1, 0, 1);
              box_corners[6] = bbox.Corner(1, 1, 1);
              box_corners[7] = bbox.Corner(0, 1, 1);

              // Transform points to the world-xy plane
              OnXform p2w = new OnXform();
              p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
              for (int i = 0; i < 8; i++)
            box_corners[i].Transform(p2w);

              // Make a brep box
              OnBrep brep = OnUtil.ON_BrepBox(box_corners);
              if (null != brep)
              {
            context.m_doc.AddBrepObject(brep);
            context.m_doc.Redraw();
              }

              return IRhinoCommand.result.success;
        }