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 15-01-2011, 10:27
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default Document Center Guidelines

I recorded a quick little macro to place guidelines at the document center so I could assign it a single keystroke. Out of curiosity...is there a way I can condense this code? It works fine and fast, but seems like it could be shorter for such an easy task!

Code:
Sub DocCenterGuides()
    Dim s1 As Shape
    Set s1 = ActiveDocument.MasterPage.GuidesLayer.CreateGuideAngle(7.5, 1#, 0#)
    s1.Outline.SetProperties Color:=CreateRGBColor(0, 0, 255)
    Dim s2 As Shape
    Set s2 = ActiveDocument.MasterPage.GuidesLayer.CreateGuideAngle(1#, 7.5, 90#)
    s2.Outline.SetProperties Color:=CreateRGBColor(0, 0, 255)
    ActiveDocument.CreateShapeRangeFromArray(s1, s2).AlignToPageCenter cdrAlignLeft + cdrAlignRight + cdrAlignTop + cdrAlignBottom, cdrTextAlignBoundingBox
    ActiveDocument.CreateShapeRangeFromArray(s1, s2).Lock
End Sub

Patti
Reply With Quote
  #2  
Old 15-01-2011, 12:16
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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 Center Guides

How about this? Short enough for you? :-)
Code:
Sub DocCenterGuides()
    ActiveDocument.MasterPage.GuidesLayer.CreateGuideAngle(1, ActivePage.SizeHeight / 2, 0).Locked = True
    ActiveDocument.MasterPage.GuidesLayer.CreateGuideAngle(ActivePage.SizeWidth / 2, 1, 90).Locked = True
End Sub
Hope it helps,

-Shelby
Reply With Quote
  #3  
Old 15-01-2011, 14:13
runflacruiser's Avatar
runflacruiser runflacruiser is offline
Senior Member
 
Join Date: Jun 2009
Location: Pigeon Forge, TN USA
Posts: 811
Default

Hi.

...or

Code:
Sub DocCenterGuides()
    With ActiveDocument.Pages(0).GuidesLayer
    .CreateGuideAngle(1, ActivePage.SizeHeight / 2, 0).Locked = True
    .CreateGuideAngle(ActivePage.SizeWidth / 2, 1, 90).Locked = True
    End With
End Sub
-John
Reply With Quote
  #4  
Old 15-01-2011, 14:21
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default

Quote:
Originally Posted by shelbym View Post
How about this? Short enough for you? :-)
Yes! But it begs some questions...you knew this was coming, eh?

I understand most of what you did, except for the order of the numbers and what they represent in the parentheses. The last number I know is the angle and the 2 is what you are dividing by, correct? So what is the 1? Is it the point size...the x-y coordinate...the number of guides to create or something else?

(1, ActivePage.SizeHeight / 2, 0)


Two more questions...

Can I use something similar so that it would create guides only on the active page, what would I change?

With your code and with mine the focus remains on the last guideline created after the macro runs. How can I make it end so that the page/Layer 1 is the focus?

Thanks, Shelby!
Patti
Reply With Quote
  #5  
Old 15-01-2011, 14:27
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default

Quote:
Originally Posted by runflacruiser View Post
Hi.

...or

Code:
Sub DocCenterGuides()
    With ActiveDocument.Pages(0).GuidesLayer
    .CreateGuideAngle(1, ActivePage.SizeHeight / 2, 0).Locked = True
    .CreateGuideAngle(ActivePage.SizeWidth / 2, 1, 90).Locked = True
    End With
End Sub
-John
Oh boy! More code to study!
Reply With Quote
  #6  
Old 15-01-2011, 15:00
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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 Guidelines

The help definition are as follows:

Function CreateGuideAngle(x As Double, y As Double, Angle As Double) As Shape

The CreateGuideAngle method creates a guideline, at a specified location on a layer, by using a point and an angle.


x Specifies the x-coordinate for the point that defines the guideline. This value is measured in document units.
y Specifies the y-coordinate for the point that defines the guideline. This value is measured in document units.
Angle Specifies the degree to which the guideline is slanted. Values range from 0 to 360 degrees.

To try and explain it a little better. When we set the angle for 0 we are creating a horizontal guide so we really only need to tell it at what Y value we want the guide placed. The X value doesn't matter so we just toss in a place holder aka 1, you could enter 0 or 9, it really doesn't matter when creating a straight guide.

In this case we get the ActivePage Height and divide is by 2 to place the guide in the center of the page.

When we set the angle for 90 we are creating a vertical guide so the only value that matter is the X value, the Y value can be whatever. We use the ActivePage Width / 2 to place it in the middle of the page.

-Shelby
Reply With Quote
  #7  
Old 15-01-2011, 16:45
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default

This also works great:

Code:
Sub DocCenterGuidesPA()
    With ActiveDocument.MasterPage.GuidesLayer
    .CreateGuideAngle(1, ActivePage.SizeHeight / 2, 0).Locked = True
    .CreateGuideAngle(ActivePage.SizeWidth / 2, 1, 90).Locked = True
    End With
End Sub
Still would like to figure out how to end with the focus on the page, not the last guideline drawn.

Thanks for the explanation, Shelby! The 1 as a placeholder wasn't in my list!

Patti
Reply With Quote
  #8  
Old 15-01-2011, 17:40
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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 ClearSelection

You should just need to clear the selection:
Code:
ActiveDocument.ClearSelection
-Shelby
Reply With Quote
  #9  
Old 15-01-2011, 17:46
PAnderson PAnderson is offline
Member
 
Join Date: Nov 2003
Posts: 47
Default

Quote:
Originally Posted by shelbym View Post
You should just need to clear the selection:
Code:
ActiveDocument.ClearSelection
-Shelby

I tried that, but the guidelines property bar is still showing. It's not a biggie, but thought there might be something else to try.

Patti
Reply With Quote
  #10  
Old 15-01-2011, 18:03
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,787
Blog Entries: 11
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 Guidelines

Try tossing in a Refresh:
Code:
ActiveDocument.ClearSelection
Refresh
-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
Select Guidelines macro kenpoist CorelDRAW/Corel DESIGNER VBA 5 05-01-2011 13:12
How do i print the guidelines? cristov General 3 26-02-2006 22:49
How to duplicate an object along common center Alex FAQ 2 03-05-2005 14:46
Snap to guidelines ddonnahoe CorelDRAW/Corel DESIGNER VBA 2 22-11-2004 12:21
Getting the center X on a text shape Rick Randall CorelDRAW/Corel DESIGNER VBA 4 03-08-2004 18:27


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


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