Code for replacing one shape with another?

Started by PuzzledSpark, August 02, 2012, 06:47:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PuzzledSpark

Does any one have any VBA code that replaces one shape with another one and copies across the properties and any lines connecting to it?

Nikolay

Download Visio 2013 Preview and click "replace shape" button  ;)

PuzzledSpark


Nikolay


PuzzledSpark

Right well I've managed to solve the problem myself as a form of "Soduku" style challenge while on holiday. I'll have to wait till I'm back home before I can clean up the code and post it here but essentially I wrote a routine to move connectors from one shape to the other (though the logic for detecting when a line is connected to a shape can be optimized - right now I assume a connection if the co-ordinates fall within the rectangular space you see when you manually select any shape in visio),

and found  this code online to copy custom properties across:
http://blog.bvisual.net/2009/02/02/copying-data-from-one-shape-to-another/

aledlund

and of course it's a standard function in the new v2013.
al

PuzzledSpark

Yep I know - but that's still in beta mode or something and it will take 5 years before it becomes a standard tool with the clients I work with so...

aledlund


charlykuntz

Quote from: PuzzledSpark on August 11, 2012, 11:44:14 AM
I wrote a routine to move connectors from one shape to the other (though the logic for detecting when a line is connected to a shape can be optimized

Today I solved a similar problem. I don't know if this piece of code is helpful for you:

Code (C#) Select
if (oldShape.FromConnects.Count > 0)
{
foreach (Connect connect in oldShape.FromConnects)
{
Cell conCell = connect.FromCell;
conCell.GlueTo(newShape.Cells[connect.ToCell.LocalName]);
}
}