
#1




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. Last edited by nic; 26032017 at 08:47. 
#2




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. Code:
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 sr.RemoveAll 
#3




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

#4




Yep!
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 nic Last edited by nic; 27032017 at 06:48. 
#5




Found some free time
Code:
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 Last edited by shark; 28032017 at 02:51. Reason: resize picture 
#6




Thanks
Thanks shark  really
Its not just that it solves this problem but it makes me understand it better and with error checking too! Appreciated nic 
Tags 
join, lines 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)  
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Removing lines of text  knowbodynow  CorelDRAW/Corel DESIGNER VBA  1  01062008 10:01 
Delete lines  ebu  CorelDRAW/Corel DESIGNER VBA  0  13092007 12:11 
Resizing lines  KennyMike  General  2  22012007 10:36 
a macro for concatenating lines ??  zhuyan166  CorelDRAW/Corel DESIGNER VBA  4  27052006 09:16 
width of lines  kalic  SecuriDesign  3  20102004 17:01 