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
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?
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"; }
If you're doing this like Fane's bounding box example, try this:
<CODE>
Sub outlineAreaFromBoundingBox() Dim sh As ShapeRange, sq As Double, rect As Shape Dim x As Double, y As Double, w As Double, h As Double Application.Unit = cdrMillimeter: ActiveDocument.Unit = cdrMillimeter Set sh = ActiveSelectionRange sh.GetBoundingBox x, y, w, h, True Set rect = ActiveLayer.CreateRectangle2(x, y, w, h) sq = rect.DisplayCurve.Area Debug.Print sq End Sub
</CODE>
You can account for the outline by setting True for the UseOutline parameter on the GetBoundingBox method.
Sorry for no formatting of code.
Sorry i am not clarify what i do it wrong ?
1 2 3 4 5 6 7 8 9 10 11 12 13
private void Button_Click_2(object sender, RoutedEventArgs e) { corel.ShapeRange sh; double sq; corel.Shape rect; double xWay; double x, y, w, h; corelApp.ActiveDocument.Unit = corelApp.ActiveDocument.Rulers.HUnits; sh = corelApp.ActiveSelectionRange; sh = corelApp.ActiveSelectionRange.GetBoundingBox(x, y, w, h, true); rect = corelApp.ActiveLayer.CreateRectangle2(x, y, w, h, 0, 0, 0, 0);
double x =0,y=0,w=0,h=0;
sh = corelApp.ActiveSelectionRange.GetBoundingBox(out x, out y, out w, out h, true);
GetBoundingBox does not return a ShapeRange, so you need to remove the "sh =". Also you just set sh to the ActiveSelectionRange so you should do it like this:
I also declare the variables in the same line, so you would not longer need the double x = 0, y = 0...etc.
Happy Coding,
-Shelby
Many thanks Shelby. It works