Send to back programatically

G

geejay

Hi

I have an app with lots of shapes placed on the page programatically. I know
the exact order in which these should be placed on the Z plane (i.e "send to
back"). At the moment, I do this with a stack of shapes, sending each to the
back in the order that they should be placed.

Is there a better, faster way of doing this? Is there a shapesheet formula
or something for this?
 
J

JuneTheSecond

Hi,

I've tested to change zorder on the page that has many shapes.
A thing I found is 2 shapes must be overlapped each other.
If not over lapped, shape.sendbackward method does not work many times.
If over lapped shape.sendbackward works correctly.
The next code works on the page that has 7 shapes.
Shp1 is at the most front, and shp2 is at the most back.
The code makes shp1 to the most back.
But this code works only when shp1 and shp2 is overlapped each other.
It is curious and interesting.

Option Explicit
Sub test()
Dim shp1 As Visio.Shape
Dim shp2 As Visio.Shape
Set shp1 = ActivePage.Shapes.ItemFromID(1)
Set shp2 = ActivePage.Shapes.ItemFromID(2)
ChangeZorder shp1, shp2
End Sub

Sub ChangeZorder(shp1 As Visio.Shape, shp2 As Visio.Shape)
Dim I As Long
For I = 1 To 12
If shp1.Index > shp2.Index Then
shp1.SendBackward
Debug.Print I, shp1.Index
End If
Next
End Sub

--
Best Regards.

JuneTheSecond
Now, visual calculation is more visual.
http://www.geocities.jp/visualcalculation/english/index.html
 
A

AlEdlund

As an observation from the side. If z-order of shapes is important and
shape.sendbackwards only applies when the shapes overlap why not consider
placing the shapes on layers.
al
 
A

Andy

The Z order applies to all the shapes on the page and does not matter
if they overlap or not (and doesn't need to be selected). If you know
the z order you want, the fastest way is to actually drop the shapes
on in the order you require. Failing that, going through your shapes
and sending to the back is the only way. There is no mechanism in
Visio to set the z order of a shape. If you have 2 shapes you want to
swap, then you need to repeatedly call sendbackward on the shape until
the z order is lower then the other shapes z order.
 
B

Bernhard K

i had to deal with this in a quite complex scenario, where we rogrammatially
groupes some shapes and after some processing we ungrouped them, but needed
to recover the original Z order. The following observations were made (we
used C#):

* the only way to change the Z order is using Shape.BringToFront() and
Shape.SendToBack(), whereas Shape.SendToBack() was unreliable for an unknown
reason, so using BringToFront is better
* the Z order applies to all shapes as a unique ordering - position X is
taken by one and only one Shape.
* Every Shape has a Z-Order value, independend of potential overlappings
* to get an ascending sort of the Z order, iterate using
foreach (Shape shp in this.Page[1].Shapes)
* if you have to manipulate and recover as i described above, a good method
is to backup the order into a List<Shape> and when you recover the original
order just loop through the List and call Shape.BringToFront(), and you
original z order is recovered. of course, depeding on your drawings
complexity, this does or does not make sense ...

so if any visio developer is reading this - what about an API enhancement in
future Visio SDK to support the manipulation of the z-order? thanks!
 
P

Paul Herber

i had to deal with this in a quite complex scenario, where we rogrammatially
groupes some shapes and after some processing we ungrouped them, but needed
to recover the original Z order. The following observations were made (we
used C#):

* the only way to change the Z order is using Shape.BringToFront() and
Shape.SendToBack(), whereas Shape.SendToBack() was unreliable for an unknown
reason, so using BringToFront is better

There is also SendBackward and BringForward which will change the Z value by +/-1
* the Z order applies to all shapes as a unique ordering - position X is
taken by one and only one Shape.
* Every Shape has a Z-Order value, independend of potential overlappings
* to get an ascending sort of the Z order, iterate using
foreach (Shape shp in this.Page[1].Shapes)
* if you have to manipulate and recover as i described above, a good method
is to backup the order into a List<Shape> and when you recover the original
order just loop through the List and call Shape.BringToFront(), and you
original z order is recovered. of course, depeding on your drawings
complexity, this does or does not make sense ...

so if any visio developer is reading this - what about an API enhancement in
future Visio SDK to support the manipulation of the z-order? thanks!

I wrote a utility similar to this
http://www.sandrila.co.uk/visio-mezzo/
to maintain certain shapes at the front of a diagram.

(mezzo = Maintain Z order - a little bit contrived!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top