Author Topic: Shapes do not stay in given z-order after save and open  (Read 8698 times)

0 Members and 1 Guest are viewing this topic.

stanbriggs

  • Newbie
  • *
  • Posts: 9
Shapes do not stay in given z-order after save and open
« on: July 14, 2021, 12:27:37 PM »
greetings,
i have a custom stencil. let's call it 'virtual server'. 'virtual server' consists of three components in a group. let's call them 'server', 'app type', and 'storage'. during my VBA processing i will sometimes programmatically remove 'storage' and replace it with a different 'storage'. initially this places 'storage' on top, of course. i can send 'storage' to the back either programmatically or manually. regardless of the method used to move it to back when i save, close, and open the Visio 'storage' is back on top.
Visio Professional 2016.
any thoughts?
thanks,
stan

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3088
    • Paul Herber's website
Re: Shapes do not stay in given z-order after save and open
« Reply #1 on: July 14, 2021, 12:49:57 PM »
When you drop your shape on a page these shapes will be in one group shape. Do you ungroup the shape?
Do you just replace the storage sub-shape?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

stanbriggs

  • Newbie
  • *
  • Posts: 9
Re: Shapes do not stay in given z-order after save and open
« Reply #2 on: July 14, 2021, 01:15:16 PM »
when i drop the stencil onto the page all of the objects are in one group.
to replace the storage i delete it (using ... shapes("storage").delete).
to add a new storage i drop onto ...shapes("virtual server").drop(..."storage",0,0). i then move it to its proper place using saved PinX and PinY values.
by doing this i never have to ungroup or add to group.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #3 on: July 14, 2021, 05:43:14 PM »
This is a bit confusing.  When you say on top, do you mean the z-order stack or the x- / y- positional order?

Couple points: 
1)  you can readily delete a shape from a group, but you must explicitly add it to a group to establish member.
2)  just because you place a shape properly does not make it a member of a group.
3)  is there any code that gets fired when you either close or open the Visio document
4)  terminology clarification:  stencil is a collection of shapes which can be simple or complex, grouped shapes.  Shapes are dragged and dropped, not stencils.  It's a bit confusing at first.

It would be helpful to have a sample file to see what's going on.

« Last Edit: July 14, 2021, 05:47:35 PM by wapperdude »
Visio 2019 Pro

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3088
    • Paul Herber's website
Re: Shapes do not stay in given z-order after save and open
« Reply #4 on: July 15, 2021, 01:50:05 AM »
Could you post a before and after example?
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

vojo

  • Hero Member
  • *****
  • Posts: 1577
Re: Shapes do not stay in given z-order after save and open
« Reply #5 on: July 15, 2021, 08:00:35 AM »
need to be careful about formula approach to pinx and piny.   Need to make sure no
missed corner cases.   I had a problem where I was updating pinx and piny based some
constraints.   Did not realize corner case that put pinx and piny to the something like 19,000 mm each.

stanbriggs

  • Newbie
  • *
  • Posts: 9
Re: Shapes do not stay in given z-order after save and open
« Reply #6 on: July 15, 2021, 01:44:18 PM »
i'm going to restate my original post and address the questions that have been asked. i'm including a screen shot of what i'm talking about.

in my stencil i have a grouped shape for database servers. two examples are shown in the screenshot.

when i drop the shape onto a page it looks like the shape at the top of the attached screenshot. note that the 'SQL Server' circle is on top (in terms of z-order). i can save this file and re-open it and that circle stays on top.
i have VBA code that, when i change the OS, makes all of the appropriate changes to the shape including removing the storage object labelled 'VMDK' and dropping a new storage object also labelled 'VMDK'. the storage that i remove is part of the database server shape. the storage that i drop is part of the same database server shape. [i drop it with "Set shp = shpCurrent.Drop(ActiveDocument.Masters.Item("VMDK DB Storage"), 0, 0)" where shpCurrent is the database server shape. this drops the shape on the page and makes it part of shpCurrent. i then move it to it's proper place using saved PinX and PinY values.

note that the circle (which now has the text "Oracle EE Std" in it) has the storage shape on top of it (in terms of z-order). i can move the circle to the front or the storage to the back. either technique leaves the database server shape looking as it should with the 'Oracle EE Std' circle on top (in terms of z-order).

when i save the file and re-open it the shape at the top which has had no changes made to it is proper; the one at the bottom now has the storage object on top of the "Oracle EE Std" circle (in terms of z-order).

there is code that executes on document open that puts the file name and path into the immediate window.

i'm baffled by this.


wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #7 on: July 15, 2021, 02:06:14 PM »
Mostly understand, but some things still not clear.  Uploading Reduced Visio file with misbehaving salespeople help.

From the example shown, which understandably doesn't touch all options, it looks like the only things that change are textual.  Why delete/add shape?  Just can be necessary text? 

Anyway, actual Visio file would be helpful.
Visio 2019 Pro

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3088
    • Paul Herber's website
Re: Shapes do not stay in given z-order after save and open
« Reply #8 on: July 15, 2021, 02:09:43 PM »
I was thinking that. Just change the text, you can also change the sub-shape name if you really want to.
I suspect you are making it more complicated than it needs to be.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #9 on: July 15, 2021, 04:23:54 PM »
I think  you've discovered  a Visio bug.  I was able to replicate the problem.  Indeed, the z-order does not stick.  It seems to be a code related issue.

If I replicate the steps manually, then the z-order remains correct.  The steps:
1) created grouped shape, saved to new stencil.  Drag and dropped to drawing page
2) selected subshape and duplicated.
3) saved subshape to same stencil

At this point, file is setup to do the code drag/drop/add to group step, set position, set z-order.  Save.  Close Visio. Open Visio, saved file.  And z-order is messed up.
Return to ground zero:  page with just group on it.  Now, manually
1) drag and drop.
2) reposition to desired location
3) send subshape to back
4) select group, then subshape, then add to group.  Everything is as desired.
6) Save, exit Visiol, open Visio, reload saved file.  Opens as expected and desired.  Z-order was preserved.

That's as far as I've gotten.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #10 on: July 15, 2021, 05:40:43 PM »
The work around involves bit of coding.  Instead of dropping to the group directly, drop to the page and then add to group. The challenging part is identifying the correct subshape after grouping.
1) use normal page drop, i.e., Activewindow.page.drop.
2) move shape to desired location
3) select the group + the new shape
4) use the AddToGroup method
5) identify the shape and send to back 
6) Save
Visio 2019 Pro

stanbriggs

  • Newbie
  • *
  • Posts: 9
Re: Shapes do not stay in given z-order after save and open
« Reply #11 on: July 16, 2021, 09:55:03 AM »
wrapperdude: did you code that work-around? i tried it and got the same results as before.

stanbriggs

  • Newbie
  • *
  • Posts: 9
Re: Shapes do not stay in given z-order after save and open
« Reply #12 on: July 16, 2021, 12:36:28 PM »
i even tried .ReplaceShape and got the same results.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #13 on: July 16, 2021, 01:12:28 PM »
Yikes!  Went back and re-tried.  As you've noted, the z-order did not hold.  My apologies.

Re-worked the code to be more pedantically methodical to no avail.

Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4046
  • Ideas Visio-lized into solutions
Re: Shapes do not stay in given z-order after save and open
« Reply #14 on: July 16, 2021, 01:35:11 PM »
Uh-oh. 
Just re-did the entire process manually.  The problem is still there.  Now I'm thinking an update issue.  As we both have it, and you're using V2016  and I'm using V2019, it would not seem likely a corruption on both of our PCs.
Visio 2019 Pro