OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Working with parts of a curve that has been broken (http://forum.oberonplace.com/showthread.php?t=24700)

nic 04-10-2014 10:25

Working with parts of a curve that has been broken
 
Hi
the code below adds nodes to a curve and then breaks the curve apart but I dont know how to then work with the new curves (Im intending to recolour them each in a separate colour).

How do you refer to the new objects created when you break a curve apart?
nic

Code:

Dim s as shape, sr as ShapeRange, sp as SubPath, nr as NodeRange
Set sr = ActivePage.Shapes.FindShapes()

'loop thru shapes
For Each s In sr

  s.Curve.SubPaths.First.AddNodeAt 0.333, cdrRelativeSegmentOffset
  s.Curve.SubPaths.First.AddNodeAt 0.666, cdrRelativeSegmentOffset

    'break nodes and curve
    Set nr = s.Curve.Nodes.All
    nr.BreakApart
    nr.RemoveAll
    s.BreakApart
   
    'bogus code
    's.PART1.Outline.Color.RGBAssign 255, 0, 0
    's.PART2.Outline.Color.RGBAssign 0, 255, 0
    's.PART3.Outline.Color.RGBAssign 0, 0, 255
   
Next s


shelbym 05-10-2014 18:46

BreakApartEx
 
The easiest way to do this is the use BreakApartEx it will return a ShapeRange with all the newly created shapes.

Here is your code modified a bit, it will randomly change the outline color:
Code:

    Dim s As Shape, sr As ShapeRange, sp As SubPath, nr As NodeRange
    Set sr = ActivePage.Shapes.FindShapes()
    Dim srBrokenCurves As New ShapeRange
    Dim n As Long, num As Long
   
    'loop thru shapes
    For Each s In sr
   
      s.Curve.SubPaths.First.AddNodeAt 0.333, cdrRelativeSegmentOffset
      s.Curve.SubPaths.First.AddNodeAt 0.666, cdrRelativeSegmentOffset
   
        'break nodes and curve
        Set nr = s.Curve.Nodes.All
        nr.BreakApart
        nr.RemoveAll
        srBrokenCurves.AddRange s.BreakApartEx
    Next s
   
    num = ActivePalette.ColorCount
   
    For Each s In srBrokenCurves
        n = CLng(Fix(Rnd() * num)) + 1
        s.Outline.Color = ActivePalette.Color(n)
    Next s

Hope that helps,

-Shelby

nic 06-10-2014 09:24

Thanks
 
Hi Shelby
thank you, that does exactly what I was after - BreakApartEx - a new tool to add to my toolbox.

Many thanks
nic


All times are GMT -5. The time now is 23:40.

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