# My macro to replace ellipses that were converted to curves back to ellipses

Create an ellipse (oval), rotate it 15deg, convert it to curves.

I created this macro to replace the shape with an ellipse but would like to add to it. I'd like to get the angle of rotation of the shape then after the shape is replaced have it rotate it to what it was.

Could probably be streamlined too but beyond my code hacking skills.

Sub ConvertCirclesBack()
Dim sr As ShapeRange, s As Shape
Dim x#, y#, w#, h#, dOffset#
ActiveDocument.BeginCommandGroup ("Convert")
Set sr = ActiveSelectionRange
If sr.Shapes.Count < 1 Then
MsgBox "Select at least one shape"
Exit Sub
End If
Optimization = True
ActiveDocument.Unit = cdrInch
If sr.Count = 0 Then Exit Sub
For Each s In sr
s.GetBoundingBox x, y, w, h
Set s = ActiveLayer.CreateEllipse2(x + w / 2, y + h / 2, w / 2, h / 2)
s.Flip cdrFlipVertical
Next s
sr.Delete
Optimization = False
ActiveWindow.Refresh
ActiveDocument.EndCommandGroup
End Sub

• Create an ellipse (oval), rotate it 15deg, convert it to curves.

If a Curve was created in the way you describe, then it will have four nodes. Some math could be used to use the coordinates of those nodes - or the coordinates of two of those nodes, and also of the center - to figure out the Radius1 and Radius2 values for the new Ellipse, and the angle to which you would need to rotate it. That's just off the top of my head. I haven't given much thought to whether there is any really clever way to do it. I guess one way to do less math would be to create a couple of two-node Curves based on the center and two of the nodes, and then get the lengths and angle from them. You wouldn't have to create actual Curve shapes in the document to do that.

if you only had a few of these to do, it's pretty quick to draw a new Ellipse manually using the 3-Point Ellipse tool, and snapping to the nodes of the existing curve shape.

• Your macro draws an ellipse very similar but not identical to the original
Here is my version of this macro below
There is also a condition that the nodes of the curve must be standard as when converting an ellipse into a curve.

Taras

Sub TV_CirclesBack()
Dim SR As ShapeRange, s As Shape, s1 As Shape, kut As Double
Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
Dim XC As Double, YC As Double, R1 As Double, R2 As Double

ActiveDocument.Unit = cdrMillimeter

Set SR = ActiveSelectionRange

For Each s In SR

XC = s.CenterX
YC = s.CenterY

X1 = s.Curve.Nodes(1).PositionX
Y1 = s.Curve.Nodes(1).PositionY

R1 = Distance(X1, Y1, XC, YC)

X2 = s.Curve.Nodes(2).PositionX
Y2 = s.Curve.Nodes(2).PositionY

R2 = Distance(X2, Y2, XC, YC)

Set s1 = ActiveLayer.CreateLineSegment(X1, Y1, XC, YC)
kut = s1.Curve.Segments(1).StartingControlPointAngle
s1.Delete

Set s1 = ActiveLayer.CreateEllipse2(0, 0, R1, R2)
s1.Rotate kut

s1.CenterX = XC
s1.CenterY = YC
Next s
SR.Delete

End Sub
Function Distance(X1 As Double, Y1 As Double, X2 As Double, Y2 As Double)
Distance = Sqr(Abs(X2 - X1) ^ 2 + Abs(Y2 - Y1) ^ 2)
End Function
{"ft_lang_label":"__label__en","ft_lang_prob":0.8782793,"math_prob":0.92383134,"size":3770,"snap":"2022-27-2022-33","text_gpt3_token_len":972,"char_repetition_ratio":0.1141795,"word_repetition_ratio":0.036363635,"special_character_ratio":0.24774536,"punctuation_ratio":0.13941698,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9840087,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-08-12T09:01:57Z\",\"WARC-Record-ID\":\"<urn:uuid:f0b8d3bb-e876-48f4-b138-b2ebdd703fa0>\",\"Content-Length\":\"149272\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6384e9bd-b4e4-4075-be5f-98a996682f68>\",\"WARC-Concurrent-To\":\"<urn:uuid:9e0dd9e8-cd84-46c5-a893-3505013bf3ee>\",\"WARC-IP-Address\":\"18.210.103.79\",\"WARC-Target-URI\":\"https://community.coreldraw.com/sdk/f/code-snippets-feedback/65044/my-macro-to-replace-ellipses-that-were-converted-to-curves-back-to-ellipses\",\"WARC-Payload-Digest\":\"sha1:XLKGM3LQZS5YBDGMYHXPNWZJAM56AKSM\",\"WARC-Block-Digest\":\"sha1:GCXKS32K7A7Q62QI7YTW3YKRMOB2G5GX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-33/CC-MAIN-2022-33_segments_1659882571597.73_warc_CC-MAIN-20220812075544-20220812105544-00469.warc.gz\"}"}