OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26-03-2017, 00:19
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default 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; 26-03-2017 at 08:47.
Reply With Quote
  #2  
Old 26-03-2017, 13:58
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default 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
Reply With Quote
  #3  
Old 27-03-2017, 01:59
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default

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
Reply With Quote
  #4  
Old 27-03-2017, 06:45
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default 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; 27-03-2017 at 06:48.
Reply With Quote
  #5  
Old 28-03-2017, 02:48
shark shark is offline
Senior Member
 
Join Date: Aug 2010
Location: Russia, Belgorod
Posts: 146
Default 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
Attached Images
 

Last edited by shark; 28-03-2017 at 02:51. Reason: resize picture
Reply With Quote
  #6  
Old 28-03-2017, 08:26
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default 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
Reply With Quote
Reply

Tags
join, lines


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing lines of text knowbodynow CorelDRAW/Corel DESIGNER VBA 1 01-06-2008 10:01
Delete lines ebu CorelDRAW/Corel DESIGNER VBA 0 13-09-2007 12:11
Resizing lines KennyMike General 2 22-01-2007 10:36
a macro for concatenating lines ?? zhuyan166 CorelDRAW/Corel DESIGNER VBA 4 27-05-2006 09:16
width of lines kalic SecuriDesign 3 20-10-2004 17:01


All times are GMT -5. The time now is 11:10.


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