OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Join two lines by adding straight lines and closing (http://forum.oberonplace.com/showthread.php?t=24784)

nic 26-03-2017 00:19

Join two lines by adding straight lines and closing
I have a macro that draws two non crossing curved lines as two seperate coreldraw shapes from data and want to join the two starting nodes and the last two nodes of the two lines by adding straight lines and then closing the resulting curve. The method of drawing the original lines prevents simply drawing a closed shape: As in order to keep the curve correct at start and finish a longer curve is drawn and then nodes are removed from the ends.

Any advice on how best to go about this would be appreciated - Please forgive that I havn't shown any of my attempts at doing this, trying to keep a little dignity.:banghead:

nic 26-03-2017 13:58

works - not pretty
Managed to blunder way through - mainly using answers from this forum

Using the xy coordinates of nodes at the ends of the lines; added new lines, added all to a shaperange and joined overlapping nodes.


sr.Add sShape
sr.Add sShape2
    Set n1 = sShape.Curve.Nodes.Last
    Set n2 = sShape.Curve.Nodes.First
    Set n3 = sShape2.Curve.Nodes.First
    Set n4 = sShape2.Curve.Nodes.Last
    a = n1.PositionX
    b = n1.PositionY
    c = n2.PositionX
    d = n2.PositionY
    e = n3.PositionX
    f = n3.PositionY
    g = n4.PositionX
    h = n4.PositionY
    Set crv = CreateCurve(ActiveDocument)
    Set sp = crv.CreateSubPath(a, b)
    sp.AppendCurveSegment e, f
    Set sShape3 = ActiveLayer.CreateCurve(crv)
    sr.Add sShape3
    Set crv = CreateCurve(ActiveDocument)
    Set sp = crv.CreateSubPath(c, d)
    sp.AppendCurveSegment g, h
    Set sShape4 = ActiveLayer.CreateCurve(crv)
    sr.Add sShape4
    Set s = sr.Combine
    s.CustomCommand "ConvertTo", "JoinCurves", 0.01

shark 27-03-2017 01:59

I think all this can be done much easier. First, you must get start/end nodes of each shapes (A_start, A_end, B_start, B_end). Then combine/weld two shapes to one curve. After this use, for example, A_start.ConnectWith B_start and A_end.ConnectWith B_end to connect this nodes

nic 27-03-2017 06:45

Hi Shark
Im sure you are right about it could be done more easily. Your idea is the way to go but once the shapes are combined the references to the nodes seem to fail with - "Node belongs to another shape".
It's working (8+ hours of guessing) and I cant justify the time ld take to make it more elegant.
Thanks again

shark 28-03-2017 02:48

Found some free time
1 Attachment(s)

Private Sub JoinNodes()
Dim s As Shape, sr As ShapeRange
Dim x1#, y1#, x2#, y2#
    Set sr = ActiveSelectionRange
    If sr.Count <> 2 Then MsgBox "Select 2 shapes!": Exit Sub
    If sr(1).Curve.Closed Or sr(2).Curve.Closed Then MsgBox "Shapes must be unclosed!": Exit Sub
    sr(1).Curve.Nodes(1).GetPosition x1, y1
    sr(2).Curve.Nodes(1).GetPosition x2, y2
    Set s = sr(1).Weld(sr(2))
    s.Curve.FindNodeAtPoint(x1, y1).ConnectWith s.Curve.FindNodeAtPoint(x2, y2)
    s.Curve.Closed = True 'Connect the remaining nodes
End Sub

nic 28-03-2017 08:26

Thanks shark - really
Its not just that it solves this problem but it makes me understand it better and with error checking too!

All times are GMT -5. The time now is 12:51.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com