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 01-05-2007, 13:40
Jeff Harrison
Guest
 
Posts: n/a
Default Is it possible to assign hotkey to these checkboxes through VBA?

I'd like to align selected nodes in curve editing mode with a hotkey.

I tried recording a macro and viewing the code - don't see what I'm looking for.
Attached Images
 
Reply With Quote
  #2  
Old 01-05-2007, 16:54
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,788
Blog Entries: 12
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 Align Node Horizontal

Here is a little code to get you started, I bet you can figure out the rest.
Code:
Sub AlignNodesHorizontal()
    Dim nNode As Node
    Dim nrSelected As NodeRange
    Dim x As Double, y As Double
    
    If ActiveShape Is Nothing Then Exit Sub 'Check to make sure something is selected
    If ActiveShape.Type <> cdrCurveShape Then Exit Sub 'Check to make sure it is a curve
    If ActiveTool <> 22 Then Exit Sub ' Check to see if in node editing mode
    
    Set nrSelected = ActiveShape.Curve.Selection 'Set selected nodes to node range
    nrSelected.FirstNode.GetPosition x, y 'Get position of first node
    
    For Each nNode In nrSelected
        nNode.PositionY = y
    Next nNode
End Sub
Let me know if you need more,

Shelby
Reply With Quote
  #3  
Old 01-05-2007, 18:21
Jeff Harrison
Guest
 
Posts: n/a
Default works great!

Thanks Shelby, U rock! I figured how to do the vertical too.

I are smart... :-)

Jeff
Reply With Quote
  #4  
Old 01-05-2007, 18:27
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,788
Blog Entries: 12
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 You go....

I knew you could do it!

Shelby
Reply With Quote
  #5  
Old 02-05-2007, 00:06
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,788
Blog Entries: 12
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 Final Code

Here is the final code that adds undo, and will keep the node selection. Enjoy and I hope everyone finds it useful.
Code:
Sub AlignNodesHorizontal()
    Dim nNode As Node
    Dim nrSelected As NodeRange
    Dim x As Double, y As Double
    
    If ActiveShape Is Nothing Then Exit Sub 'Check to make sure something is selected
    If ActiveShape.Type <> cdrCurveShape Then Exit Sub 'Check to make sure it is a curve
    If ActiveTool <> 22 Then Exit Sub ' Check to see if in node editing mode
    
    'Start the Undo Group.
    ActiveDocument.BeginCommandGroup "Align Nodes"
    'If error goto error handler so undo stack is not currupted.
    On Error GoTo ErrHandler
    
    'Stops the flashing effect of setting each node position
    Optimization = True
    
    Set nrSelected = ActiveShape.Curve.Selection 'Set selected nodes to node range
    nrSelected.FirstNode.GetPosition x, y 'Get position of first node
    
    'Loop thru each node and set the position
    For Each nNode In nrSelected
        nNode.PositionY = y
    Next nNode
    
    nrSelected.Move 0, 0 'A little trick to keep the selection
    
'Ends the undo command group and refreshes the application.
ExitSub:
    ActiveDocument.EndCommandGroup
    Optimization = False
    ActiveWindow.Refresh
    Application.Refresh
    Exit Sub

'Displays message if there was an error.
ErrHandler:
    MsgBox "Error occured: " & Err.Description
    Resume ExitSub
End Sub

Sub AlignNodesVertical()
    Dim nNode As Node
    Dim nrSelected As NodeRange
    Dim x As Double, y As Double
    
    If ActiveShape Is Nothing Then Exit Sub 'Check to make sure something is selected
    If ActiveShape.Type <> cdrCurveShape Then Exit Sub 'Check to make sure it is a curve
    If ActiveTool <> 22 Then Exit Sub ' Check to see if in node editing mode
    
    'Start the Undo Group.
    ActiveDocument.BeginCommandGroup "Align Nodes"
    'If error goto error handler so undo stack is not currupted.
    On Error GoTo ErrHandler
    
    'Stops the flashing effect of setting each node position
    Optimization = True
    
    Set nrSelected = ActiveShape.Curve.Selection 'Set selected nodes to node range
    nrSelected.FirstNode.GetPosition x, y 'Get position of first node
    
    'Loop thru each node and set the position
    For Each nNode In nrSelected
        nNode.PositionX = x
    Next nNode
    
    nrSelected.Move 0, 0 'A little trick to keep the selection
    
'Ends the undo command group and refreshes the application.
ExitSub:
    ActiveDocument.EndCommandGroup
    Optimization = False
    ActiveWindow.Refresh
    Application.Refresh
    Exit Sub

'Displays message if there was an error.
ErrHandler:
    MsgBox "Error occured: " & Err.Description
    Resume ExitSub
End Sub
Shelby
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
Where to begin with CorelDRAW and VBA shelbym CorelDRAW/Corel DESIGNER VBA 2 03-04-2007 10:15
delete vba project from cdr file hotairballoon CorelDRAW/Corel DESIGNER VBA 1 18-05-2005 10:08
CD 10, VBA not returning true outline width Webster CorelDRAW/Corel DESIGNER VBA 1 24-11-2004 18:09
VBA does not work with my CD 10 ! jobar CorelDRAW/Corel DESIGNER VBA 1 24-08-2003 13:38
Detect if VBA is installed (an answer and a question) reanan CorelDRAW/Corel DESIGNER VBA 3 04-12-2002 15:35


All times are GMT -5. The time now is 08:20.


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