Visio Guy

Visio Discussions => Shapes & Templates => Topic started by: stanbriggs on July 14, 2021, 05:27:37 PM

Title: Shapes do not stay in given z-order after save and open
Post by: stanbriggs on July 14, 2021, 05: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
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Paul Herber on July 14, 2021, 05: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?
Title: Re: Shapes do not stay in given z-order after save and open
Post by: stanbriggs on July 14, 2021, 06: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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 14, 2021, 10: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.

Title: Re: Shapes do not stay in given z-order after save and open
Post by: Paul Herber on July 15, 2021, 06:50:05 AM
Could you post a before and after example?
Title: Re: Shapes do not stay in given z-order after save and open
Post by: vojo on July 15, 2021, 01:00:35 PM
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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: stanbriggs on July 15, 2021, 06: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.

Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 15, 2021, 07: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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Paul Herber on July 15, 2021, 07: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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 15, 2021, 09: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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 15, 2021, 10: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
Title: Re: Shapes do not stay in given z-order after save and open
Post by: stanbriggs on July 16, 2021, 02:55:03 PM
wrapperdude: did you code that work-around? i tried it and got the same results as before.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: stanbriggs on July 16, 2021, 05:36:28 PM
i even tried .ReplaceShape and got the same results.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 16, 2021, 06: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.

Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 16, 2021, 06: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.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 16, 2021, 07:37:45 PM
I tried a couple different things, most failed.  But at one point in saving, Visio asked if I wanted to preserve Z-order.  I said yes, but that made no difference.  So, the clue is in the saving process.

The only, and very ugly, work-around I discover to be effective was to ungroup and then re-group.  That did save correctly.

Would be nice if anyone else would try and verify this loss of z-factor when adding shape to group.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 16, 2021, 08:21:04 PM
Final note:
I was able to narrow this down.  If you drag and drop a grouped shape from a stencil, then add another/replace a shape to the group the "new" shape appears on top.  That's normal.  You can then subselect into the group and move the shape to the back.  This again is normal.  Save the document.  Close the file.  Re-open, and Viola! the z-order is incorrect.  The new subshape is at the very top visually.  Ergo, the problem.

Had the dragNdrop group been ungrouped and then regrouped (this is typically a bad idea/thing to do), then add new shape, send to back.  Repeat save, close, open, and all is well. 

I don't recall this being a problem in the past.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Paul Herber on July 17, 2021, 04:24:00 PM
Defo reproducable here in Visio 2016, but in V2010 it's ok.
I took one of my large grouped shapes, placed a rectangle next to it, selected all, added to group. In the Drawing Explorer, found the added shape (Sheet.26 in this case), Send To Back, saved file in VSSX format. Reopened file. New shape is back on top.
Had a look using my Utils -> Grouped Shape Report.
When the new shape is added to the group, it becomes Sheet.26 and is the last shape in the grouped shape list report.
Send to Back: report now shows Sheet.26 in position 1, i.e. it has been sent to back.
Save, Reload ...
Report now shows Sheet.26 back to being the last shape in the grouped shape list.
Now repeat in V2016 but save in .VSD format. All is ok. It is the VSDX format save that is &%£@*&$  wrong.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 17, 2021, 06:12:37 PM
@Paul Gerber:  totally awesome dude!!!
Title: Re: Shapes do not stay in given z-order after save and open
Post by: wapperdude on July 17, 2021, 11:30:58 PM
Interesting addendum to Paul's findings. 

First, I confirmed that VSD does get it right.  But then, resaved the VSD file as VSDX.  Right?!?  After all, the VSD is now correct.  Busted.  The VSDX file still gets it wrong!!!
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Visisthebest on November 15, 2023, 11:20:29 PM
Excellent investigation of a clear Z order issue with subshapes!

I wonder where Z order is stored in the XML of a VSDX file, this may be a way to fix it by editing the XML in the file.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Paul Herber on November 16, 2023, 08:27:26 AM
Each shape has a .index property, that is the Z-order.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Visisthebest on November 16, 2023, 09:09:16 AM
Yes I forgot Paul, I would be afraid to change the index number in a VSDX file's XML, maybe other data is referencing it or just the shape ID?

Can certainly try to experiment with it with a test file, who knows this might solve the issue.
Title: Re: Shapes do not stay in given z-order after save and open
Post by: Visisthebest on November 16, 2023, 11:03:08 AM
Ok so this new issue here: http://visguy.com/vgforum/index.php?topic=10233.0

Is related to this issue from 2021!

My problem is data graphics, when added to a group shape, are covered by the subshapes in the group.

What I just discovered is, after I save a VSDX and reopen, the order is fine again and the subshapes are covered by the data graphics!

So in my case saving fixes the issue, although it is not a very good fix. I will continue to investigate, also looking at the XML.