I use TextObject. TextGeometry. GetBoundingBox (plane) method to create BoundingBox has some problems.BoundingBox is not the correct border of TextObject.as the picture shows.Is this a bug?
Thank you for all the suggestions.
When you get the bounding box for a piece of geometry, you can specify a transformation. The bounding box component allows you to input a plane, which is used to ChangeBasis or Orient transform which is then used inside the bounding box calculation.
I’m on an iPad right now so can’t do better than that…
I think the order of your planes in the ChangeBasis call is wrong. My own personal mnemonic for ChangeBasis is that it’s always the other way around than you think.
Do note a bounding box itself has no orientation, it’s just two corner points. So if you want to see your box oriented correctly, you’ll have to convert it into a Box3d and transform it back.
code1:
private void RunScript(Guid guid, ref object A)
{
var text = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.TextObject;
if(text != null)
{
BoundingBox empty = BoundingBox.Empty;
var textPlane = text.TextGeometry.Plane;
Transform transform = Transform.ChangeBasis(Plane.WorldXY, textPlane);
var bbox = text.TextGeometry.GetBoundingBox(transform);
empty.Union(bbox);
Box box = new Box(textPlane, new Interval(bbox.Min.X, bbox.Max.X), new Interval(bbox.Min.Y, bbox.Max.Y), new Interval(bbox.Min.Z, bbox.Max.Z));
A = box;
this.Component.ExpireSolution(true);
}
}
code2:
private void RunScript(Guid guid, ref object A)
{
var text = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.TextObject;
if(text != null)
{
A = TextBoundingBox(text);
this.Component.ExpireSolution(true);
}
}
private Rectangle3d TextBoundingBox(Rhino.DocObjects.TextObject text)
{
BoundingBox empty = BoundingBox.Empty;
var textPlane = text.TextGeometry.Plane;
Transform transform = Transform.ChangeBasis(Plane.WorldXY, textPlane);
var curves = text.TextGeometry.Explode();
foreach(var curve in curves)
{
BoundingBox bbox = curve.GetBoundingBox(transform);
empty.Union(bbox);
}
return new Rhino.Geometry.Rectangle3d(textPlane, new Interval(empty.Min.X, empty.Max.X), new Interval(empty.Min.Y, empty.Max.Y));
}