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 06-12-2005, 00:47
Shaddy
Guest
 
Posts: n/a
Default Is there a property/method to check for shape off page?

I'm not sure what to search for to see if it's already been discussed. Basically, I'm going to repeat a given object until it goes off the page, then start a new row. I plan on adding a text file merge and an auto increment field for serial numbers (done those seperately, just not together yet). But I don't see how to tell when the shape goes off the page.

I s'pose I could do the math and keep a tally of the dimensions, but it would be nice for the other feature.

Shaddy
Reply With Quote
  #2  
Old 06-12-2005, 08:28
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, it can be fairly simple. You know the dimensions of the current page (ActivePage.GetSize). You can easily get the position and size of the current shape (Shape.GetBoundingBox) and you can determine the coordinates of the four corners of the shape. Then finally you can figure out if all four corners are within the page rectangle.

Here is an example of how you can duplicate the current selected shapes horizontally/vertically until the duplicates reach the right/bottom edge of page:

Code:
Sub DuplicateUntilOffPage()
    Dim sr As ShapeRange
    
    Set sr = ActiveSelectionRange
    If sr.Count = 0 Then
        MsgBox "Nothing selected"
        Exit Sub
    End If
    
    If Not CheckShapesInsidePage(sr) Then
        MsgBox "The shapes are already outside the page boundaries"
        Exit Sub
    End If
    
    DuplicateHorizontally sr
    
    Set sr = sr.Duplicate(0, -sr.SizeHeight)
    While CheckShapesInsidePage(sr)
        DuplicateHorizontally sr
        Set sr = sr.Duplicate(0, -sr.SizeHeight)
    Wend
    
    ' delete the remaining shapes which are off page now
    sr.Delete
End Sub

Private Sub DuplicateHorizontally(ByVal sr As ShapeRange)
    Do
        Set sr = sr.Duplicate(sr.SizeWidth, 0)
    Loop While CheckShapesInsidePage(sr)
    
    ' delete the remaining shapes which are off page now
    sr.Delete
End Sub

Private Function CheckShapesInsidePage(ByVal sr As ShapeRange) As Boolean
    Dim px1 As Double, py1 As Double
    Dim px2 As Double, py2 As Double
    Dim x1 As Double, y1 As Double
    Dim x2 As Double, y2 As Double
    
    ' Get the coordinates of page borders
    px1 = ActiveDocument.DrawingOriginX + ActivePage.SizeWidth / 2
    py1 = ActiveDocument.DrawingOriginY + ActivePage.SizeHeight / 2
    px2 = px1 + ActivePage.SizeWidth
    py2 = py1 + ActivePage.SizeHeight
    
    ' Get coordinates of the current shapes
    sr.GetBoundingBox x1, y1, x2, y2
    x2 = x1 + x2
    y2 = y1 + y2
    
    CheckShapesInsidePage = (x1 >= px1 And x1 <= px2) And _
                            (x2 >= px1 And x2 <= px2) And _
                            (y1 >= py1 And y1 <= py2) And _
                            (y2 >= py1 And y2 <= py2)
End Function
Reply With Quote
  #3  
Old 06-12-2005, 18:37
Shaddy
Guest
 
Posts: n/a
Default

THis line here Set sr = sr.Duplicate(sr.SizeWidth, 0) isn't setting the new selection. As in, the original shape range is still selected, which means it'll loop continuously horizontally.

How do you set is so the newly created item is selected?

EDIT: Whooops, I did some more looking and saw that by adding sr.CreateSelection directly after the previous makes it work.
Sorry to post before exauhsting my search, but I have a very hard time using the help file when i don't know exactly what to look up. Who knew it sould be CreateSelection as opposed to just Select.

Thanks for your help Alex, I wasn't expecting so much, you really went above and beyond.

Shaddy

Last edited by Shaddy; 06-12-2005 at 18:47.
Reply With Quote
  #4  
Old 06-12-2005, 19:58
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Quote:
Originally Posted by Shaddy
THis line here Set sr = sr.Duplicate(sr.SizeWidth, 0) isn't setting the new selection. As in, the original shape range is still selected, which means it'll loop continuously horizontally.
Shaddy,

