duplicate method corruption?

G

googull

Visio 2002
I've written a VBA script to replicate a pattern as a matrix as M rows by N
cols. I've tried using different techniques to clone an existing shape
(inside a group) and had hoped to only to have to set a the applicable user
defined fields ( user.row and user.col) - but I've found that the shape when
duplicated doesn't behave even though the formulas in the various shapesheet
settings appear correct. So I've tried overwriting the formulas with their
own content to "wake them up" which works but it appears that I also have to
rewrite every geometry cell as I carry one variable into the geometry!
Isn't there a way to replicate a shape inside a group without it's formulas
all becoming defunct?
 
C

Chris Roth [ Visio MVP ]

I've noticed similar problems...since Visio 2002, I think. When copying
shapes per code, guarded formulas in the Width/Height/Pin cells will
nonentheless get whacked. But I haven't seen this in Geometry.

The general method that I use is to add a user cell, usually something like
User.Index. The shape reacts as much as possible to a simple change in
User.Index. Then I add "hack" code to re-write formulas that are getting
killed by the copying procedure. You are probably already doing this.

I guess the best advice I can think of is this: make as much of the Shape's
smarts as possible based off of internal "User.Index" type variables, and
stay away from referencing the group, except where absolutely necessary.
Also, try and isolate the group's properties that you need, so you can
re-jam the formulas as simply as possible.

Here's an example:

SubShape, original version:

Width = Guard( Group!Width - User.Margin )
PinX = Guard( Group!Width - User.Margin - User.SubWidth * User.Index )

When you copy this shape, all of the "Group!Width" elements might get
whacked, and the entire formulas could be lost. Then you'd have to build a
string to rejam the entire formula. Makes your code messy.

A better method might be:

Width = Guard( User.grWidth - User.Margin )
PinX = Guard( User.grWidth - User.Margin - User.SubWidth * User.Index )

User.grWidth = Group!Width // isolate the group reference

Now when you copy, only User.grWidth will get messed up, and your other
formulas will stay intact. They will have errors in their values, but the
formulas will be ok. Only User.grWidth will be messed up, and it's easy to
reset that:

shpSub.Cells("User.grWidth").Formula = shpSub.ContainingShape.NameID &
"!Width"

Once User.grWidth is re-set, the other formulas will pick up the value and
you'll be fine.

--

Hope this helps,

Chris Roth
Visio MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top