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 03-08-2004, 16:40
bumblebee
Guest
 
Posts: n/a
Default vba question

am trying to write a code in which following is required.

for example i enter text or create or import a graphic in a new document. i wnat to remove fill and simply look at the wireframe of the design. Typically, there are fixed directions of path. For example, character O will be two circles, now when i break apart the curves there will be 2 diffrent circles .The outside circle may have a clockwise direction and inside circle will have opposite direction - counter clockwise. If desired, can I show small arrows on the path every so often to define the directions? Also, how do i get that starting point of the curve both the curves from where they began the drwing in my code and than enlarge it in size and than fill it with red so it is more visible to the user or in other words is it possible to show the starting point of the vector or every single shape with a slightly larger color dot? The user will know the starting position of every vector and the direction in which the tool of the machine will move to cut the material. Can I change the direction of individual path or by selecting one or many or all paths? Can I change the starting position to some other point on the curve or vector? How do I change?

I am pretty new to this VBA programming and your help will be really apreciated..
Reply With Quote
  #2  
Old 03-08-2004, 20:15
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: vba question

Hmm, it looks like an interesting problem.

I spend some time on it and here is what I have come up with. The following macro indicates the starting point and direction of each subpath of each object selected:

Code:
Sub ShowCurveDirection()
    Dim s As Shape
    Dim sSegment As Shape
    Dim crv As Curve
    Dim crvSegment As Curve
    Dim sp As SubPath
    Dim Duplicated As Boolean
    Dim n As Long
    
    ' Loop through every selected shape
    For Each s In ActiveSelection.Shapes
        Duplicated = False
        
        ' If the shape is text, duplicate it and convert the copy to curves
        If s.Type = cdrTextShape Then
            Set s = s.Duplicate
            s.ConvertToCurves
            Duplicated = True
        End If
        
        ' Get the display curve (no need to convert ellipse, polygon, etc to curves first)
        Set crv = s.DisplayCurve
        
        ' Loop through every subpath in the curve
        For Each sp In crv.SubPaths
            ' Get the first segment as another curve object
            Set crvSegment = sp.Segments(1).GetCopy
            ' Make sure the curve is long enough to see both start and end points
            ' If not, add more segments (let's choose 0.5 inches as the threshold here)
            n = 2
            Do While crvSegment.Length < 0.5 And n < sp.Segments.Count
                crvSegment.AppendCurve sp.Segments(n).GetCopy
                ' Now join the segments into one path
                crvSegment.SubPaths(1).EndNode.JoinWith crvSegment.SubPaths(2).StartNode
                n = n + 1
            Loop
            ' Create the arrow out of the constructed curve
            Set sSegment = ActiveLayer.CreateCurve(crvSegment)
            ' Apply red outline to it which start with a circle and ends with an arrow
            ' to indicate the starting point of the path and its direction
            sSegment.Outline.SetProperties 0.02, , CreateCMYKColor(0, 100, 100, 0), ArrowHeads(53), ArrowHeads(2)
        Next sp
        
        ' If we duplicated the object above, delete the copy as it is no longer needed
        If Duplicated Then s.Delete
    Next s
End Sub
I hope the comments I put in the code explain a bit what I'm doing here. I have attached a picture of how the result of the macro looks like when run on a text object.
Attached Images
 
Reply With Quote
  #3  
Old 03-08-2004, 20:40
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: vba question

Now in order to change the starting point of a subpath, you need to break it apart at the given node and then join it again. Obviously, this applies only to the closed paths.

Here is a macro which allows to make the selected node of a closed curve the starting node of the path. Just select the node with the Shape tool and run the following macro to make that node the starting node of the corresponding subpath:

Code:
Sub MakeFirstNode()
    Dim s As Shape
    Dim nr As NodeRange
    Dim n As Node
    Dim nt As cdrNodeType
    Dim sp As SubPath
    
    ' Check to see if a curve is selected
    Set s = ActiveShape
    If s.Type <> cdrCurveShape Then
        MsgBox "A node on a curve must be selected first", vbCritical
        Exit Sub
    End If
    
    ' Check if there is one node selected on the curve
    Set nr = s.Curve.Selection
    If nr.Count <> 1 Then
        MsgBox "Only one node must be selected on the curve", vbCritical
        Exit Sub
    End If
    
    Set n = nr(1)
    Set sp = n.SubPath
    ' Check if the subpath to which the node belongs is closed
    If Not sp.Closed Then
        MsgBox "The selected node must be on a closed subpath", vbCritical
        Exit Sub
    End If
    
    ' Remember the node type first (cusp, smooth or symmetrical)
    nt = n.Type
    ' Break the subpath apart at the selected node
    n.BreakApart
    ' Re-join the subpath
    sp.Closed = True
    ' Restore the node type
    sp.StartNode.Type = nt
End Sub
Finally, you can change the direction of the whole curve (all the subpaths) if you select it with the Shape tool and click Reverse Curve Direction button on the property bar (10th button from the left).

