OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Document Center Guidelines (http://forum.oberonplace.com/showthread.php?t=7440)

PAnderson 15-01-2011 10:27

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

shelbym 15-01-2011 12:16

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

runflacruiser 15-01-2011 14:13

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

PAnderson 15-01-2011 14:21

Quote:

Originally Posted by shelbym (Post 18132)
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

PAnderson 15-01-2011 14:27

Quote:

Originally Posted by runflacruiser (Post 18134)
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! :looney:

shelbym 15-01-2011 15:00

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

PAnderson 15-01-2011 16:45

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

shelbym 15-01-2011 17:40

ClearSelection
 
You should just need to clear the selection:
Code:

ActiveDocument.ClearSelection
-Shelby

PAnderson 15-01-2011 17:46

Quote:

Originally Posted by shelbym (Post 18141)
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

shelbym 15-01-2011 18:03

Guidelines
 
Try tossing in a Refresh:
Code:

ActiveDocument.ClearSelection
Refresh

-Shelby


All times are GMT -5. The time now is 03:30.

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