Reputation: 185
I must write an application, which iterate visio drawings and replace shapes.
I tested the new Visio 2013 API method Shape.ReplaceShape()
and this works
so far.
The problem is that after calling .ReplaceShape() the user defined Cells and their values are not copied in the new shape and I have not idea, how can I do this (elegantly).
Upvotes: 0
Views: 317
Reputation: 4327
The Visio API provides what you need in order to do this. Unfortunately the API call does not allow you to specify copying user cells, so you have to do the copying yourself.
Not C# code, much closer to VBA, but should be good enough as a simple method (with a simplifying assumption, below):
For idx = 0 to FromShp.RowCount(visSectionUser) - 1
newRow = ToShp.AddRow(visSectionUser,visRowLast,visTagDefault)
ToShp.CellsSRC(visSectionuser,newRow,0).formulaU = FromShp.CellsSRC(vissectionUser,idx,0).formulaU
Next idx
Unfortunately this will be a lot more complicated for you if your user cells refer to other cells within the shape's shapesheet, unless they're standard cells (like the object cells: width, height, etc...).
So, if your old shape has an action or scratch or geometry cell that's referenced, you'll have to handle that appropriately. Before you try and copy a cell, you can check whether it has a precedent cell, and depending on the nature of the shapes you're dealing with, you can decide whether or not to just copy the value rather than the formula, which may or may not be invalid in the new shape.
If your user cells only refer to other user cells, then you could create all the copy cells in your ToShp before you copy over any formulas, and that will take care of any errors in that case. But the whole point is, you need to make sure any precedent rows for a cell are available before yo copy formulas over.
Upvotes: 1