News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Shapes do not stay in given z-order after save and open

Started by stanbriggs, July 14, 2021, 05:27:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stanbriggs

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

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 for Visio -

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

stanbriggs

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

#3
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.

Visio 2019 Pro

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

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

vojo

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

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

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

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 for Visio -

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

wapperdude

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

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

wrapperdude: did you code that work-around? i tried it and got the same results as before.

stanbriggs

i even tried .ReplaceShape and got the same results.

wapperdude

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

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

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 384 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1260KB.
Tokens: post-login.
Cache hits: 14: 0.00274s for 26,740 bytes (show)
Cache misses: 4: (show)
Queries used: 17.

[Show Queries]