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 03-02-2003, 06:59
Rick Randall
Guest
 
Posts: n/a
Default Keeping the stacking order when changing layers

Hi. I have a macro that moves a drawing from one template to another and puts text and callout lines on a specific text layer. All I am really doing is opening a new blank template and importing the old drawing into it. The text and leader lines come in as a group so basically my macro finds the group where the text is by searching for a random text shape, then assigns a variable to the parentgroup that it belongs to. It then assigns each shape in the group to a shape range variable (ungrouped). From there I can simply assign the appropriate layer to each shape in the shape range. The problem I am having is: due to the randomness of how VBA finds shapes when using the following For...Each loop, my stacking order gets messed up. Certain shapes are now in front of others when I don't want them to be. :
Code:
Dim s As Shape, ss As Shape, sr As ShapeRange
Dim lyrTxt As Layer

Set s = lyrDrw.Shapes.FindShape(, cdrTextShape)
If Not s Is Nothing Then
Set sr = s.ParentGroup.UngroupAllEx
    For Each g In sr
    g.Layer = lyrTxt
    Next g
How can I move the contents of a shape range onto another layer while maintaing the stacking order of all the shapes in the shape range? [/code]
Reply With Quote
  #2  
Old 04-02-2003, 22:34
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Keeping the stacking order when changing layers

Rick,

Actually the order of objects in ShapeRange is quite predetermined. It is controlled by Document.ShapeEnumDirection property.

However in your case, the final stacking order changes because when you move shape one by one, they are put on top of the layer, so when you move from upper layer to a lower one, the order doesn't change, however when you move the shapes backwards, they come in opposite order. To fix this, just use ShapeRange.OrderReverse to correct the order.

Here is an example:

Code:
Sub LayerTest()
    Dim s As Shape, sr As ShapeRange
    Dim lyrFrom As Layer, lyrTo As Layer
    Set lyrFrom = ActivePage.Layers(2)
    Set lyrTo = ActivePage.Layers(1)
    
    Set sr = lyrFrom.Shapes.All
    For Each s In sr
        s.Layer = lyrTo
    Next s
    
    If lyrFrom.Index < lyrTo.Index Then sr.OrderReverse
End Sub
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


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


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