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 22-09-2014, 09:19
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Virtual shape and speed up

Hi,
the code below takes the data from an array and draws a curved line through a set of x,y points. I would like to speed up that process and think doing it with a virtual layer would help but I can't get the syntax right. Where would i need to insert ActiveVirtualLayer and LogCreateShape?


Code:
    Set crv = CreateCurve(ActiveDocument)
    
    Set sp = crv.CreateSubPath(Data(1, 0), Data(1, 1))
    
    'add curves to shape
    For n =  2 To 2000
        sp.AppendCurveSegment Data(n, 0), Data(n, 1)
    Next n
    
    sp.Closed = False
    
    Set sShape = ActiveLayer.CreateCurve(crv)
and can the following be speeded up by smoothing all the nodes in one go rather than running through a loop?

Code:
  'smooth nodes
    Set nr = sShape.Curve.Nodes.All
    For Each nd In nr
        nd.Type = cdrSmoothNode
    Next nd
Thanks
nic
Reply With Quote
  #2  
Old 28-09-2014, 23:29
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Virtual Curves and Shapes

This should get you started:
Code:
Sub CreateMyVirtualCurve()
    Dim s As Shape, crv As Curve
    Dim x As Double, y As Double
    Dim arrPoints(9, 1) As Double
    
    arrPoints(0, 0) = 162.4175222: arrPoints(0, 1) = 0.750376435
    arrPoints(1, 0) = 162.1904178: arrPoints(1, 1) = 1.42190801
    arrPoints(2, 0) = 161.8497645: arrPoints(2, 1) = 1.948110991
    arrPoints(3, 0) = 161.4460634: arrPoints(3, 1) = 2.285272734
    arrPoints(4, 0) = 161.0384773: arrPoints(4, 1) = 2.41926736
    arrPoints(5, 0) = 160.6855104: arrPoints(5, 1) = 2.367701481
    arrPoints(6, 0) = 160.4357975: arrPoints(6, 1) = 2.177051589
    arrPoints(7, 0) = 160.3204565: arrPoints(7, 1) = 1.915245416
    arrPoints(8, 0) = 160.3482122: arrPoints(8, 1) = 1.66085887
    arrPoints(9, 0) = 160.5040603: arrPoints(9, 1) = 1.490634456
    
    x = arrPoints(0, 0)
    y = arrPoints(0, 1)
    
    Set crv = New Curve 'Create our curve in Memory
    Set sp = crv.CreateSubPath(x, y)
    
    For i = 1 To 9
        x = arrPoints(i, 0)
        y = arrPoints(i, 1)
        sp.AppendCurveSegment x, y
    Next i
    
    sp.Closed = False
    
    'Take our curve in memory and create a virtual shape
    Set s = ActiveVirtualLayer.CreateCurve(crv)
    
    'Smooth all the nodes
    s.Curve.Nodes.All.SetType cdrSmoothNode
    
    'Log the newly created virual shape
    ActiveDocument.LogCreateShape s
End Sub
Also, just for fun. In X7 there is a much easier way to do this:
Code:
Sub CreateMyVirtualCurveX7()
    Dim s As Shape, crv As Curve
    Dim pr As New PointRange
    Dim arrPoints(9, 1) As Double
    
    arrPoints(0, 0) = 162.4175222: arrPoints(0, 1) = 0.750376435
    arrPoints(1, 0) = 162.1904178: arrPoints(1, 1) = 1.42190801
    arrPoints(2, 0) = 161.8497645: arrPoints(2, 1) = 1.948110991
    arrPoints(3, 0) = 161.4460634: arrPoints(3, 1) = 2.285272734
    arrPoints(4, 0) = 161.0384773: arrPoints(4, 1) = 2.41926736
    arrPoints(5, 0) = 160.6855104: arrPoints(5, 1) = 2.367701481
    arrPoints(6, 0) = 160.4357975: arrPoints(6, 1) = 2.177051589
    arrPoints(7, 0) = 160.3204565: arrPoints(7, 1) = 1.915245416
    arrPoints(8, 0) = 160.3482122: arrPoints(8, 1) = 1.66085887
    arrPoints(9, 0) = 160.5040603: arrPoints(9, 1) = 1.490634456
    
    For i = 0 To 9
        pr.AddPointXY arrPoints(i, 0), arrPoints(i, 1)
    Next i
    
    Set crv = ActiveDocument.CreateCurveFitToPoints(pr)
    'Or you can set a tolerance
    'Set crv = ActiveDocument.CreateCurveFitToPoints(pr, False, .01)
    
    Set s = ActiveVirtualLayer.CreateCurve(crv)
    
    ActiveDocument.LogCreateShape s
End Sub
Hope that helps,

-Shelby
Reply With Quote
  #3  
Old 29-09-2014, 12:29
nic nic is offline
Member
 
Join Date: May 2009
Posts: 90
Default Thanks

Hi Shelby
tried out both methods and found they both worked - went with the first as it kept the number of nodes constant and the number of nodes is significant in this case: The second method draws the line but decides itself how many nodes it needs

Im not sure if working with virtual layers saved much time here but Im glad to have learned a little about them and have projects that would benefit but there was a little gem in your code that did knock off a huge bunch of time -

s.Curve.Nodes.All.SetType cdrSmoothNode

as opposed to my code

For Each nd In sShape.Curve.Nodes
nd.Type = cdrSmoothNode
Next nd

Thanks again for your help.
Reply With Quote
Reply

Tags
smooth nodes, virtual layer


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
Cannot rotate a virtual shape with the same precision as a shape runflacruiser Macros/Add-ons 1 19-01-2011 15:34
Virtual layers, shapes and drawing speed jemmyell CorelDRAW/Corel DESIGNER VBA 2 06-05-2009 16:40
Speed-up processing 10 times :-) wOxxOm CorelDRAW/Corel DESIGNER VBA 2 12-03-2008 03:17
Speed up printing RonHill General 0 22-06-2004 14:20
speed difference between corelscript and vba bbolte CorelDRAW CS 2 05-12-2002 18:58


All times are GMT -5. The time now is 00:39.


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