Skip to content

M_Rhino_Geometry_Brep_CreateFromBox

Will Pearson edited this page Aug 12, 2016 · 2 revisions

Brep.CreateFromBox Method (BoundingBox)

Constructs new brep that matches a bounding box.

Namespace: Rhino.Geometry
Assembly: RhinoCommon (in RhinoCommon.dll) Version: Rhino 6.0

Syntax

C#

public static Brep CreateFromBox(
	BoundingBox box
)

VB

Public Shared Function CreateFromBox ( 
	box As BoundingBox
) As Brep

Parameters

 

box
Type: Rhino.Geometry.BoundingBox
A box to use for creation.

Return Value

Type: Brep
A new brep; or null on failure.

Examples

VB

Imports Rhino
Imports Rhino.Geometry
Imports Rhino.Commands
Imports Rhino.Input

Namespace examples_vb
  Public Class BrepFromCurveBBoxCommand
    Inherits Command
    Public Overrides ReadOnly Property EnglishName() As String
      Get
        Return "vbBrepFromCurveBBox"
      End Get
    End Property

    Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
      Dim objref As DocObjects.ObjRef = Nothing
      Dim rc = RhinoGet.GetOneObject("Select Curve", False, DocObjects.ObjectType.Curve, objref)
      If rc <> Result.Success Then
        Return rc
      End If
      Dim curve = objref.Curve()

      Dim view = doc.Views.ActiveView
      Dim plane = view.ActiveViewport.ConstructionPlane()
      ' Create a construction plane aligned bounding box
      Dim bbox = curve.GetBoundingBox(plane)

      If bbox.IsDegenerate(doc.ModelAbsoluteTolerance) > 0 Then
        RhinoApp.WriteLine("the curve's bounding box is degenerate (flat) in at least one direction so a box cannot be created.")
        Return Result.Failure
      End If
      Dim brepbox = Brep.CreateFromBox(bbox)
      doc.Objects.AddBrep(brepbox)
      doc.Views.Redraw()
      Return Result.Success
    End Function
  End Class
End Namespace

C#

using Rhino;
using Rhino.Geometry;
using Rhino.Commands;
using Rhino.Input;
using Rhino.DocObjects;

namespace examples_cs
{
  public class BrepFromCurveBBoxCommand : Command
  {
    public override string EnglishName { get { return "csBrepFromCurveBBox"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      Rhino.DocObjects.ObjRef objref;
      var rc = RhinoGet.GetOneObject("Select Curve", false, ObjectType.Curve, out objref);
      if( rc != Result.Success )
        return rc;
      var curve = objref.Curve();

      var view = doc.Views.ActiveView;
      var plane = view.ActiveViewport.ConstructionPlane();
      // Create a construction plane aligned bounding box
      var bbox = curve.GetBoundingBox(plane);

      if (bbox.IsDegenerate(doc.ModelAbsoluteTolerance) > 0) {
        RhinoApp.WriteLine("the curve's bounding box is degenerate (flat) in at least one direction so a box cannot be created.");
        return Result.Failure;
      }
      var brep = Brep.CreateFromBox(bbox);
      doc.Objects.AddBrep(brep);
      doc.Views.Redraw();
      return Result.Success;
    }
  }
}

Python

import Rhino
from Rhino.Geometry import *
from Rhino.Commands import Result
from Rhino.Input import RhinoGet
from Rhino.DocObjects import ObjectType
import rhinoscriptsyntax as rs
from scriptcontext import doc

def RunCommand():
  rc, objRef = RhinoGet.GetOneObject("Select curve", False, ObjectType.Curve)
  if rc <> Result.Success:
    return rc
  curve = objRef.Curve()
  if None == curve:
    return Result.Failure

  view = doc.Views.ActiveView
  plane = view.ActiveViewport.ConstructionPlane()
  # Create a construction plane aligned bounding box
  bbox = curve.GetBoundingBox(plane)

  if bbox.IsDegenerate(doc.ModelAbsoluteTolerance) > 0:
    print "the curve's bounding box is degenerate (flat) in at least one direction so a box cannot be created."
    return Result.Failure

  brep = Brep.CreateFromBox(bbox)
  doc.Objects.AddBrep(brep)
  doc.Views.Redraw()

  return Result.Success

if __name__ == "__main__":
  print RunCommand()

Version Information

Supported in: 6.0.16224.21491, 5D58w

See Also

Reference

Brep Class
CreateFromBox Overload
Rhino.Geometry Namespace

Clone this wiki locally