OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   Mysterious problem in new page activation (http://forum.oberonplace.com/showthread.php?t=5953)

sakis_drm 22-06-2008 07:57

Mysterious problem in new page activation
 
I need to do some complex unrevertible tasks to the shapes of "original" Page 1.
e.g. continous break apparts, convert to curves etc...
and don't like to affect the shapes in the "original" Page 1.

So,
1. I copy the selected shapes
2. Create a new page "Page 2"
3. Activate "Page 2" (it is not mandatory to do this)
3. Paste them into "Page 2" (until that point, all works FINE)..

Now I have to do my tasks!
All the tasks are taking place at "Page 1" despite my activation on "Page 2"!!!:icon_frow

Code:

Public Sub CopyToNewPage()
    ActiveDocument.Selection.Copy
    ActiveDocument.AddPages 1
    ActiveDocument.ActiveLayer.Paste
    MsgBox ActiveDocument.ActivePage.Name
    'my tasks
End Sub


Now, watch carefully...
I have added a MessageBox that returns the active page's name...
It returns "Page 1":crazyjump

If I put a breakpoint on the Paste or the Msgbox command,
after the resume
It returns "Page 2":crazyjump:crazyjump:crazyjump


Note:
The same issue appears as well as to Shelbym's code which does the same work, posted somewhere into the forum.
I added the msgbox command.

Code:

Public Sub CopyToNext()
    Dim sr As ShapeRange
    Dim s As Shape
    Dim p As Page

    Set sr = ActiveSelectionRange
    Set p = ActiveDocument.InsertPages(1, False, ActivePage.Index)

    For Each s In sr
        s.Layer.Activate
        s.Duplicate
        s.MoveToLayer ActiveDocument.Pages(ActivePage.Index + 1).ActiveLayer
    Next s
    ActiveDocument.Pages.Last.Activate
    MsgBox ActiveDocument.ActivePage.Name

End Sub

I have tried to add commands in order to create an interval between the page creation paste... and my tasks such as:
  • DoEvents
  • TimePause (this is mine... it stops the system for a while)
  • Activewindow.Refresh

sakis_drm 30-06-2008 15:54

Corel's bug?
 
Seems like Corel's bug..

If anyone has any idea or
If anyone faces the same problem or
If anyone has solved thar problem in the past,

It would be great to post his opinion..

shelbym 30-06-2008 21:53

CopyToNextPage
 
Alright I have only tested this in X4, but I think it does everything you want. It takes the selection, creates a new page and moves a duplicate of the selection to the new page. It then applies a yellow fill to each of the new shapes on the new page. The original page is left intact with no changes.
Code:

Sub CopyToNextPage()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim p As Page
   
    Set sr = ActiveSelectionRange.Duplicate() 'Duplicate the selection
    Set p = ActiveDocument.InsertPages(1, False, ActivePage.Index) 'Create a new Page
   
    sr.MoveToLayer p.Layers("Layer 1") 'Move the duplicates to the new page
   
    'Do something to the duplicates (Fill them Yellow)
    For Each s In sr
        s.Fill.ApplyUniformFill CreateCMYKColor(0, 0, 100, 0)
    Next s
End Sub

What did I miss?

-Shelby

sakis_drm 01-07-2008 14:59

Need a real page activation
 
Thanks for you response,

my original issue is the same because if i add the line...
Quote:

MsgBox ActiveDocument.ActivePage.Name
at the end of your code ... It will return "Page 1" again!

In your code "CopyToNextPage" you refear to an object "SR".
In my code I reafer to activepage's objects. That is the difference... :icon_frow

I need a command that will realy activates the newly created page..
something like...

1. Add a page
2. Activate that new page
3. MsgBox ActiveDocument.ActivePage.Name
4. must return the new page's name

Thanks a lot.

shelbym 01-07-2008 16:03

Version
 
***Update: I have now tested in 12 and X3 and I get the same results: Page1, Page2, Page2 as expected

What version are you using? I tried the following code in X4 SR1
Code:

Sub CopyToNextPage()
    Dim s As Shape
    Dim sr As ShapeRange
    Dim p As Page

    MsgBox ActiveDocument.ActivePage.Name
   
    Set sr = ActiveSelectionRange.Duplicate() 'Duplicate the selection
    Set p = ActiveDocument.InsertPages(1, False, ActivePage.Index) 'Create a new Page
   
    p.Activate
    MsgBox ActiveDocument.ActivePage.Name
   
    sr.MoveToLayer p.Layers("Layer 1") 'Move the duplicates to the new page
   
    'Do something to the duplicates (Fill them Yellow)
    For Each s In sr
        s.Fill.ApplyUniformFill CreateCMYKColor(0, 0, 100, 0)
    Next s
   
    MsgBox ActiveDocument.ActivePage.Name
End Sub

And it reports: Page1, Page2, Page2 as I would expect.

-Shelby

sakis_drm 02-07-2008 11:36

Does not activate page 2
 
I got "Page 1", "Page 1", "Page 1" on Corel version 14.0.0.567

I ll try to update my version if i can :rolleyes:

The only way to get "Page 2" is to place a breakpoint on the last msgbox command.
Maybe I have to do that in 2 steps to force the user to press another button
in order to execute the procedures to the newly created page after the page activation. :(

Alex 02-07-2008 12:54

Have you installed the service pack for CGS X4? If not, you should :)

http://www.corel.com/servlet/Satelli...=1205332430735

sakis_drm 02-07-2008 16:02

Alex is right
 
Service Pack 1 solved that issue.

Alex and Shelbym, thanks a lot!
Nice to meet you!


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

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