Why do you need selection once again? Selection isn't everything in CorelDRAW, you know sr.GetBoundingBox will work whether or not shapes in the range are actually selected. So I really don't see a need for sr.CreateSelection here. It will slow down your macro, if that's what you are after, but that's about all the uses for it here

I tried the macro before posting it and it worked for me. At least in CorelDRAW 12.
Reply With Quote
  #5  
Old 06-12-2005, 20:34
Shaddy
Guest
 
Posts: n/a
Default

It didn't work for me (endless loop creating a few thousand copies off to the right until I was able to stop it), and as I stepped through watching the values, I noticed it was using the same x and y values as the first time through.

I also have version 12, but I'll investigate farther. Now I wonder what I have set differently.

Shaddy
Reply With Quote
  #6  
Old 17-08-2006, 15:54
Shaddy
Guest
 
Posts: n/a
Default

Just bringing this back up again... I never did get the .Duplicate to work correctly, (the code as you posted) in DRAW 12 (it works in 13 OK). And I noticed a weird behavior... When I "run" it full speed it uses the original shape so it will never detect that it copied off the page, but when I run it step by step (repeatedly pressing the F8 key) it does work correctly.

Why would it behave differently when running versus stepping?

Shaddy
Reply With Quote
  #7  
Old 20-08-2006, 09:15
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Probably a bug in CorelDRAW 12. When you run a macro "full speed" many things don't have a chance to update properly (like UI toolbars, etc) and maybe some internal features were really updated by the UI (for example, current selection bounding box). When you do it step by step, as soon as you step through the code which changes the selection, the UI updates everything as if you did the selection with your mouse/keyboard and everything works Ok. However when you run the whole macro, the change in selection might not be noticed and methods that rely on selection may not work properly.

Technically, this should never happen and I guess this problem was fixed in v13. To fix this in CorelDRAW 12, you might want to either rework the code to do the same thing with a different method. Maybe something like this. Instead of using:

Code:
Set srDup = sr.Duplicate
you might try using this:

Code:
sr.CreateSelection
Set srDup = ActiveSelection.DuplicateAsRange
You should never need to do such thing, unless there is a problem with the "correct" method.

Another way could be to insert some "DoEvents" commands in your macro to allow CorelDRAW to process some messages and "notice" changes in document:

Code:
Set s = ActiveLayer.CreateRectangle(0,0,1,2)
DoEvents
s.Duplicate...
This will make your macro to run slower, but there is no use of a fast macro that doesn't work correctly, right?


I hope this helps.
Reply With Quote
  #8  
Old 22-08-2006, 16:26
Shaddy
Guest
 
Posts: n/a
Default

That's it. If I just make a rectangle, it will go off screen when full speed, but not when stepped through. If I make it more complicated with a lot of objects selected it works correctly full speed. (I guess the complexity makes it take longer for calculations n such). That's what I get for having a nice, fast machine finally.

Thanks for your help once again. I assumed it was my code.

Shaddy
Reply With Quote
  #9  
Old 26-08-2006, 13:04
Shaddy
Guest
 
Posts: n/a
Default

Sorry to harp on this, but I thought I'd give you an update... I have been using X3 for developing, and just recently put 12 on my PC again in an effort to make my VBA more compatable with other users. That's when these problem occured.

What I didn't do was update 12 after I installed it. After a few updates, the code works fine without adding pauses or clock-gobblers.

I can finally finish going over the code differences and changing from X3-only code to a more 12 friendly code.

Thanks for your continuing assistance.

Shaddy
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
Page Numbering Hernán New product ideas 3 15-02-2007 22:12
Importing only 1st page from a multipage CDR mecanomaniaco CorelDRAW/Corel DESIGNER VBA 3 28-02-2005 17:21
Export each page with a diff. file name ddonnahoe CorelDRAW/Corel DESIGNER VBA 3 02-02-2004 14:40
How do you "go to" a specific /named/ page? Steve CorelDRAW/Corel DESIGNER VBA 2 08-05-2003 17:10
Page selection and object moving problems wbochar CorelDRAW/Corel DESIGNER VBA 1 15-04-2003 09:10


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


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