'Upgrading' shapes on an existing page based on masters in stencil

Started by Walterr25, January 29, 2021, 08:24:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Walterr25

Hi,

Long time lurker, first time poster here. I'm trying  to figure out a way to automate the process of 'upgrading' shapes on an existing page based on a newer version of a stencil my Add-in provides to the end-user. The desired flow should be:

1. User opens document
2. Add-in detects shapes on document are from an older version (I have a mechanism in place for this)
3. Add-in proceeds to match each document shape with its corresponding newer shape from the stencil (also taken care of)
4. Add-in 'replaces' the old shape with the new shape from the stencil (this is where I need help)

Definition of 'replacing a shape' for my use-case:
1. Visual appearance of the shape on the page must be equal to the shape of the stencil
2. Shape text must be left untouched
3. Add-in specific User cells must be equal to the shape of the stencil (I might be able to do this separate from the 'replace' action however)
4. Connections from and to the shape must be left untouched
5. Layer memberships must be left untouched
6. Position must  be left untouched

Note: some of the shapes in the stencil are connector shapes which must also be replaced, one of which must become the 'Dynamic connector' in the Document Stencil

Things I've tried:

1. Iterating through all shapes and execute shape.ReplaceShape(master) where master is the corresponding master shape. Problems with this approach: It seems that there is no way to preserve the original layer information (specifically, the 'replaced' shape is always added to the currently 'Active layer' which violates point 5 of my defintion. Another issue is that when I use .ReplaceShape() for connector shapes, they lose the connections to their shapes.
2. Replace the existing document master shape with the ones from the stencil. Problem with this approach: I can't find a way to achieve this since .ReplaceShape() doesn't seem to work for master shapes?

Any ideas on how to achieve this would be greatly appreciated. The add-in is written in C# but code samples in other languages are also great.

Thanks!

Hey Ken

Walterr:

   I addressed this same issue many years ago, and I posted the details of how it all works

   However, I did not take your approach of replacing the shapes or the masters.   Both remain intact forever.  Instead, each shape has a version number, and if the stencil encounters an old shape when opening the document, I just have the stencil make the changes to the old shape's shapesheet as necessary.  So all masters, layers, connections, etc. remain as is.  Might not work if you're replacing a Visio shape with a JPEG, for example, but I've never had to do that.  So the approach has held up well for me across the years.

   Good luck!

   - Ken

Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

vojo

open document stencil if you have N shapes that need updated

Walterr25