how i can calculate in c# the square mm from a graphic?
i think we can create a bounding box outside the selected items, and get the area in mm2
You can use Shape.Curve.Area. But keep in mind - the area of shapes with holes may not be shown correctly.
Can you this explain me more please. Maybe you have a example code?
What do you mean by "bounding box"? Do you need a rectangle to include all shapes area? Do you need the area of all selected shapes outline? In your specific case, the area of the ellipse? Do you need the area of ellipse decreasing the area of the rectangle and the text? Can you better describe your need, please?
Please, try the next ways:
1. The area of the Bounding box:
Sub outlineAreaFromBoundingBox() Dim sh As ShapeRange, sq As Double, rect As Shape Application.Unit = cdrMillimeter: ActiveDocument.Unit = cdrMillimeter Set sh = ActiveSelectionRange Set rect = ActiveLayer.CreateRectangleRect(sh.BoundingBox) sq = rect.DisplayCurve.area: rect.Delete Debug.Print sq End Sub
2.The area of the global selection outline:
Sub OutlineAreaFromWeld() Dim sh As ShapeRange, sq As Double Application.Unit = cdrMillimeter: ActiveDocument.Unit = cdrMillimeter Set sh = ActiveSelectionRange 'weld the selected shapes: Application.FrameWork.Automation.Invoke "416c9d7d-7ca2-4947-92b7-7c4b8191ca2c" sq = ActiveShape.DisplayCurve.area: Debug.Print sq ActiveDocument.Undo End Sub
The Bounding Box is what i looking forBut how i can set the rectangle to absolutely outside of an object? in my case is the rectangle on the middle of the ellipse as example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
private void Button_Click_2(object sender, RoutedEventArgs e) { corel.ShapeRange sh; double sq; corel.Shape rect; corelApp.ActiveDocument.Unit = corelApp.ActiveDocument.Rulers.HUnits; sh = corelApp.ActiveSelectionRange; rect = corelApp.ActiveLayer.CreateRectangleRect(sh.BoundingBox); sq = rect.DisplayCurve.Area/100; //rect.Delete(); // for debug we need it to see it TB_EngravingArea.Text = sq.ToString("N0") + " cm2"; }