However if you want to change the direction of one or several subpaths only, you need to create a macro for this. Here is an example. Just select a few nodes and the direction of the corresponding subpath(s) will be reversed:

Code:
Sub ReverseSubpaths()
    Dim s As Shape
    Dim crv As Curve
    Dim nr As NodeRange
    Dim PathSelected() As Boolean
    Dim sp As SubPath
    Dim n As Node
    Dim i As Long
    
    ' Check to see if a curve is selected
    Set s = ActiveShape
    If s.Type <> cdrCurveShape Then
        MsgBox "A curve must be selected", vbCritical
        Exit Sub
    End If
    
    Set nr = s.Curve.Selection
    If nr.Count = 0 Then
        MsgBox "Select one or more nodes on the curve", vbCritical
        Exit Sub
    End If
    
    ' Prepare the array to indicate which subpath is selected
    ReDim PathSelected(1 To s.Curve.SubPaths.Count)
    
    For Each n In nr
        PathSelected(n.SubPath.Index) = True
    Next n
    
    ' Make copy of the existing curve
    Set crv = s.Curve.GetCopy
    
    ' Reverse the direction of selected subpaths
    For Each sp In crv.SubPaths
        If PathSelected(sp.Index) Then
            sp.ReverseDirection
        End If
    Next sp
    
    ' Put the modified curve back into the curve object
    s.Curve.CopyAssign crv
End Sub
Note: the three code samples above are for CorelDRAW 12. They will not work under earlier version of CorelDRAW because they use some of advanced curve editing techniques which are not available in CorelDRAW 9-11. However you can adapt the macros rather easily to work well under CorelDRAW 11. CorelDRAW 10 can be done with a little more effort. I wouldn't even touch CorelDRAW 9 though. It lacks most of curve editing capabilities in the automation object model...

I hope this helps.
Reply With Quote
  #4  
Old 04-08-2004, 01:18
bumblebee
Guest
 
Posts: n/a
Default Re: vba question

Quote:
Originally Posted by bumblebee
am trying to write a code in which following is required.

for example i enter text or create or import a graphic in a new document. i wnat to remove fill and simply look at the wireframe of the design. Typically, there are fixed directions of path. For example, character O will be two circles, now when i break apart the curves there will be 2 diffrent circles .The outside circle may have a clockwise direction and inside circle will have opposite direction - counter clockwise. If desired, can I show small arrows on the path every so often to define the directions? Also, how do i get that starting point of the curve both the curves from where they began the drwing in my code and than enlarge it in size and than fill it with red so it is more visible to the user or in other words is it possible to show the starting point of the vector or every single shape with a slightly larger color dot? The user will know the starting position of every vector and the direction in which the tool of the machine will move to cut the material. Can I change the direction of individual path or by selecting one or many or all paths? Can I change the starting position to some other point on the curve or vector? How do I change?

I am pretty new to this VBA programming and your help will be really apreciated..

thanks a lot alex this really really helped.
As being very new to VBA programming i am finding a little difficult to use th libraries and members functions and subs in VBA.Can you please suggest some good tutorial or soemthing which will help me to familirize with VBA classes .
I have done a lot of programming in C++ so i guess just a familiarilty with VBA classes and functions is needed the most here.

Thanks again and thanks for having such a wonderful site .
Reply With Quote
  #5  
Old 04-08-2004, 15:07
bumblebee
Guest
 
Posts: n/a
Default vba question

thanks a lot for your help alex.

the macrofor the 1 st part looks good .i was just looking into it and i found that suppose i stretch the text or increase its size and make it larger smaller the arrow does not stretch or move along with it.
is it poosible for doing so the arrow which is drawn it can also be redrawn with the same size on the object whose size just changed .the arrow direction is just an indication to the user who is operating the machine that the shape or object is going to cut it in that direction.
Also for the starting point to change it to other point it can not only be on the curve, but anywhere in the whole shape or object it maybe on left most corner or right most corner .so can that be done?
can i allow the user to select the color of the arrow and the starting point.?
in the reverse curve direction when i reverse the curve the starting point also changes in opposite diection .the starting point should remain the same only the curve should be drawn in opposite direction from the same starting point.

your help on this one will be apreciated
thanks in advance.
Reply With Quote
Reply


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
delete vba project from cdr file hotairballoon CorelDRAW/Corel DESIGNER VBA 1 18-05-2005 09:08
CD 10, VBA not returning true outline width Webster CorelDRAW/Corel DESIGNER VBA 1 24-11-2004 17:09
Contest sensitive VBA programs? Peter Clifton CorelDRAW/Corel DESIGNER VBA 2 04-11-2003 14:44
VBA does not work with my CD 10 ! jobar CorelDRAW/Corel DESIGNER VBA 1 24-08-2003 12:38
Detect if VBA is installed (an answer and a question) reanan CorelDRAW/Corel DESIGNER VBA 3 04-12-2002 14:35


All times are GMT -5. The time now is 14:29.


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