How to set a gumball from a brep?

Gumball is a transformation widget. And the basis for many transformation is a base plane (e.g. starting location). So the Gumball wants to be oriented to some plane.

A Brep does not necessarily have an obvious plane on which to orient on. So, it might not be easy to come up with a single “SetFromBrep” function that always set it to where you want.

But if you need some example, then perhaps you can use this as a starting place.

Public Shared Function SetFromBrepFace(ByRef gbl As GumballObject, ByVal face As BrepFace) As Boolean
  Dim result As Boolean = False
  If (gb IsNot Nothing AndAlso face IsNot Nothing) Then
    Dim u As Double = face.Domain(0).Mid
    Dim v As Double = face.Domain(1).Mid
    Dim frame As New Plane()
    result = face.FrameAt(u, v, frame)
    If (result = True) Then
      result = gbl.SetFromPlane(frame)
    End If
  End If
  Return result
End Function
1 Like