| McNeel Wiki | |||||
| edit · print · help · all topics | |||||
Main Pages
Languages
| QuestionHow I can obtain the bounding box of a curve object based on a reference plane using VB.NET? AnswerUse the RhinoGetTightBoundingBox SDK function. By default, this function will compute the bounding box of an array of objects in world coordinates. But, if you specify the optional "plane" argument, the bounding box will be computed based on that plane. ExampleThe following example code demonstrates how to calculate the bounding box of a curve object based on a reference plane. RequestPlease add c# version.
' Select a curve object
Dim go As New MRhinoGetObject
go.SetCommandPrompt("Select curve")
go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object)
go.GetObjects(1, 1)
If (go.CommandResult() <> IRhinoCommand.result.success) Then
Return go.CommandResult()
End If
' Validate selection
Dim obj As IRhinoObject = go.Object(0).Object()
If (obj Is Nothing) Then
Return IRhinoCommand.result.failure
End If
' Get the active view
Dim view As MRhinoView = RhUtil.RhinoApp.ActiveView()
If (view Is Nothing) Then
Return IRhinoCommand.result.failure
End If
' Get the active view's construction plane
Dim plane As New OnPlane(view.ActiveViewport().ConstructionPlane().m_plane)
' Compute the tight bounding box of the curve based on the
' active view's construction plane
Dim bbox As New OnBoundingBox
Dim objs(0) As IRhinoObject
objs(0) = obj
Dim rc As Boolean = RhinoGetTightBoundingBox(objs, bbox, False, plane)
If (rc = False) Then
Return IRhinoCommand.result.failure
End If
' Print the min and max box coordinates in world coordinates
Dim min As On3dPoint = bbox.Min()
Dim max As On3dPoint = bbox.Max()
RhUtil.RhinoApp.Print(String.Format("World min: {0},{1},{2}" + vbCrLf, min.x, min.y, min.z))
RhUtil.RhinoApp.Print(String.Format("World max: {0},{1},{2}" + vbCrLf, max.x, max.y, max.z))
' Create a world to construction plane transformation
Dim world_to_plane As New OnXform
world_to_plane.ChangeBasis(plane, OnUtil.On_xy_plane)
' Transform the bounding box
bbox.Transform(world_to_plane)
' Print the min and max box coordinates in cplane coordinates
min = bbox.Min()
max = bbox.Max()
RhUtil.RhinoApp.Print(String.Format("CPlane min: {0},{1},{2}" + vbCrLf, min.x, min.y, min.z))
RhUtil.RhinoApp.Print(String.Format("CPlane max: {0},{1},{2}" + vbCrLf, max.x, max.y, max.z))
| ||||
| rename · changes · history · subscriptions · lost and found · references · file upload | |||||